Chromium Code Reviews| 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 // AudioConverter is a complete mixing, resampling, buffering, and channel | 5 // AudioConverter is a complete mixing, resampling, buffering, and channel |
| 6 // mixing solution for converting data from one set of AudioParameters to | 6 // mixing solution for converting data from one set of AudioParameters to |
| 7 // another. | 7 // another. |
| 8 // | 8 // |
| 9 // For efficiency, pieces are only invoked when necessary; i.e., | 9 // For efficiency, pieces are only invoked when necessary; i.e., |
| 10 // - The resampler is only used if sample rates differ. | 10 // - The resampler is only used if sample rates differ. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 // Interface for inputs into the converter. Each InputCallback is added or | 49 // Interface for inputs into the converter. Each InputCallback is added or |
| 50 // removed from Convert() processing via AddInput() and RemoveInput(). | 50 // removed from Convert() processing via AddInput() and RemoveInput(). |
| 51 class MEDIA_EXPORT InputCallback { | 51 class MEDIA_EXPORT InputCallback { |
| 52 public: | 52 public: |
| 53 // Method for providing more data into the converter. Expects |audio_bus| | 53 // Method for providing more data into the converter. Expects |audio_bus| |
| 54 // to be completely filled with data upon return; zero padded if not enough | 54 // to be completely filled with data upon return; zero padded if not enough |
| 55 // frames are available to satisfy the request. The return value is the | 55 // frames are available to satisfy the request. The return value is the |
| 56 // volume level of the provided audio data. If a volume level of zero is | 56 // volume level of the provided audio data. If a volume level of zero is |
| 57 // returned no further processing will be done on the provided data, else | 57 // returned no further processing will be done on the provided data, else |
| 58 // the volume level will be used to scale the provided audio data. | 58 // the volume level will be used to scale the provided audio data. |
| 59 // |frames_delayed| is given in terms of the input sample rate. | |
| 59 virtual double ProvideInput(AudioBus* audio_bus, | 60 virtual double ProvideInput(AudioBus* audio_bus, |
| 60 base::TimeDelta buffer_delay) = 0; | 61 uint32_t frames_delayed) = 0; |
| 61 | 62 |
| 62 protected: | 63 protected: |
| 63 virtual ~InputCallback() {} | 64 virtual ~InputCallback() {} |
| 64 }; | 65 }; |
| 65 | 66 |
| 66 // Constructs an AudioConverter for converting between the given input and | 67 // Constructs an AudioConverter for converting between the given input and |
| 67 // output parameters. Specifying |disable_fifo| means all InputCallbacks are | 68 // output parameters. Specifying |disable_fifo| means all InputCallbacks are |
| 68 // capable of handling arbitrary buffer size requests; i.e. one call might ask | 69 // capable of handling arbitrary buffer size requests; i.e. one call might ask |
| 69 // for 10 frames of data (indicated by the size of AudioBus provided) and the | 70 // for 10 frames of data (indicated by the size of AudioBus provided) and the |
| 70 // next might ask for 20. In synthetic testing, disabling the FIFO yields a | 71 // next might ask for 20. In synthetic testing, disabling the FIFO yields a |
| 71 // ~20% speed up for common cases. | 72 // ~20% speed up for common cases. |
| 72 AudioConverter(const AudioParameters& input_params, | 73 AudioConverter(const AudioParameters& input_params, |
| 73 const AudioParameters& output_params, | 74 const AudioParameters& output_params, |
| 74 bool disable_fifo); | 75 bool disable_fifo); |
| 75 ~AudioConverter(); | 76 ~AudioConverter(); |
| 76 | 77 |
| 77 // Converts audio from all inputs into the |dest|. If an |initial_delay| is | 78 // Converts audio from all inputs into the |dest|. If |initial_frames_delayed| |
|
Henrik Grunell
2016/05/25 14:48:38
initial_frames_delayed or frames_delayed?
chcunningham
2016/05/25 18:21:15
Fixed - frames_delayed.
| |
| 78 // specified, it will be propagated to each input. | 79 // is specified, it will be propagated to each input. Count of frames must be |
| 80 // given in terms of the output sample rate. | |
|
Henrik Grunell
2016/05/25 14:48:38
Nit: last sentence is implicit, you could skip it.
chcunningham
2016/05/25 18:21:15
Ha, I know you're right, but I always have to paus
| |
| 79 void Convert(AudioBus* dest); | 81 void Convert(AudioBus* dest); |
| 80 void ConvertWithDelay(const base::TimeDelta& initial_delay, AudioBus* dest); | 82 void ConvertWithDelay(uint32_t frames_dealyed, AudioBus* dest); |
|
Henrik Grunell
2016/05/25 14:48:38
Spelling.
chcunningham
2016/05/25 18:21:15
Done.
| |
| 81 | 83 |
| 82 // Adds or removes an input from the converter. RemoveInput() will call | 84 // Adds or removes an input from the converter. RemoveInput() will call |
| 83 // Reset() if no inputs remain after the specified input is removed. | 85 // Reset() if no inputs remain after the specified input is removed. |
| 84 void AddInput(InputCallback* input); | 86 void AddInput(InputCallback* input); |
| 85 void RemoveInput(InputCallback* input); | 87 void RemoveInput(InputCallback* input); |
| 86 | 88 |
| 87 // Flushes all buffered data. | 89 // Flushes all buffered data. |
| 88 void Reset(); | 90 void Reset(); |
| 89 | 91 |
| 90 // The maximum size in frames that guarantees we will only make a single call | 92 // The maximum size in frames that guarantees we will only make a single call |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 std::unique_ptr<AudioBus> unmixed_audio_; | 128 std::unique_ptr<AudioBus> unmixed_audio_; |
| 127 | 129 |
| 128 // Temporary AudioBus destination for mixing inputs. | 130 // Temporary AudioBus destination for mixing inputs. |
| 129 std::unique_ptr<AudioBus> mixer_input_audio_bus_; | 131 std::unique_ptr<AudioBus> mixer_input_audio_bus_; |
| 130 | 132 |
| 131 // Since resampling is expensive, figure out if we should downmix channels | 133 // Since resampling is expensive, figure out if we should downmix channels |
| 132 // before resampling. | 134 // before resampling. |
| 133 bool downmix_early_; | 135 bool downmix_early_; |
| 134 | 136 |
| 135 // Used to calculate buffer delay information for InputCallbacks. | 137 // Used to calculate buffer delay information for InputCallbacks. |
| 136 base::TimeDelta input_frame_duration_; | 138 uint32_t initial_frames_delayed_; |
| 137 base::TimeDelta output_frame_duration_; | 139 uint32_t resampler_frames_delayed_; |
| 138 base::TimeDelta initial_delay_; | 140 const double io_sample_rate_ratio_; |
| 139 int resampler_frame_delay_; | |
| 140 | 141 |
| 141 // Number of channels of input audio data. Set during construction via the | 142 // Number of channels of input audio data. Set during construction via the |
| 142 // value from the input AudioParameters class. Preserved to recreate internal | 143 // value from the input AudioParameters class. Preserved to recreate internal |
| 143 // AudioBus structures on demand in response to varying frame size requests. | 144 // AudioBus structures on demand in response to varying frame size requests. |
| 144 const int input_channel_count_; | 145 const int input_channel_count_; |
| 145 | 146 |
| 146 DISALLOW_COPY_AND_ASSIGN(AudioConverter); | 147 DISALLOW_COPY_AND_ASSIGN(AudioConverter); |
| 147 }; | 148 }; |
| 148 | 149 |
| 149 } // namespace media | 150 } // namespace media |
| 150 | 151 |
| 151 #endif // MEDIA_BASE_AUDIO_CONVERTER_H_ | 152 #endif // MEDIA_BASE_AUDIO_CONVERTER_H_ |
| OLD | NEW |