4646 Smith, Julius O. Digital Audio Resampling Home Page
4747 Center for Computer Research in Music and Acoustics (CCRMA),
4848 Stanford University, 2007.
49- Web published at http ://ccrma.stanford.edu/~jos/resample/.
49+ Web published at https ://ccrma.stanford.edu/~jos/resample/.
5050
5151 There is one main difference, though. This resampler uses cubic
5252 interpolation instead of linear interpolation in the above paper. This
6363
6464#ifdef OUTSIDE_SPEEX
6565#include <stdlib.h>
66- static void * speex_alloc (int size ) {return calloc (size ,1 );}
67- static void * speex_realloc (void * ptr , int size ) {return realloc (ptr , size );}
68- static void speex_free (void * ptr ) {free (ptr );}
66+ static void * speex_alloc (int size ) {return calloc (size ,1 );}
67+ static void * speex_realloc (void * ptr , int size ) {return realloc (ptr , size );}
68+ static void speex_free (void * ptr ) {free (ptr );}
69+ #ifndef EXPORT
70+ #define EXPORT
71+ #endif
6972#include "speex_resampler.h"
7073#include "arch.h"
7174#else /* OUTSIDE_SPEEX */
@@ -75,7 +78,6 @@ static void speex_free (void *ptr) {free(ptr);}
7578#include "os_support.h"
7679#endif /* OUTSIDE_SPEEX */
7780
78- #include "stack_alloc.h"
7981#include <math.h>
8082#include <limits.h>
8183
@@ -94,11 +96,11 @@ static void speex_free (void *ptr) {free(ptr);}
9496#define UINT32_MAX 4294967296U
9597#endif
9698
97- #ifdef _USE_SSE
99+ #ifdef USE_SSE
98100#include "resample_sse.h"
99101#endif
100102
101- #ifdef _USE_NEON
103+ #ifdef USE_NEON
102104#include "resample_neon.h"
103105#endif
104106
@@ -194,16 +196,14 @@ struct FuncDef {
194196 int oversample ;
195197};
196198
197- static const struct FuncDef _KAISER12 = {kaiser12_table , 64 };
198- #define KAISER12 (&_KAISER12)
199- /*static struct FuncDef _KAISER12 = {kaiser12_table, 32};
200- #define KAISER12 (&_KAISER12)*/
201- static const struct FuncDef _KAISER10 = {kaiser10_table , 32 };
202- #define KAISER10 (&_KAISER10)
203- static const struct FuncDef _KAISER8 = {kaiser8_table , 32 };
204- #define KAISER8 (&_KAISER8)
205- static const struct FuncDef _KAISER6 = {kaiser6_table , 32 };
206- #define KAISER6 (&_KAISER6)
199+ static const struct FuncDef kaiser12_funcdef = {kaiser12_table , 64 };
200+ #define KAISER12 (&kaiser12_funcdef)
201+ static const struct FuncDef kaiser10_funcdef = {kaiser10_table , 32 };
202+ #define KAISER10 (&kaiser10_funcdef)
203+ static const struct FuncDef kaiser8_funcdef = {kaiser8_table , 32 };
204+ #define KAISER8 (&kaiser8_funcdef)
205+ static const struct FuncDef kaiser6_funcdef = {kaiser6_table , 32 };
206+ #define KAISER6 (&kaiser6_funcdef)
207207
208208struct QualityMapping {
209209 int base_length ;
@@ -572,6 +572,7 @@ static int resampler_basic_zero(SpeexResamplerState *st, spx_uint32_t channel_in
572572 const int frac_advance = st -> frac_advance ;
573573 const spx_uint32_t den_rate = st -> den_rate ;
574574
575+ (void )in ;
575576 while (!(last_sample >= (spx_int32_t )* in_len || out_sample >= (spx_int32_t )* out_len ))
576577 {
577578 out [out_stride * out_sample ++ ] = 0 ;
@@ -589,16 +590,15 @@ static int resampler_basic_zero(SpeexResamplerState *st, spx_uint32_t channel_in
589590 return out_sample ;
590591}
591592
592- static int _muldiv (spx_uint32_t * result , spx_uint32_t value , spx_uint32_t mul , spx_uint32_t div )
593+ static int multiply_frac (spx_uint32_t * result , spx_uint32_t value , spx_uint32_t num , spx_uint32_t den )
593594{
594- speex_assert (result );
595- spx_uint32_t major = value / div ;
596- spx_uint32_t remainder = value % div ;
595+ spx_uint32_t major = value / den ;
596+ spx_uint32_t remain = value % den ;
597597 /* TODO: Could use 64 bits operation to check for overflow. But only guaranteed in C99+ */
598- if (remainder > UINT32_MAX / mul || major > UINT32_MAX / mul
599- || major * mul > UINT32_MAX - remainder * mul / div )
598+ if (remain > UINT32_MAX / num || major > UINT32_MAX / num
599+ || major * num > UINT32_MAX - remain * num / den )
600600 return RESAMPLER_ERR_OVERFLOW ;
601- * result = remainder * mul / div + major * mul ;
601+ * result = remain * num / den + major * num ;
602602 return RESAMPLER_ERR_SUCCESS ;
603603}
604604
@@ -619,7 +619,7 @@ static int update_filter(SpeexResamplerState *st)
619619 {
620620 /* down-sampling */
621621 st -> cutoff = quality_map [st -> quality ].downsample_bandwidth * st -> den_rate / st -> num_rate ;
622- if (_muldiv (& st -> filt_len ,st -> filt_len ,st -> num_rate ,st -> den_rate ) != RESAMPLER_ERR_SUCCESS )
622+ if (multiply_frac (& st -> filt_len ,st -> filt_len ,st -> num_rate ,st -> den_rate ) != RESAMPLER_ERR_SUCCESS )
623623 goto fail ;
624624 /* Round up to make sure we have a multiple of 8 for SSE */
625625 st -> filt_len = ((st -> filt_len - 1 )& (~0x7 ))+ 8 ;
@@ -638,12 +638,12 @@ static int update_filter(SpeexResamplerState *st)
638638 st -> cutoff = quality_map [st -> quality ].upsample_bandwidth ;
639639 }
640640
641- /* Choose the resampling type that requires the least amount of memory */
642641#ifdef RESAMPLE_FULL_SINC_TABLE
643642 use_direct = 1 ;
644643 if (INT_MAX /sizeof (spx_word16_t )/st -> den_rate < st -> filt_len )
645644 goto fail ;
646645#else
646+ /* Choose the resampling type that requires the least amount of memory */
647647 use_direct = st -> filt_len * st -> den_rate <= st -> filt_len * st -> oversample + 8
648648 && INT_MAX /sizeof (spx_word16_t )/st -> den_rate >= st -> filt_len ;
649649#endif
@@ -977,8 +977,7 @@ EXPORT int speex_resampler_process_int(SpeexResamplerState *st, spx_uint32_t cha
977977 const spx_uint32_t xlen = st -> mem_alloc_size - (st -> filt_len - 1 );
978978#ifdef VAR_ARRAYS
979979 const unsigned int ylen = (olen < FIXED_STACK_ALLOC ) ? olen : FIXED_STACK_ALLOC ;
980- VARDECL (spx_word16_t * ystack );
981- ALLOC (ystack , ylen , spx_word16_t );
980+ spx_word16_t ystack [ylen ];
982981#else
983982 const unsigned int ylen = FIXED_STACK_ALLOC ;
984983 spx_word16_t ystack [FIXED_STACK_ALLOC ];
@@ -1093,7 +1092,7 @@ EXPORT void speex_resampler_get_rate(SpeexResamplerState *st, spx_uint32_t *in_r
10931092 * out_rate = st -> out_rate ;
10941093}
10951094
1096- static inline spx_uint32_t _gcd (spx_uint32_t a , spx_uint32_t b )
1095+ static inline spx_uint32_t compute_gcd (spx_uint32_t a , spx_uint32_t b )
10971096{
10981097 while (b != 0 )
10991098 {
@@ -1123,7 +1122,7 @@ EXPORT int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t r
11231122 st -> num_rate = ratio_num ;
11241123 st -> den_rate = ratio_den ;
11251124
1126- fact = _gcd (st -> num_rate , st -> den_rate );
1125+ fact = compute_gcd (st -> num_rate , st -> den_rate );
11271126
11281127 st -> num_rate /= fact ;
11291128 st -> den_rate /= fact ;
@@ -1132,7 +1131,7 @@ EXPORT int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t r
11321131 {
11331132 for (i = 0 ;i < st -> nb_channels ;i ++ )
11341133 {
1135- if (_muldiv (& st -> samp_frac_num [i ],st -> samp_frac_num [i ],st -> den_rate ,old_den ) != RESAMPLER_ERR_SUCCESS )
1134+ if (multiply_frac (& st -> samp_frac_num [i ],st -> samp_frac_num [i ],st -> den_rate ,old_den ) != RESAMPLER_ERR_SUCCESS )
11361135 return RESAMPLER_ERR_OVERFLOW ;
11371136 /* Safety net */
11381137 if (st -> samp_frac_num [i ] >= st -> den_rate )
0 commit comments