diff options
Diffstat (limited to 'src/pcm')
-rw-r--r-- | src/pcm/PcmConvert.cxx | 68 | ||||
-rw-r--r-- | src/pcm/PcmConvert.hxx | 36 | ||||
-rw-r--r-- | src/pcm/PcmResample.cxx | 8 | ||||
-rw-r--r-- | src/pcm/PcmResampleFallback.cxx | 8 | ||||
-rw-r--r-- | src/pcm/PcmResampleInternal.hxx | 4 |
5 files changed, 70 insertions, 54 deletions
diff --git a/src/pcm/PcmConvert.cxx b/src/pcm/PcmConvert.cxx index 8eafe527c..cca2f701e 100644 --- a/src/pcm/PcmConvert.cxx +++ b/src/pcm/PcmConvert.cxx @@ -32,23 +32,48 @@ const Domain pcm_convert_domain("pcm_convert"); PcmConvert::PcmConvert() { +#ifndef NDEBUG + src_format.Clear(); + dest_format.Clear(); +#endif } PcmConvert::~PcmConvert() { + assert(!src_format.IsValid()); + assert(!dest_format.IsValid()); +} + +bool +PcmConvert::Open(AudioFormat _src_format, AudioFormat _dest_format, + gcc_unused Error &error) +{ + assert(!src_format.IsValid()); + assert(!dest_format.IsValid()); + assert(_src_format.IsValid()); + assert(_dest_format.IsValid()); + + src_format = _src_format; + dest_format = _dest_format; + + return true; } void -PcmConvert::Reset() +PcmConvert::Close() { dsd.Reset(); resampler.Reset(); + +#ifndef NDEBUG + src_format.Clear(); + dest_format.Clear(); +#endif } inline const int16_t * -PcmConvert::Convert16(const AudioFormat src_format, - const void *src_buffer, size_t src_size, - const AudioFormat dest_format, size_t *dest_size_r, +PcmConvert::Convert16(const void *src_buffer, size_t src_size, + size_t *dest_size_r, Error &error) { const int16_t *buf; @@ -96,9 +121,8 @@ PcmConvert::Convert16(const AudioFormat src_format, } inline const int32_t * -PcmConvert::Convert24(const AudioFormat src_format, - const void *src_buffer, size_t src_size, - const AudioFormat dest_format, size_t *dest_size_r, +PcmConvert::Convert24(const void *src_buffer, size_t src_size, + size_t *dest_size_r, Error &error) { const int32_t *buf; @@ -145,9 +169,8 @@ PcmConvert::Convert24(const AudioFormat src_format, } inline const int32_t * -PcmConvert::Convert32(const AudioFormat src_format, - const void *src_buffer, size_t src_size, - const AudioFormat dest_format, size_t *dest_size_r, +PcmConvert::Convert32(const void *src_buffer, size_t src_size, + size_t *dest_size_r, Error &error) { const int32_t *buf; @@ -194,9 +217,8 @@ PcmConvert::Convert32(const AudioFormat src_format, } inline const float * -PcmConvert::ConvertFloat(const AudioFormat src_format, - const void *src_buffer, size_t src_size, - const AudioFormat dest_format, size_t *dest_size_r, +PcmConvert::ConvertFloat(const void *src_buffer, size_t src_size, + size_t *dest_size_r, Error &error) { const float *buffer = (const float *)src_buffer; @@ -251,9 +273,7 @@ PcmConvert::ConvertFloat(const AudioFormat src_format, } const void * -PcmConvert::Convert(AudioFormat src_format, - const void *src, size_t src_size, - const AudioFormat dest_format, +PcmConvert::Convert(const void *src, size_t src_size, size_t *dest_size_r, Error &error) { @@ -279,23 +299,23 @@ PcmConvert::Convert(AudioFormat src_format, switch (dest_format.format) { case SampleFormat::S16: - return Convert16(src_format, src, src_size, - dest_format, dest_size_r, + return Convert16(src, src_size, + dest_size_r, error); case SampleFormat::S24_P32: - return Convert24(src_format, src, src_size, - dest_format, dest_size_r, + return Convert24(src, src_size, + dest_size_r, error); case SampleFormat::S32: - return Convert32(src_format, src, src_size, - dest_format, dest_size_r, + return Convert32(src, src_size, + dest_size_r, error); case SampleFormat::FLOAT: - return ConvertFloat(src_format, src, src_size, - dest_format, dest_size_r, + return ConvertFloat(src, src_size, + dest_size_r, error); default: diff --git a/src/pcm/PcmConvert.hxx b/src/pcm/PcmConvert.hxx index 40f785179..4bace1d36 100644 --- a/src/pcm/PcmConvert.hxx +++ b/src/pcm/PcmConvert.hxx @@ -24,10 +24,10 @@ #include "PcmDsd.hxx" #include "PcmResample.hxx" #include "PcmBuffer.hxx" +#include "AudioFormat.hxx" #include <stddef.h> -struct AudioFormat; class Error; /** @@ -48,17 +48,23 @@ class PcmConvert { /** the buffer for converting the channel count */ PcmBuffer channels_buffer; + AudioFormat src_format, dest_format; + public: PcmConvert(); ~PcmConvert(); + /** + * Prepare the object. Call Close() when done. + */ + bool Open(AudioFormat _src_format, AudioFormat _dest_format, + Error &error); /** - * Reset the pcm_convert_state object. Use this at the - * boundary between two distinct songs and each time the - * format changes. + * Close the object after it was prepared with Open(). After + * that, it may be reused by calling Open() again. */ - void Reset(); + void Close(); /** * Converts PCM data between two audio formats. @@ -72,34 +78,24 @@ public: * ignore errors * @return the destination buffer, or NULL on error */ - const void *Convert(AudioFormat src_format, - const void *src, size_t src_size, - AudioFormat dest_format, + const void *Convert(const void *src, size_t src_size, size_t *dest_size_r, Error &error); private: - const int16_t *Convert16(AudioFormat src_format, - const void *src_buffer, size_t src_size, - AudioFormat dest_format, + const int16_t *Convert16(const void *src_buffer, size_t src_size, size_t *dest_size_r, Error &error); - const int32_t *Convert24(AudioFormat src_format, - const void *src_buffer, size_t src_size, - AudioFormat dest_format, + const int32_t *Convert24(const void *src_buffer, size_t src_size, size_t *dest_size_r, Error &error); - const int32_t *Convert32(AudioFormat src_format, - const void *src_buffer, size_t src_size, - AudioFormat dest_format, + const int32_t *Convert32(const void *src_buffer, size_t src_size, size_t *dest_size_r, Error &error); - const float *ConvertFloat(AudioFormat src_format, - const void *src_buffer, size_t src_size, - AudioFormat dest_format, + const float *ConvertFloat(const void *src_buffer, size_t src_size, size_t *dest_size_r, Error &error); }; diff --git a/src/pcm/PcmResample.cxx b/src/pcm/PcmResample.cxx index 01f269ea9..b30e01407 100644 --- a/src/pcm/PcmResample.cxx +++ b/src/pcm/PcmResample.cxx @@ -101,7 +101,7 @@ PcmResampler::ResampleFloat(unsigned channels, unsigned src_rate, not do any math on the sample values, so this hack is possible: */ return (const float *) - pcm_resample_fallback_32(this, channels, + pcm_resample_fallback_32(buffer, channels, src_rate, (const int32_t *)src_buffer, src_size, dest_rate, dest_size_r); @@ -123,7 +123,7 @@ PcmResampler::Resample16(unsigned channels, (void)error_r; #endif - return pcm_resample_fallback_16(this, channels, + return pcm_resample_fallback_16(buffer, channels, src_rate, src_buffer, src_size, dest_rate, dest_size_r); } @@ -144,7 +144,7 @@ PcmResampler::Resample32(unsigned channels, unsigned src_rate, (void)error_r; #endif - return pcm_resample_fallback_32(this, channels, + return pcm_resample_fallback_32(buffer, channels, src_rate, src_buffer, src_size, dest_rate, dest_size_r); } @@ -167,7 +167,7 @@ PcmResampler::Resample24(unsigned channels, unsigned src_rate, /* reuse the 32 bit code - the resampler code doesn't care if the upper 8 bits are actually used */ - return pcm_resample_fallback_32(this, channels, + return pcm_resample_fallback_32(buffer, channels, src_rate, src_buffer, src_size, dest_rate, dest_size_r); } diff --git a/src/pcm/PcmResampleFallback.cxx b/src/pcm/PcmResampleFallback.cxx index a62cd64f7..ca92e5a83 100644 --- a/src/pcm/PcmResampleFallback.cxx +++ b/src/pcm/PcmResampleFallback.cxx @@ -24,7 +24,7 @@ /* resampling code blatantly ripped from ESD */ const int16_t * -pcm_resample_fallback_16(PcmResampler *state, +pcm_resample_fallback_16(PcmBuffer &buffer, unsigned channels, unsigned src_rate, const int16_t *src_buffer, size_t src_size, @@ -37,7 +37,7 @@ pcm_resample_fallback_16(PcmResampler *state, (src_frames * dest_rate + src_rate - 1) / src_rate; unsigned dest_samples = dest_frames * channels; size_t dest_size = dest_samples * sizeof(*src_buffer); - int16_t *dest_buffer = (int16_t *)state->buffer.Get(dest_size); + int16_t *dest_buffer = (int16_t *)buffer.Get(dest_size); assert((src_size % (sizeof(*src_buffer) * channels)) == 0); @@ -65,7 +65,7 @@ pcm_resample_fallback_16(PcmResampler *state, } const int32_t * -pcm_resample_fallback_32(PcmResampler *state, +pcm_resample_fallback_32(PcmBuffer &buffer, unsigned channels, unsigned src_rate, const int32_t *src_buffer, size_t src_size, @@ -78,7 +78,7 @@ pcm_resample_fallback_32(PcmResampler *state, (src_frames * dest_rate + src_rate - 1) / src_rate; unsigned dest_samples = dest_frames * channels; size_t dest_size = dest_samples * sizeof(*src_buffer); - int32_t *dest_buffer = (int32_t *)state->buffer.Get(dest_size); + int32_t *dest_buffer = (int32_t *)buffer.Get(dest_size); assert((src_size % (sizeof(*src_buffer) * channels)) == 0); diff --git a/src/pcm/PcmResampleInternal.hxx b/src/pcm/PcmResampleInternal.hxx index 5090c13d1..94cef94ff 100644 --- a/src/pcm/PcmResampleInternal.hxx +++ b/src/pcm/PcmResampleInternal.hxx @@ -81,7 +81,7 @@ pcm_resample_lsr_24(PcmResampler *state, #endif const int16_t * -pcm_resample_fallback_16(PcmResampler *state, +pcm_resample_fallback_16(PcmBuffer &buffer, unsigned channels, unsigned src_rate, const int16_t *src_buffer, size_t src_size, @@ -89,7 +89,7 @@ pcm_resample_fallback_16(PcmResampler *state, size_t *dest_size_r); const int32_t * -pcm_resample_fallback_32(PcmResampler *state, +pcm_resample_fallback_32(PcmBuffer &buffer, unsigned channels, unsigned src_rate, const int32_t *src_buffer, |