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