diff --git a/02_day/test-resample/Android.mk b/02_day/test-resample/Android.mk index 5d9ca4f..828bb26 100644 --- a/02_day/test-resample/Android.mk +++ b/02_day/test-resample/Android.mk @@ -1,6 +1,5 @@ LOCAL_PATH:= $(call my-dir) - include $(CLEAR_VARS) LOCAL_SRC_FILES:= \ @@ -25,3 +24,4 @@ LOCAL_MODULE:= test-resample LOCAL_MODULE_TAGS := optional include $(BUILD_EXECUTABLE) + diff --git a/02_day/test-resample/AudioResampler.h b/02_day/test-resample/AudioResampler.h index cdc6d92..a8e3e6f 100644 --- a/02_day/test-resample/AudioResampler.h +++ b/02_day/test-resample/AudioResampler.h @@ -19,7 +19,9 @@ #include #include + #include +#include #include #include @@ -47,7 +49,7 @@ public: DYN_HIGH_QUALITY=7, }; - static const float UNITY_GAIN_FLOAT = 1.0f; + static const CONSTEXPR float UNITY_GAIN_FLOAT = 1.0f; static AudioResampler* create(audio_format_t format, int inChannelCount, int32_t sampleRate, src_quality quality=DEFAULT_QUALITY); @@ -65,12 +67,18 @@ public: // Resample int16_t samples from provider and accumulate into 'out'. // A mono provider delivers a sequence of samples. // A stereo provider delivers a sequence of interleaved pairs of samples. - // Multi-channel providers are not supported. + // // In either case, 'out' holds interleaved pairs of fixed-point Q4.27. // That is, for a mono provider, there is an implicit up-channeling. // Since this method accumulates, the caller is responsible for clearing 'out' initially. - // FIXME assumes provider is always successful; it should return the actual frame count. - virtual void resample(int32_t* out, size_t outFrameCount, + // + // For a float resampler, 'out' holds interleaved pairs of float samples. + // + // Multichannel interleaved frames for n > 2 is supported for quality DYN_LOW_QUALITY, + // DYN_MED_QUALITY, and DYN_HIGH_QUALITY. + // + // Returns the number of frames resampled into the out buffer. + virtual size_t resample(int32_t* out, size_t outFrameCount, AudioBufferProvider* provider) = 0; virtual void reset(); @@ -168,7 +176,6 @@ private: }; // ---------------------------------------------------------------------------- -} -; // namespace android +} // namespace android #endif // ANDROID_AUDIO_RESAMPLER_H diff --git a/02_day/test-resample/test-resample.cpp b/02_day/test-resample/test-resample.cpp index 84a655a..7893778 100644 --- a/02_day/test-resample/test-resample.cpp +++ b/02_day/test-resample/test-resample.cpp @@ -427,6 +427,14 @@ int main(int argc, char* argv[]) { printf("quality: %d channels: %d msec: %" PRId64 " Mfrms/s: %.2lf\n", quality, channels, time/1000000, output_frames * looplimit / (time / 1e9) / 1e6); resampler->reset(); + + // TODO fix legacy bug: reset does not clear buffers. + // delete and recreate resampler here. + delete resampler; + resampler = AudioResampler::create(format, channels, + output_freq, quality); + resampler->setSampleRate(input_freq); + resampler->setVolume(AudioResampler::UNITY_GAIN_FLOAT, AudioResampler::UNITY_GAIN_FLOAT); } memset(output_vaddr, 0, output_size);