Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(625)

Side by Side Diff: media/base/audio_converter.cc

Issue 14189035: Reduce jitter from uneven SincResampler buffer size requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/audio_converter_unittest.cc » ('j') | media/base/sinc_resampler.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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 resampler_.reset(new MultiChannelResampler( 55 resampler_.reset(new MultiChannelResampler(
56 downmix_early_ ? output_params.channels() : 56 downmix_early_ ? output_params.channels() :
57 input_params.channels(), 57 input_params.channels(),
58 io_sample_rate_ratio, base::Bind( 58 io_sample_rate_ratio, 512, base::Bind(
59 &AudioConverter::ProvideInput, base::Unretained(this)))); 59 &AudioConverter::ProvideInput, base::Unretained(this))));
60 } 60 }
61 61
62 input_frame_duration_ = base::TimeDelta::FromMicroseconds( 62 input_frame_duration_ = base::TimeDelta::FromMicroseconds(
63 base::Time::kMicrosecondsPerSecond / 63 base::Time::kMicrosecondsPerSecond /
64 static_cast<double>(input_params.sample_rate())); 64 static_cast<double>(input_params.sample_rate()));
65 output_frame_duration_ = base::TimeDelta::FromMicroseconds( 65 output_frame_duration_ = base::TimeDelta::FromMicroseconds(
66 base::Time::kMicrosecondsPerSecond / 66 base::Time::kMicrosecondsPerSecond /
67 static_cast<double>(output_params.sample_rate())); 67 static_cast<double>(output_params.sample_rate()));
68 68
69 if (disable_fifo) 69 if (disable_fifo)
70 return; 70 return;
71 71
72 // Since the resampler / output device may want a different buffer size than 72 // Since the resampler / output device may want a different buffer size than
73 // the caller asked for, we need to use a FIFO to ensure that both sides 73 // the caller asked for, we need to use a FIFO to ensure that both sides
74 // read in chunk sizes they're configured for. 74 // read in chunk sizes they're configured for.
75 if (resampler_.get() || 75 // TODO(dalecurtis): Update comment.
76 if (!resampler_.get() &&
76 input_params.frames_per_buffer() != output_params.frames_per_buffer()) { 77 input_params.frames_per_buffer() != output_params.frames_per_buffer()) {
77 DVLOG(1) << "Rebuffering from " << input_params.frames_per_buffer() 78 LOG(ERROR) << "Rebuffering from " << input_params.frames_per_buffer()
78 << " to " << output_params.frames_per_buffer(); 79 << " to " << output_params.frames_per_buffer();
79 audio_fifo_.reset(new AudioPullFifo( 80 audio_fifo_.reset(new AudioPullFifo(
80 downmix_early_ ? output_params.channels() : 81 downmix_early_ ? output_params.channels() :
81 input_params.channels(), 82 input_params.channels(),
82 input_params.frames_per_buffer(), base::Bind( 83 input_params.frames_per_buffer(), base::Bind(
83 &AudioConverter::SourceCallback, 84 &AudioConverter::SourceCallback,
84 base::Unretained(this)))); 85 base::Unretained(this))));
85 } 86 }
86 } 87 }
87 88
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 211
211 void AudioConverter::ProvideInput(int resampler_frame_delay, AudioBus* dest) { 212 void AudioConverter::ProvideInput(int resampler_frame_delay, AudioBus* dest) {
212 resampler_frame_delay_ = resampler_frame_delay; 213 resampler_frame_delay_ = resampler_frame_delay;
213 if (audio_fifo_) 214 if (audio_fifo_)
214 audio_fifo_->Consume(dest, dest->frames()); 215 audio_fifo_->Consume(dest, dest->frames());
215 else 216 else
216 SourceCallback(0, dest); 217 SourceCallback(0, dest);
217 } 218 }
218 219
219 } // namespace media 220 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/audio_converter_unittest.cc » ('j') | media/base/sinc_resampler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698