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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // since we'll mix into the AudioBus from the output stream. | 43 // since we'll mix into the AudioBus from the output stream. |
44 unmixed_audio_ = AudioBus::Create( | 44 unmixed_audio_ = AudioBus::Create( |
45 input_params.channels(), output_params.frames_per_buffer()); | 45 input_params.channels(), output_params.frames_per_buffer()); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 // Only resample if necessary since it's expensive. | 49 // Only resample if necessary since it's expensive. |
50 if (input_params.sample_rate() != output_params.sample_rate()) { | 50 if (input_params.sample_rate() != output_params.sample_rate()) { |
51 DVLOG(1) << "Resampling from " << input_params.sample_rate() << " to " | 51 DVLOG(1) << "Resampling from " << input_params.sample_rate() << " to " |
52 << output_params.sample_rate(); | 52 << output_params.sample_rate(); |
53 double io_sample_rate_ratio = input_params.sample_rate() / | 53 const double io_sample_rate_ratio = input_params.sample_rate() / |
54 static_cast<double>(output_params.sample_rate()); | 54 static_cast<double>(output_params.sample_rate()); |
| 55 const int request_size = disable_fifo ? SincResampler::kDefaultBlockSize : |
| 56 input_params.frames_per_buffer(); |
55 resampler_.reset(new MultiChannelResampler( | 57 resampler_.reset(new MultiChannelResampler( |
56 downmix_early_ ? output_params.channels() : | 58 downmix_early_ ? output_params.channels() : |
57 input_params.channels(), | 59 input_params.channels(), |
58 io_sample_rate_ratio, base::Bind( | 60 io_sample_rate_ratio, request_size, base::Bind( |
59 &AudioConverter::ProvideInput, base::Unretained(this)))); | 61 &AudioConverter::ProvideInput, base::Unretained(this)))); |
60 } | 62 } |
61 | 63 |
62 input_frame_duration_ = base::TimeDelta::FromMicroseconds( | 64 input_frame_duration_ = base::TimeDelta::FromMicroseconds( |
63 base::Time::kMicrosecondsPerSecond / | 65 base::Time::kMicrosecondsPerSecond / |
64 static_cast<double>(input_params.sample_rate())); | 66 static_cast<double>(input_params.sample_rate())); |
65 output_frame_duration_ = base::TimeDelta::FromMicroseconds( | 67 output_frame_duration_ = base::TimeDelta::FromMicroseconds( |
66 base::Time::kMicrosecondsPerSecond / | 68 base::Time::kMicrosecondsPerSecond / |
67 static_cast<double>(output_params.sample_rate())); | 69 static_cast<double>(output_params.sample_rate())); |
68 | 70 |
69 if (disable_fifo) | 71 // The resampler can be configured to work with a specific buffer size, so a |
| 72 // FIFO is not necessary when resampling. |
| 73 if (disable_fifo || resampler_) |
70 return; | 74 return; |
71 | 75 |
72 // Since the resampler / output device may want a different buffer size than | 76 // Since the output device may want a different buffer size than the caller |
73 // the caller asked for, we need to use a FIFO to ensure that both sides | 77 // asked for, we need to use a FIFO to ensure that both sides read in chunk |
74 // read in chunk sizes they're configured for. | 78 // sizes they're configured for. |
75 if (resampler_.get() || | 79 if (input_params.frames_per_buffer() != output_params.frames_per_buffer()) { |
76 input_params.frames_per_buffer() != output_params.frames_per_buffer()) { | |
77 DVLOG(1) << "Rebuffering from " << input_params.frames_per_buffer() | 80 DVLOG(1) << "Rebuffering from " << input_params.frames_per_buffer() |
78 << " to " << output_params.frames_per_buffer(); | 81 << " to " << output_params.frames_per_buffer(); |
79 audio_fifo_.reset(new AudioPullFifo( | 82 audio_fifo_.reset(new AudioPullFifo( |
80 downmix_early_ ? output_params.channels() : | 83 downmix_early_ ? output_params.channels() : |
81 input_params.channels(), | 84 input_params.channels(), |
82 input_params.frames_per_buffer(), base::Bind( | 85 input_params.frames_per_buffer(), base::Bind( |
83 &AudioConverter::SourceCallback, | 86 &AudioConverter::SourceCallback, |
84 base::Unretained(this)))); | 87 base::Unretained(this)))); |
85 } | 88 } |
86 } | 89 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 217 |
215 void AudioConverter::ProvideInput(int resampler_frame_delay, AudioBus* dest) { | 218 void AudioConverter::ProvideInput(int resampler_frame_delay, AudioBus* dest) { |
216 resampler_frame_delay_ = resampler_frame_delay; | 219 resampler_frame_delay_ = resampler_frame_delay; |
217 if (audio_fifo_) | 220 if (audio_fifo_) |
218 audio_fifo_->Consume(dest, dest->frames()); | 221 audio_fifo_->Consume(dest, dest->frames()); |
219 else | 222 else |
220 SourceCallback(0, dest); | 223 SourceCallback(0, dest); |
221 } | 224 } |
222 | 225 |
223 } // namespace media | 226 } // namespace media |
OLD | NEW |