From 1ee7b56befc16d0940bd162f3ac9b6ae66e85f0b Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 14 Aug 2007 16:21:52 +0200 Subject: Update speex rate converter code Take speex rate converter code from speex SVN tree, which includes the fix for the noises with simple conversion (signed / unsigned mismatch). --- pph/speex_resampler.h | 65 +++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 31 deletions(-) (limited to 'pph/speex_resampler.h') diff --git a/pph/speex_resampler.h b/pph/speex_resampler.h index 1499ce0..c44fbcd 100644 --- a/pph/speex_resampler.h +++ b/pph/speex_resampler.h @@ -69,31 +69,16 @@ #define speex_resampler_get_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality) #define speex_resampler_set_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride) #define speex_resampler_get_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride) -#define speex_resample_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resample_set_output_stride) -#define speex_resample_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resample_get_output_stride) +#define speex_resampler_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride) +#define speex_resampler_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride) #define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros) #define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem) +#define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror) #define spx_int16_t short #define spx_int32_t int #define spx_uint16_t unsigned short #define spx_uint32_t unsigned int - -#if 0 -#ifdef FIXED_POINT -/*#define spx_word16_t spx_int16_t -#define spx_word32_t spx_int32_t*/ -#include "arch.h" - -#else /* FIXED_POINT */ - -#define spx_word16_t float -#define spx_word32_t float -#define MULT16_16(a,b) ((a)*(b)) -#define MULT16_32_Q15(a,b) ((a)*(b)) -#define PSHR32(a,b) (a) -#endif /* FIXED_POINT */ -#endif #else /* OUTSIDE_SPEEX */ @@ -110,7 +95,17 @@ extern "C" { #define SPEEX_RESAMPLER_QUALITY_DEFAULT 4 #define SPEEX_RESAMPLER_QUALITY_VOIP 3 #define SPEEX_RESAMPLER_QUALITY_DESKTOP 5 + +enum { + RESAMPLER_ERR_SUCCESS = 0, + RESAMPLER_ERR_ALLOC_FAILED = 1, + RESAMPLER_ERR_BAD_STATE = 2, + RESAMPLER_ERR_INVALID_ARG = 3, + RESAMPLER_ERR_PTR_OVERLAP = 4, + RESAMPLER_ERR_MAX_ERROR +}; + struct SpeexResamplerState_; typedef struct SpeexResamplerState_ SpeexResamplerState; @@ -126,7 +121,8 @@ typedef struct SpeexResamplerState_ SpeexResamplerState; SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels, spx_uint32_t in_rate, spx_uint32_t out_rate, - int quality); + int quality, + int *err); /** Create a new resampler with fractional input/output rates. The sampling * rate ratio is an arbitrary rational number with both the numerator and @@ -146,7 +142,8 @@ SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels, spx_uint32_t ratio_den, spx_uint32_t in_rate, spx_uint32_t out_rate, - int quality); + int quality, + int *err); /** Destroy a resampler state. * @param st Resampler state @@ -163,7 +160,7 @@ void speex_resampler_destroy(SpeexResamplerState *st); * @param out Output buffer * @param out_len Size of the output buffer. Returns the number of samples written */ -void speex_resampler_process_float(SpeexResamplerState *st, +int speex_resampler_process_float(SpeexResamplerState *st, spx_uint32_t channel_index, const float *in, spx_uint32_t *in_len, @@ -180,7 +177,7 @@ void speex_resampler_process_float(SpeexResamplerState *st, * @param out Output buffer * @param out_len Size of the output buffer. Returns the number of samples written */ -void speex_resampler_process_int(SpeexResamplerState *st, +int speex_resampler_process_int(SpeexResamplerState *st, spx_uint32_t channel_index, const spx_int16_t *in, spx_uint32_t *in_len, @@ -196,7 +193,7 @@ void speex_resampler_process_int(SpeexResamplerState *st, * @param out_len Size of the output buffer. Returns the number of samples written. * This is all per-channel. */ -void speex_resampler_process_interleaved_float(SpeexResamplerState *st, +int speex_resampler_process_interleaved_float(SpeexResamplerState *st, const float *in, spx_uint32_t *in_len, float *out, @@ -211,7 +208,7 @@ void speex_resampler_process_interleaved_float(SpeexResamplerState *st, * @param out_len Size of the output buffer. Returns the number of samples written. * This is all per-channel. */ -void speex_resampler_process_interleaved_int(SpeexResamplerState *st, +int speex_resampler_process_interleaved_int(SpeexResamplerState *st, const spx_int16_t *in, spx_uint32_t *in_len, spx_int16_t *out, @@ -222,7 +219,7 @@ void speex_resampler_process_interleaved_int(SpeexResamplerState *st, * @param in_rate Input sampling rate (integer number of Hz). * @param out_rate Output sampling rate (integer number of Hz). */ -void speex_resampler_set_rate(SpeexResamplerState *st, +int speex_resampler_set_rate(SpeexResamplerState *st, spx_uint32_t in_rate, spx_uint32_t out_rate); @@ -243,7 +240,7 @@ void speex_resampler_get_rate(SpeexResamplerState *st, * @param in_rate Input sampling rate rounded to the nearest integer (in Hz). * @param out_rate Output sampling rate rounded to the nearest integer (in Hz). */ -void speex_resampler_set_rate_frac(SpeexResamplerState *st, +int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, @@ -264,7 +261,7 @@ void speex_resampler_get_ratio(SpeexResamplerState *st, * @param quality Resampling quality between 0 and 10, where 0 has poor * quality and 10 has very high quality. */ -void speex_resampler_set_quality(SpeexResamplerState *st, +int speex_resampler_set_quality(SpeexResamplerState *st, int quality); /** Get the conversion quality. @@ -293,14 +290,14 @@ void speex_resampler_get_input_stride(SpeexResamplerState *st, * @param st Resampler state * @param stride Output stride */ -void speex_resample_set_output_stride(SpeexResamplerState *st, +void speex_resampler_set_output_stride(SpeexResamplerState *st, spx_uint32_t stride); /** Get the output stride. * @param st Resampler state copied * @param stride Output stride */ -void speex_resample_get_output_stride(SpeexResamplerState *st, +void speex_resampler_get_output_stride(SpeexResamplerState *st, spx_uint32_t *stride); /** Make sure that the first samples to go out of the resamplers don't have @@ -311,12 +308,18 @@ void speex_resample_get_output_stride(SpeexResamplerState *st, * is the same for the first frame). * @param st Resampler state */ -void speex_resampler_skip_zeros(SpeexResamplerState *st); +int speex_resampler_skip_zeros(SpeexResamplerState *st); /** Reset a resampler so a new (unrelated) stream can be processed. * @param st Resampler state */ -void speex_resampler_reset_mem(SpeexResamplerState *st); +int speex_resampler_reset_mem(SpeexResamplerState *st); + +/** Returns the English meaning for an error code + * @param err Error code + * @return English string + */ +const char *speex_resampler_strerror(int err); #ifdef __cplusplus } -- cgit