OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #ifndef WEBRTC_COMMON_AUDIO_AUDIO_RING_BUFFER_H_ | 10 #ifndef WEBRTC_COMMON_AUDIO_AUDIO_RING_BUFFER_H_ |
11 #define WEBRTC_COMMON_AUDIO_AUDIO_RING_BUFFER_H_ | 11 #define WEBRTC_COMMON_AUDIO_AUDIO_RING_BUFFER_H_ |
12 | 12 |
13 #include <stddef.h> | 13 #include <stddef.h> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 struct RingBuffer; | 16 struct RingBuffer; |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 | 19 |
20 // A ring buffer tailored for float deinterleaved audio. Any operation that | 20 // A ring buffer tailored for float deinterleaved audio. Any operation that |
21 // cannot be performed as requested will cause a crash (e.g. insufficient data | 21 // cannot be performed as requested will cause a crash (e.g. insufficient data |
22 // in the buffer to fulfill a read request.) | 22 // in the buffer to fulfill a read request.) |
23 class AudioRingBuffer final { | 23 class AudioRingBuffer final { |
24 public: | 24 public: |
25 // Specify the number of channels and maximum number of frames the buffer will | 25 // Specify the number of channels and maximum number of frames the buffer will |
26 // contain. | 26 // contain. |
27 AudioRingBuffer(size_t channels, size_t max_frames); | 27 AudioRingBuffer(size_t channels, size_t max_frames); |
28 ~AudioRingBuffer(); | 28 ~AudioRingBuffer(); |
29 | 29 |
30 // Copy |data| to the buffer and advance the write pointer. |channels| must | 30 // Copies |data| to the buffer and advances the write pointer. |channels| must |
31 // be the same as at creation time. | 31 // be the same as at creation time. |
32 void Write(const float* const* data, size_t channels, size_t frames); | 32 void Write(const float* const* data, size_t channels, size_t frames); |
33 | 33 |
34 // Copy from the buffer to |data| and advance the read pointer. |channels| | 34 // Copies from the buffer to |data| and advances the read pointer. |channels| |
35 // must be the same as at creation time. | 35 // must be the same as at creation time. |
36 void Read(float* const* data, size_t channels, size_t frames); | 36 void Read(float* const* data, size_t channels, size_t frames); |
37 | 37 |
38 size_t ReadFramesAvailable() const; | 38 size_t ReadFramesAvailable() const; |
39 size_t WriteFramesAvailable() const; | 39 size_t WriteFramesAvailable() const; |
40 | 40 |
41 // Positive values advance the read pointer and negative values withdraw | 41 // Moves the read position. The forward version advances the read pointer |
42 // the read pointer (i.e. flush and stuff the buffer respectively.) | 42 // towards the write pointer and the backward verison withdraws the read |
43 void MoveReadPosition(int frames); | 43 // pointer away from the write pointer (i.e. flushing and stuffing the buffer |
| 44 // respectively.) |
| 45 void MoveReadPositionForward(size_t frames); |
| 46 void MoveReadPositionBackward(size_t frames); |
44 | 47 |
45 private: | 48 private: |
46 // We don't use a ScopedVector because it doesn't support a specialized | 49 // We don't use a ScopedVector because it doesn't support a specialized |
47 // deleter (like scoped_ptr for instance.) | 50 // deleter (like scoped_ptr for instance.) |
48 std::vector<RingBuffer*> buffers_; | 51 std::vector<RingBuffer*> buffers_; |
49 }; | 52 }; |
50 | 53 |
51 } // namespace webrtc | 54 } // namespace webrtc |
52 | 55 |
53 #endif // WEBRTC_COMMON_AUDIO_AUDIO_RING_BUFFER_H_ | 56 #endif // WEBRTC_COMMON_AUDIO_AUDIO_RING_BUFFER_H_ |
OLD | NEW |