Index: media/base/multi_channel_resampler.h |
diff --git a/media/base/multi_channel_resampler.h b/media/base/multi_channel_resampler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0b6491e8d74ff6dfe8597c6e674487dd5817f994 |
--- /dev/null |
+++ b/media/base/multi_channel_resampler.h |
@@ -0,0 +1,73 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_BASE_MULTI_CHANNEL_RESAMPLER_H_ |
+#define MEDIA_BASE_MULTI_CHANNEL_RESAMPLER_H_ |
+ |
+#include <vector> |
+ |
+#include "base/memory/scoped_ptr.h" |
+#include "media/base/sinc_resampler.h" |
+ |
+namespace media { |
+ |
+class MEDIA_EXPORT MultiChannelResampler |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
Add a class-level comment (what this does, how it'
DaleCurtis
2012/07/03 03:02:57
Done.
|
+ : public SincResampler::AudioSourceProvider { |
+ public: |
+ // Abstract base-class for a pulling data into the resampler. |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
english
DaleCurtis
2012/07/03 03:02:57
Removed.
|
+ class MultiChannelAudioSourceProvider { |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
Is this a provider of "audio source"s or a provide
DaleCurtis
2012/07/03 03:02:57
Just ReadCB now.
|
+ public: |
+ // ProvideInput() is called repeatedly to render time-slices of a continuous |
+ // multi channel audio stream. |
+ virtual void ProvideInput(const std::vector<float*>& audio_data, |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
|audio_data|'s format needs description.
My guess
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
When your interface is just one (or just a few) me
DaleCurtis
2012/07/01 23:27:46
I'm keeping style with AudioRendererSink::RenderCa
DaleCurtis
2012/07/03 03:02:57
Converted to Callback, kept RenderCallback style.
|
+ int number_of_frames) = 0; |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
fwiw, with a type of int, I think |frames| is clea
DaleCurtis
2012/07/01 23:27:46
Ditto. I prefer frames as well, but am going for c
Ami GONE FROM CHROMIUM
2012/07/01 23:44:44
Yep, in this case.
(note, also, consistency can wo
DaleCurtis
2012/07/02 17:43:45
sgtm.
DaleCurtis
2012/07/03 03:02:57
Done.
|
+ |
+ protected: |
+ virtual ~MultiChannelAudioSourceProvider() {} |
+ }; |
+ |
+ // Constructs a MultiChannelResampler with the specified |provider|, which is |
+ // used to acquire data for all channels during resampling. |scale_factor| is |
+ // input_sample_rate / output_sample_rate. |
+ // TODO(dalecurtis): Should provider be a const ref? Need to make ProvideInput |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
TODO goes away with my callback suggestion above.
DaleCurtis
2012/07/03 03:02:57
Removed.
|
+ // const if so... Following the RenderCallback model currently. |
+ MultiChannelResampler(MultiChannelAudioSourceProvider* provider, |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
generally output params follow input params, so th
DaleCurtis
2012/07/03 03:02:57
These are all input parameters? I moved the CB to
|
+ double scale_factor, int number_of_channels); |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
s/scale_factor/io_sample_rate_ratio/ is clearer?
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
FWIW, number_of_channels is implicit in the Provid
DaleCurtis
2012/07/03 03:02:57
Doesn't really save anything and makes the already
|
+ virtual ~MultiChannelResampler(); |
+ |
+ // Resample |number_of_frames| of data from |provider_| into |audio_data|. |
+ void Resample(const std::vector<float*>& audio_data, int number_of_frames); |
+ |
+ private: |
+ int number_of_channels_; |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
const
DaleCurtis
2012/07/03 03:02:57
Removed.
|
+ |
+ // Index of the channel currently being processed. |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
This and the next two members are used mostly for
DaleCurtis
2012/07/03 03:02:57
I was able to bind away channel_index_, but I don'
|
+ size_t channel_index_; |
+ |
+ // Number of frames requested by SincResampler from ProvideInput() when the |
+ // |channel_index_| was 0. |
+ int last_frame_count_; |
+ |
+ // Sanity check to ensure ProvideInput() is only called once per channel. |
+ size_t callback_count_; |
+ |
+ // Source of data for resampling. |
+ MultiChannelAudioSourceProvider* provider_; |
+ |
+ // Each channel has its own high quality resampler. |
+ std::vector<SincResampler*> resamplers_; |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
ScopedVector
DaleCurtis
2012/07/03 03:02:57
Done.
|
+ |
+ // Staging area for data between the MultiChannelAudioSourceProvider and the |
+ // SincResampler. |
+ std::vector<float*> resampler_audio_data_; |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
vector<scoped_array<float> > would be clearer abou
DaleCurtis
2012/07/01 23:27:46
I don't think I can pass that along via RenderCall
Ami GONE FROM CHROMIUM
2012/07/01 23:44:44
Ouch (great example of how API choices propagate..
DaleCurtis
2012/07/02 17:43:45
Actually, I don't know what I was talking about. I
DaleCurtis
2012/07/03 03:02:57
Actually, that's not true, I remember what I was t
|
+ |
+ // SincResampler::AudioSourceProvider implementation. ProvideInput() will be |
+ // called once for each channel, starting with the first channel. Each time |
Ami GONE FROM CHROMIUM
2012/06/30 20:12:14
s/starting with the first channel/in channel order
DaleCurtis
2012/07/03 03:02:57
Done.
|
+ // it's called, it will provide the next channel of data. |
+ virtual void ProvideInput(float* destination, int number_of_frames) OVERRIDE; |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_MULTI_CHANNEL_RESAMPLER_H_ |