| 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 #include "media/base/audio_converter.h" | 5 #include "media/base/audio_converter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 it != transform_inputs_.end(); ++it) { | 171 it != transform_inputs_.end(); ++it) { |
| 172 InputCallback* input = *it; | 172 InputCallback* input = *it; |
| 173 | 173 |
| 174 float volume = input->ProvideInput( | 174 float volume = input->ProvideInput( |
| 175 mixer_input_audio_bus_.get(), buffer_delay); | 175 mixer_input_audio_bus_.get(), buffer_delay); |
| 176 | 176 |
| 177 // Optimize the most common single input, full volume case. | 177 // Optimize the most common single input, full volume case. |
| 178 if (it == transform_inputs_.begin()) { | 178 if (it == transform_inputs_.begin()) { |
| 179 if (volume == 1.0f) { | 179 if (volume == 1.0f) { |
| 180 mixer_input_audio_bus_->CopyTo(temp_dest); | 180 mixer_input_audio_bus_->CopyTo(temp_dest); |
| 181 continue; | 181 } else if (volume > 0) { |
| 182 for (int i = 0; i < mixer_input_audio_bus_->channels(); ++i) { |
| 183 vector_math::FMUL( |
| 184 mixer_input_audio_bus_->channel(i), volume, |
| 185 mixer_input_audio_bus_->frames(), temp_dest->channel(i)); |
| 186 } |
| 187 } else { |
| 188 // Zero |temp_dest| otherwise, so we're mixing into a clean buffer. |
| 189 temp_dest->Zero(); |
| 182 } | 190 } |
| 183 | 191 |
| 184 // Zero |temp_dest| otherwise, so we're mixing into a clean buffer. | 192 continue; |
| 185 temp_dest->Zero(); | |
| 186 } | 193 } |
| 187 | 194 |
| 188 // Volume adjust and mix each mixer input into |temp_dest| after rendering. | 195 // Volume adjust and mix each mixer input into |temp_dest| after rendering. |
| 189 if (volume > 0) { | 196 if (volume > 0) { |
| 190 for (int i = 0; i < mixer_input_audio_bus_->channels(); ++i) { | 197 for (int i = 0; i < mixer_input_audio_bus_->channels(); ++i) { |
| 191 vector_math::FMAC( | 198 vector_math::FMAC( |
| 192 mixer_input_audio_bus_->channel(i), volume, | 199 mixer_input_audio_bus_->channel(i), volume, |
| 193 mixer_input_audio_bus_->frames(), temp_dest->channel(i)); | 200 mixer_input_audio_bus_->frames(), temp_dest->channel(i)); |
| 194 } | 201 } |
| 195 } | 202 } |
| 196 } | 203 } |
| 197 | 204 |
| 198 if (needs_downmix) { | 205 if (needs_downmix) { |
| 199 DCHECK_EQ(temp_dest->frames(), dest->frames()); | 206 DCHECK_EQ(temp_dest->frames(), dest->frames()); |
| 200 channel_mixer_->Transform(temp_dest, dest); | 207 channel_mixer_->Transform(temp_dest, dest); |
| 201 } | 208 } |
| 202 } | 209 } |
| 203 | 210 |
| 204 void AudioConverter::ProvideInput(int resampler_frame_delay, AudioBus* dest) { | 211 void AudioConverter::ProvideInput(int resampler_frame_delay, AudioBus* dest) { |
| 205 resampler_frame_delay_ = resampler_frame_delay; | 212 resampler_frame_delay_ = resampler_frame_delay; |
| 206 if (audio_fifo_) | 213 if (audio_fifo_) |
| 207 audio_fifo_->Consume(dest, dest->frames()); | 214 audio_fifo_->Consume(dest, dest->frames()); |
| 208 else | 215 else |
| 209 SourceCallback(0, dest); | 216 SourceCallback(0, dest); |
| 210 } | 217 } |
| 211 | 218 |
| 212 } // namespace media | 219 } // namespace media |
| OLD | NEW |