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(). | 7 // requests data from the buffer via FillBuffer(). |
8 // | 8 // |
9 // This class is *not* thread-safe. Calls to enqueue and retrieve data must be | 9 // This class is *not* thread-safe. Calls to enqueue and retrieve data must be |
10 // locked if called from multiple threads. | 10 // locked if called from multiple threads. |
11 // | 11 // |
12 // AudioRendererAlgorithm uses the Waveform Similarity Overlap and Add (WSOLA) | 12 // AudioRendererAlgorithm uses the Waveform Similarity Overlap and Add (WSOLA) |
13 // algorithm to stretch or compress audio data to meet playback speeds less than | 13 // algorithm to stretch or compress audio data to meet playback speeds less than |
14 // or greater than the natural playback of the audio stream. The algorithm | 14 // or greater than the natural playback of the audio stream. The algorithm |
15 // preserves local properties of the audio, therefore, pitch and harmonics are | 15 // preserves local properties of the audio, therefore, pitch and harmonics are |
16 // are preserved. See audio_renderer_algorith.cc for a more elaborate | 16 // are preserved. See audio_renderer_algorith.cc for a more elaborate |
17 // description of the algorithm. | 17 // description of the algorithm. |
18 // | 18 // |
19 // Audio at very low or very high playback rates are muted to preserve quality. | 19 // Audio at very low or very high playback rates are muted to preserve quality. |
20 | 20 |
21 #ifndef MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ | 21 #ifndef MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ |
22 #define MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ | 22 #define MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ |
23 | 23 |
24 #include <stdint.h> | 24 #include <stdint.h> |
25 | 25 |
| 26 #include <memory> |
| 27 |
26 #include "base/macros.h" | 28 #include "base/macros.h" |
27 #include "base/memory/ref_counted.h" | 29 #include "base/memory/ref_counted.h" |
28 #include "base/memory/scoped_ptr.h" | |
29 #include "media/audio/audio_parameters.h" | 30 #include "media/audio/audio_parameters.h" |
30 #include "media/base/audio_buffer.h" | 31 #include "media/base/audio_buffer.h" |
31 #include "media/base/audio_buffer_queue.h" | 32 #include "media/base/audio_buffer_queue.h" |
32 | 33 |
33 namespace media { | 34 namespace media { |
34 | 35 |
35 class AudioBus; | 36 class AudioBus; |
36 | 37 |
37 class MEDIA_EXPORT AudioRendererAlgorithm { | 38 class MEDIA_EXPORT AudioRendererAlgorithm { |
38 public: | 39 public: |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // Number of frames in |wsola_output_| that overlap-and-add is completed for | 176 // Number of frames in |wsola_output_| that overlap-and-add is completed for |
176 // them and can be copied to output if FillBuffer() is called. It also | 177 // them and can be copied to output if FillBuffer() is called. It also |
177 // specifies the index where the next WSOLA window has to overlap-and-add. | 178 // specifies the index where the next WSOLA window has to overlap-and-add. |
178 int num_complete_frames_; | 179 int num_complete_frames_; |
179 | 180 |
180 // This stores a part of the output that is created but couldn't be rendered. | 181 // This stores a part of the output that is created but couldn't be rendered. |
181 // Output is generated frame-by-frame which at some point might exceed the | 182 // Output is generated frame-by-frame which at some point might exceed the |
182 // number of requested samples. Furthermore, due to overlap-and-add, | 183 // number of requested samples. Furthermore, due to overlap-and-add, |
183 // the last half-window of the output is incomplete, which is stored in this | 184 // the last half-window of the output is incomplete, which is stored in this |
184 // buffer. | 185 // buffer. |
185 scoped_ptr<AudioBus> wsola_output_; | 186 std::unique_ptr<AudioBus> wsola_output_; |
186 | 187 |
187 // Overlap-and-add window. | 188 // Overlap-and-add window. |
188 scoped_ptr<float[]> ola_window_; | 189 std::unique_ptr<float[]> ola_window_; |
189 | 190 |
190 // Transition window, used to update |optimal_block_| by a weighted sum of | 191 // Transition window, used to update |optimal_block_| by a weighted sum of |
191 // |optimal_block_| and |target_block_|. | 192 // |optimal_block_| and |target_block_|. |
192 scoped_ptr<float[]> transition_window_; | 193 std::unique_ptr<float[]> transition_window_; |
193 | 194 |
194 // Auxiliary variables to avoid allocation in every iteration. | 195 // Auxiliary variables to avoid allocation in every iteration. |
195 | 196 |
196 // Stores the optimal block in every iteration. This is the most | 197 // Stores the optimal block in every iteration. This is the most |
197 // similar block to |target_block_| within |search_block_| and it is | 198 // similar block to |target_block_| within |search_block_| and it is |
198 // overlap-and-added to |wsola_output_|. | 199 // overlap-and-added to |wsola_output_|. |
199 scoped_ptr<AudioBus> optimal_block_; | 200 std::unique_ptr<AudioBus> optimal_block_; |
200 | 201 |
201 // A block of data that search is performed over to find the |optimal_block_|. | 202 // A block of data that search is performed over to find the |optimal_block_|. |
202 scoped_ptr<AudioBus> search_block_; | 203 std::unique_ptr<AudioBus> search_block_; |
203 | 204 |
204 // Stores the target block, denoted as |target| above. |search_block_| is | 205 // Stores the target block, denoted as |target| above. |search_block_| is |
205 // searched for a block (|optimal_block_|) that is most similar to | 206 // searched for a block (|optimal_block_|) that is most similar to |
206 // |target_block_|. | 207 // |target_block_|. |
207 scoped_ptr<AudioBus> target_block_; | 208 std::unique_ptr<AudioBus> target_block_; |
208 | 209 |
209 DISALLOW_COPY_AND_ASSIGN(AudioRendererAlgorithm); | 210 DISALLOW_COPY_AND_ASSIGN(AudioRendererAlgorithm); |
210 }; | 211 }; |
211 | 212 |
212 } // namespace media | 213 } // namespace media |
213 | 214 |
214 #endif // MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ | 215 #endif // MEDIA_FILTERS_AUDIO_RENDERER_ALGORITHM_H_ |
OLD | NEW |