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

Side by Side Diff: media/base/multi_channel_resampler.h

Issue 14189035: Reduce jitter from uneven SincResampler buffer size requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 7 years, 7 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 | « media/base/fake_audio_render_callback.cc ('k') | media/base/multi_channel_resampler.cc » ('j') | no next file with comments »
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 #ifndef MEDIA_BASE_MULTI_CHANNEL_RESAMPLER_H_ 5 #ifndef MEDIA_BASE_MULTI_CHANNEL_RESAMPLER_H_
6 #define MEDIA_BASE_MULTI_CHANNEL_RESAMPLER_H_ 6 #define MEDIA_BASE_MULTI_CHANNEL_RESAMPLER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
13 #include "media/base/sinc_resampler.h" 13 #include "media/base/sinc_resampler.h"
14 14
15 namespace media { 15 namespace media {
16 class AudioBus; 16 class AudioBus;
17 17
18 // MultiChannelResampler is a multi channel wrapper for SincResampler; allowing 18 // MultiChannelResampler is a multi channel wrapper for SincResampler; allowing
19 // high quality sample rate conversion of multiple channels at once. 19 // high quality sample rate conversion of multiple channels at once.
20 class MEDIA_EXPORT MultiChannelResampler { 20 class MEDIA_EXPORT MultiChannelResampler {
21 public: 21 public:
22 // Callback type for providing more data into the resampler. Expects AudioBus 22 // Callback type for providing more data into the resampler. Expects AudioBus
23 // to be completely filled with data upon return; zero padded if not enough 23 // to be completely filled with data upon return; zero padded if not enough
24 // frames are available to satisfy the request. |frame_delay| is the number 24 // frames are available to satisfy the request. |frame_delay| is the number
25 // of output frames already processed and can be used to estimate delay. 25 // of output frames already processed and can be used to estimate delay.
26 typedef base::Callback<void(int frame_delay, AudioBus* audio_bus)> ReadCB; 26 typedef base::Callback<void(int frame_delay, AudioBus* audio_bus)> ReadCB;
27 27
28 // Constructs a MultiChannelResampler with the specified |read_cb|, which is 28 // Constructs a MultiChannelResampler with the specified |read_cb|, which is
29 // used to acquire audio data for resampling. |io_sample_rate_ratio| is the 29 // used to acquire audio data for resampling. |io_sample_rate_ratio| is the
30 // ratio of input / output sample rates. 30 // ratio of input / output sample rates. |request_frames| is the size in
31 MultiChannelResampler(int channels, double io_sample_rate_ratio, 31 // frames of the AudioBus to be filled by |read_cb|.
32 MultiChannelResampler(int channels,
33 double io_sample_rate_ratio,
34 size_t request_frames,
32 const ReadCB& read_cb); 35 const ReadCB& read_cb);
33 virtual ~MultiChannelResampler(); 36 virtual ~MultiChannelResampler();
34 37
35 // Resamples |frames| of data from |read_cb_| into AudioBus. 38 // Resamples |frames| of data from |read_cb_| into AudioBus.
36 void Resample(AudioBus* audio_bus, int frames); 39 void Resample(int frames, AudioBus* audio_bus);
37 40
38 // Flush all buffered data and reset internal indices. Not thread safe, do 41 // Flush all buffered data and reset internal indices. Not thread safe, do
39 // not call while Resample() is in progress. 42 // not call while Resample() is in progress.
40 void Flush(); 43 void Flush();
41 44
42 // Update ratio for all SincResamplers. SetRatio() will cause reconstruction 45 // Update ratio for all SincResamplers. SetRatio() will cause reconstruction
43 // of the kernels used for resampling. Not thread safe, do not call while 46 // of the kernels used for resampling. Not thread safe, do not call while
44 // Resample() is in progress. 47 // Resample() is in progress.
45 void SetRatio(double io_sample_rate_ratio); 48 void SetRatio(double io_sample_rate_ratio);
46 49
47 private: 50 private:
48 // SincResampler::ReadCB implementation. ProvideInput() will be called for 51 // SincResampler::ReadCB implementation. ProvideInput() will be called for
49 // each channel (in channel order) as SincResampler needs more data. 52 // each channel (in channel order) as SincResampler needs more data.
50 void ProvideInput(int channel, float* destination, int frames); 53 void ProvideInput(int channel, int frames, float* destination);
51 54
52 // Sanity check to ensure that ProvideInput() retrieves the same number of 55 // Sanity check to ensure that ProvideInput() retrieves the same number of
53 // frames for every channel. 56 // frames for every channel.
54 int last_frame_count_; 57 int last_frame_count_;
55 58
56 // Source of data for resampling. 59 // Source of data for resampling.
57 ReadCB read_cb_; 60 ReadCB read_cb_;
58 61
59 // Each channel has its own high quality resampler. 62 // Each channel has its own high quality resampler.
60 ScopedVector<SincResampler> resamplers_; 63 ScopedVector<SincResampler> resamplers_;
61 64
62 // Buffers for audio data going into SincResampler from ReadCB. 65 // Buffers for audio data going into SincResampler from ReadCB.
63 scoped_ptr<AudioBus> resampler_audio_bus_; 66 scoped_ptr<AudioBus> resampler_audio_bus_;
64 scoped_ptr<AudioBus> wrapped_resampler_audio_bus_; 67 scoped_ptr<AudioBus> wrapped_resampler_audio_bus_;
65 std::vector<float*> resampler_audio_data_; 68 std::vector<float*> resampler_audio_data_;
66 69
67 // The number of output frames that have successfully been processed during 70 // The number of output frames that have successfully been processed during
68 // the current Resample() call. 71 // the current Resample() call.
69 int output_frames_ready_; 72 int output_frames_ready_;
70 73
71 DISALLOW_COPY_AND_ASSIGN(MultiChannelResampler); 74 DISALLOW_COPY_AND_ASSIGN(MultiChannelResampler);
72 }; 75 };
73 76
74 } // namespace media 77 } // namespace media
75 78
76 #endif // MEDIA_BASE_MULTI_CHANNEL_RESAMPLER_H_ 79 #endif // MEDIA_BASE_MULTI_CHANNEL_RESAMPLER_H_
OLDNEW
« no previous file with comments | « media/base/fake_audio_render_callback.cc ('k') | media/base/multi_channel_resampler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698