OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "platform/audio/AudioBus.h" | 32 #include "platform/audio/AudioBus.h" |
33 #include "wtf/Allocator.h" | 33 #include "wtf/Allocator.h" |
34 | 34 |
35 namespace blink { | 35 namespace blink { |
36 | 36 |
37 class AudioFIFO { | 37 class AudioFIFO { |
38 USING_FAST_MALLOC(AudioFIFO); | 38 USING_FAST_MALLOC(AudioFIFO); |
39 WTF_MAKE_NONCOPYABLE(AudioFIFO); | 39 WTF_MAKE_NONCOPYABLE(AudioFIFO); |
40 | 40 |
41 public: | 41 public: |
42 // Create a FIFO large enough to hold |fifoLength| frames of data of |numberOf
Channels| channels. | 42 // Create a FIFO large enough to hold |fifoLength| frames of data of |
| 43 // |numberOfChannels| channels. |
43 AudioFIFO(unsigned numberOfChannels, size_t fifoLength); | 44 AudioFIFO(unsigned numberOfChannels, size_t fifoLength); |
44 | 45 |
45 // Push the data from the bus into the FIFO. | 46 // Push the data from the bus into the FIFO. |
46 void push(const AudioBus*); | 47 void push(const AudioBus*); |
47 | 48 |
48 // Consume |framesToConsume| frames of data from the FIFO and put them in |des
tination|. The | 49 // Consume |framesToConsume| frames of data from the FIFO and put them in |
49 // corresponding frames are removed from the FIFO. | 50 // |destination|. The corresponding frames are removed from the FIFO. |
50 void consume(AudioBus* destination, size_t framesToConsume); | 51 void consume(AudioBus* destination, size_t framesToConsume); |
51 | 52 |
52 // Number of frames of data that are currently in the FIFO. | 53 // Number of frames of data that are currently in the FIFO. |
53 size_t framesInFifo() const { return m_framesInFifo; } | 54 size_t framesInFifo() const { return m_framesInFifo; } |
54 | 55 |
55 private: | 56 private: |
56 // Update the FIFO index by the step, with appropriate wrapping around the end
point. | 57 // Update the FIFO index by the step, with appropriate wrapping around the |
| 58 // endpoint. |
57 int updateIndex(int index, int step) { return (index + step) % m_fifoLength; } | 59 int updateIndex(int index, int step) { return (index + step) % m_fifoLength; } |
58 | 60 |
59 void findWrapLengths(size_t index, | 61 void findWrapLengths(size_t index, |
60 size_t providerSize, | 62 size_t providerSize, |
61 size_t& part1Length, | 63 size_t& part1Length, |
62 size_t& part2Length); | 64 size_t& part2Length); |
63 | 65 |
64 // The FIFO itself. In reality, the FIFO is a circular buffer. | 66 // The FIFO itself. In reality, the FIFO is a circular buffer. |
65 RefPtr<AudioBus> m_fifoAudioBus; | 67 RefPtr<AudioBus> m_fifoAudioBus; |
66 | 68 |
67 // The total available space in the FIFO. | 69 // The total available space in the FIFO. |
68 size_t m_fifoLength; | 70 size_t m_fifoLength; |
69 | 71 |
70 // The number of actual elements in the FIFO | 72 // The number of actual elements in the FIFO |
71 size_t m_framesInFifo; | 73 size_t m_framesInFifo; |
72 | 74 |
73 // Where to start reading from the FIFO. | 75 // Where to start reading from the FIFO. |
74 size_t m_readIndex; | 76 size_t m_readIndex; |
75 | 77 |
76 // Where to start writing to the FIFO. | 78 // Where to start writing to the FIFO. |
77 size_t m_writeIndex; | 79 size_t m_writeIndex; |
78 }; | 80 }; |
79 | 81 |
80 } // namespace blink | 82 } // namespace blink |
81 | 83 |
82 #endif // AudioFIFO.h | 84 #endif // AudioFIFO.h |
OLD | NEW |