| 1 | /* |
| 2 | Copyright 2018 Google Inc. All Rights Reserved. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS-IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef RESONANCE_AUDIO_GRAPH_BUFFERED_SOURCE_NODE_H_ |
| 18 | #define RESONANCE_AUDIO_GRAPH_BUFFERED_SOURCE_NODE_H_ |
| 19 | |
| 20 | #include "base/audio_buffer.h" |
| 21 | #include "base/constants_and_types.h" |
| 22 | #include "node/source_node.h" |
| 23 | |
| 24 | namespace vraudio { |
| 25 | |
| 26 | // Node that sets the |AudioBuffer| of a source. This class is *not* |
| 27 | // thread-safe and calls to this class must be synchronized with the graph |
| 28 | // processing. |
| 29 | class BufferedSourceNode : public SourceNode { |
| 30 | public: |
| 31 | // Constructor. |
| 32 | // |
| 33 | // @param source_id Source id. |
| 34 | // @param num_channel Number of channels in output buffers. |
| 35 | BufferedSourceNode(SourceId source_id, size_t num_channels, |
| 36 | size_t frames_per_buffer); |
| 37 | |
| 38 | // Returns a mutable pointer to the internal |AudioBuffer| and sets a flag to |
| 39 | // process the buffer in the next graph processing iteration. Calls to this |
| 40 | // method must be synchronized with the audio graph processing. |
| 41 | // |
| 42 | // @return Mutable audio buffer pointer. |
| 43 | AudioBuffer* GetMutableAudioBufferAndSetNewBufferFlag(); |
| 44 | |
| 45 | protected: |
| 46 | // Implements SourceNode. |
| 47 | const AudioBuffer* AudioProcess() override; |
| 48 | |
| 49 | // Source id. |
| 50 | const SourceId source_id_; |
| 51 | |
| 52 | // Input audio buffer. |
| 53 | AudioBuffer input_audio_buffer_; |
| 54 | |
| 55 | // Flag indicating if an new audio buffer has been set via |
| 56 | // |GetMutableAudioBufferAndSetNewBufferFlag|. |
| 57 | bool new_buffer_flag_; |
| 58 | }; |
| 59 | |
| 60 | } // namespace vraudio |
| 61 | |
| 62 | #endif // RESONANCE_AUDIO_GRAPH_BUFFERED_SOURCE_NODE_H_ |
| 63 | |