| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // AudioRendererAlgorithm buffers and transforms audio data. The owner of | 5 // AudioRendererAlgorithm buffers and transforms audio data. The owner of |
| 6 // this object provides audio data to the object through EnqueueBuffer() and | 6 // this object provides audio data to the object through EnqueueBuffer() and |
| 7 // requests data from the buffer via FillBuffer(). The owner also sets the | 7 // requests data from the buffer via FillBuffer(). The owner also sets the |
| 8 // playback rate, and the AudioRendererAlgorithm will stretch or compress the | 8 // playback rate, and the AudioRendererAlgorithm will stretch or compress the |
| 9 // buffered audio as necessary to match the playback rate when fulfilling | 9 // buffered audio as necessary to match the playback rate when fulfilling |
| 10 // FillBuffer() requests. | 10 // FillBuffer() requests. |
| 11 // | 11 // |
| 12 // This class is *not* thread-safe. Calls to enqueue and retrieve data must be | 12 // This class is *not* thread-safe. Calls to enqueue and retrieve data must be |
| 13 // locked if called from multiple threads. | 13 // locked if called from multiple threads. |
| 14 // | 14 // |
| 15 // AudioRendererAlgorithm uses the Waveform Similarity Overlap and Add (WSOLA) | 15 // AudioRendererAlgorithm uses the Waveform Similarity Overlap and Add (WSOLA) |
| 16 // algorithm to stretch or compress audio data to meet playback speeds less than | 16 // algorithm to stretch or compress audio data to meet playback speeds less than |
| 17 // or greater than the natural playback of the audio stream. The algorithm | 17 // or greater than the natural playback of the audio stream. The algorithm |
| 18 // preserves local properties of the audio, therefore, pitch and harmonics are | 18 // preserves local properties of the audio, therefore, pitch and harmonics are |
| 19 // are preserved. See audio_renderer_algorith.cc for a more elaborate | 19 // are preserved. See audio_renderer_algorith.cc for a more elaborate |
| 20 // description of the algorithm. | 20 // description of the algorithm. |
| 21 // | 21 // |
| 22 // Audio at very low or very high playback rates are muted to preserve quality. |
| 23 // |
| 22 | 24 |
| 23 #ifndef MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ | 25 #ifndef MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ |
| 24 #define MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ | 26 #define MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ |
| 25 | 27 |
| 26 #include "base/memory/ref_counted.h" | 28 #include "base/memory/ref_counted.h" |
| 27 #include "base/memory/scoped_ptr.h" | 29 #include "base/memory/scoped_ptr.h" |
| 28 #include "media/audio/audio_parameters.h" | 30 #include "media/audio/audio_parameters.h" |
| 29 #include "media/base/audio_buffer.h" | 31 #include "media/base/audio_buffer.h" |
| 30 #include "media/base/audio_buffer_queue.h" | 32 #include "media/base/audio_buffer_queue.h" |
| 31 | 33 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 void IncreaseQueueCapacity(); | 77 void IncreaseQueueCapacity(); |
| 76 | 78 |
| 77 // Returns the number of frames left in |audio_buffer_|, which may be larger | 79 // Returns the number of frames left in |audio_buffer_|, which may be larger |
| 78 // than QueueCapacity() in the event that EnqueueBuffer() delivered more data | 80 // than QueueCapacity() in the event that EnqueueBuffer() delivered more data |
| 79 // than |audio_buffer_| was intending to hold. | 81 // than |audio_buffer_| was intending to hold. |
| 80 int frames_buffered() { return audio_buffer_.frames(); } | 82 int frames_buffered() { return audio_buffer_.frames(); } |
| 81 | 83 |
| 82 // Returns the samples per second for this audio stream. | 84 // Returns the samples per second for this audio stream. |
| 83 int samples_per_second() { return samples_per_second_; } | 85 int samples_per_second() { return samples_per_second_; } |
| 84 | 86 |
| 87 // Is the sound currently muted? |
| 88 bool is_muted() { return muted_; } |
| 89 |
| 85 private: | 90 private: |
| 86 // Within |search_block_|, find the block of data that is most similar to | 91 // Within |search_block_|, find the block of data that is most similar to |
| 87 // |target_block_|, and write it in |optimal_block_|. This method assumes that | 92 // |target_block_|, and write it in |optimal_block_|. This method assumes that |
| 88 // there is enough data to perform a search, i.e. |search_block_| and | 93 // there is enough data to perform a search, i.e. |search_block_| and |
| 89 // |target_block_| can be extracted from the available frames. | 94 // |target_block_| can be extracted from the available frames. |
| 90 void GetOptimalBlock(); | 95 void GetOptimalBlock(); |
| 91 | 96 |
| 92 // Read a maximum of |requested_frames| frames from |wsola_output_|. Returns | 97 // Read a maximum of |requested_frames| frames from |wsola_output_|. Returns |
| 93 // number of frames actually read. | 98 // number of frames actually read. |
| 94 int WriteCompletedFramesTo( | 99 int WriteCompletedFramesTo( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 133 |
| 129 // Sample rate of audio stream. | 134 // Sample rate of audio stream. |
| 130 int samples_per_second_; | 135 int samples_per_second_; |
| 131 | 136 |
| 132 // Used by algorithm to scale output. | 137 // Used by algorithm to scale output. |
| 133 float playback_rate_; | 138 float playback_rate_; |
| 134 | 139 |
| 135 // Buffered audio data. | 140 // Buffered audio data. |
| 136 AudioBufferQueue audio_buffer_; | 141 AudioBufferQueue audio_buffer_; |
| 137 | 142 |
| 143 // True if the audio should be muted. |
| 144 bool muted_; |
| 145 |
| 146 // If muted, keep track of partial frames that should have been skipped over. |
| 147 double muted_partial_frame_; |
| 148 |
| 138 // How many frames to have in the queue before we report the queue is full. | 149 // How many frames to have in the queue before we report the queue is full. |
| 139 int capacity_; | 150 int capacity_; |
| 140 | 151 |
| 141 // Book keeping of the current time of generated audio, in frames. This | 152 // Book keeping of the current time of generated audio, in frames. This |
| 142 // should be appropriately updated when out samples are generated, regardless | 153 // should be appropriately updated when out samples are generated, regardless |
| 143 // of whether we push samples out when FillBuffer() is called or we store | 154 // of whether we push samples out when FillBuffer() is called or we store |
| 144 // audio in |wsola_output_| for the subsequent calls to FillBuffer(). | 155 // audio in |wsola_output_| for the subsequent calls to FillBuffer(). |
| 145 // Furthermore, if samples from |audio_buffer_| are evicted then this | 156 // Furthermore, if samples from |audio_buffer_| are evicted then this |
| 146 // member variable should be updated based on |playback_rate_|. | 157 // member variable should be updated based on |playback_rate_|. |
| 147 // Note that this member should be updated ONLY by calling UpdateOutputTime(), | 158 // Note that this member should be updated ONLY by calling UpdateOutputTime(), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // searched for a block (|optimal_block_|) that is most similar to | 212 // searched for a block (|optimal_block_|) that is most similar to |
| 202 // |target_block_|. | 213 // |target_block_|. |
| 203 scoped_ptr<AudioBus> target_block_; | 214 scoped_ptr<AudioBus> target_block_; |
| 204 | 215 |
| 205 DISALLOW_COPY_AND_ASSIGN(AudioRendererAlgorithm); | 216 DISALLOW_COPY_AND_ASSIGN(AudioRendererAlgorithm); |
| 206 }; | 217 }; |
| 207 | 218 |
| 208 } // namespace media | 219 } // namespace media |
| 209 | 220 |
| 210 #endif // MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ | 221 #endif // MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ |
| OLD | NEW |