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

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

Issue 10823175: Switch AudioRenderSink::Callback to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup MCR AudioBus usage. Created 8 years, 4 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 17
17 // MultiChannelResampler is a multi channel wrapper for SincResampler; allowing 18 // MultiChannelResampler is a multi channel wrapper for SincResampler; allowing
18 // high quality sample rate conversion of multiple channels at once. 19 // high quality sample rate conversion of multiple channels at once.
19 class MEDIA_EXPORT MultiChannelResampler { 20 class MEDIA_EXPORT MultiChannelResampler {
20 public: 21 public:
21 // Callback type for providing more data into the resampler. Expects |frames| 22 // Callback type for providing more data into the resampler. Expects AudioBus
22 // of data for all channels to be rendered into |destination|; zero padded if 23 // to be completely filled with data upon return; zero padded if not enough
23 // not enough frames are available to satisfy the request. 24 // frames are available to satisfy the request.
24 typedef base::Callback<void(const std::vector<float*>& destination, 25 typedef base::Callback<void(AudioBus* audio_bus)> ReadCB;
25 int frames)> ReadCB;
26 26
27 // Constructs a MultiChannelResampler with the specified |read_cb|, which is 27 // Constructs a MultiChannelResampler with the specified |read_cb|, which is
28 // used to acquire audio data for resampling. |io_sample_rate_ratio| is the 28 // used to acquire audio data for resampling. |io_sample_rate_ratio| is the
29 // ratio of input / output sample rates. 29 // ratio of input / output sample rates.
30 MultiChannelResampler(int channels, double io_sample_rate_ratio, 30 MultiChannelResampler(int channels, double io_sample_rate_ratio,
31 const ReadCB& read_cb); 31 const ReadCB& read_cb);
32 virtual ~MultiChannelResampler(); 32 virtual ~MultiChannelResampler();
33 33
34 // Resample |frames| of data from |read_cb_| into |destination|. 34 // Resamples |frames| of data from |read_cb_| into AudioBus.
35 void Resample(const std::vector<float*>& destination, int frames); 35 void Resample(AudioBus* audio_bus, int frames);
36 36
37 private: 37 private:
38 // SincResampler::ReadCB implementation. ProvideInput() will be called for 38 // SincResampler::ReadCB implementation. ProvideInput() will be called for
39 // each channel (in channel order) as SincResampler needs more data. 39 // each channel (in channel order) as SincResampler needs more data.
40 void ProvideInput(int channel, float* destination, int frames); 40 void ProvideInput(int channel, float* destination, int frames);
41 41
42 // Sanity check to ensure that ProvideInput() retrieves the same number of 42 // Sanity check to ensure that ProvideInput() retrieves the same number of
43 // frames for every channel. 43 // frames for every channel.
44 int last_frame_count_; 44 int last_frame_count_;
45 45
46 // Sanity check to ensure |resampler_audio_data_| is properly allocated.
47 int first_frame_count_;
48
49 // Source of data for resampling. 46 // Source of data for resampling.
50 ReadCB read_cb_; 47 ReadCB read_cb_;
51 48
52 // Each channel has its own high quality resampler. 49 // Each channel has its own high quality resampler.
53 ScopedVector<SincResampler> resamplers_; 50 ScopedVector<SincResampler> resamplers_;
54 51
55 // Buffer for audio data going into SincResampler from ReadCB. Owned by this 52 // Buffers for audio data going into SincResampler from ReadCB.
56 // class and only temporarily passed out to ReadCB when data is required. 53 scoped_ptr<AudioBus> resampler_audio_bus_;
54 scoped_ptr<AudioBus> wrapped_resampler_audio_bus_;
57 std::vector<float*> resampler_audio_data_; 55 std::vector<float*> resampler_audio_data_;
58 }; 56 };
59 57
60 } // namespace media 58 } // namespace media
61 59
62 #endif // MEDIA_BASE_MULTI_CHANNEL_RESAMPLER_H_ 60 #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