Skip to content

Commit 45aace2

Browse files
committed
resample: clean up, sync with opus-tools version
- Do not define macros, functions, or variables with file scope using names beginning with an underscore (these names are reserved for the implementation; see C89 section 7.1.3 or any later version) or that shadow other global declarations - Avoid declarations after statements (speex_assert) for C89 compat - Silence unused parameter warning in resampler_basic_zero - No need for the stack_alloc.h macros within #ifdef VAR_ARRAYS; use the standard C syntax - When OUTSIDE_SPEEX, define EXPORT if not already defined - Update URL to https
1 parent 8ce055a commit 45aace2

File tree

8 files changed

+44
-45
lines changed

8 files changed

+44
-45
lines changed

configure.ac

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ fi],
184184
AC_DEFINE([FLOATING_POINT], , [Compile as floating-point]))
185185

186186
if test "$has_sse" = yes; then
187-
AC_DEFINE([_USE_SSE], , [Enable SSE support])
187+
AC_DEFINE([USE_SSE], , [Enable SSE support])
188188
fi
189189

190190
if test "$has_neon" = yes; then
191-
AC_DEFINE([_USE_NEON], , [Enable NEON support])
191+
AC_DEFINE([USE_NEON], , [Enable NEON support])
192192
fi
193193

194194
if test "$has_sse2" = yes; then
195-
AC_DEFINE([_USE_SSE2], , [Enable SSE2 support])
195+
AC_DEFINE([USE_SSE2], , [Enable SSE2 support])
196196
fi
197197

198198
AC_ARG_ENABLE(float-api, [ --disable-float-api Disable the floating-point API],

libspeexdsp/arch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#ifdef FLOATING_POINT
4242
#error You cannot compile as floating point and fixed point at the same time
4343
#endif
44-
#ifdef _USE_SSE
44+
#ifdef USE_SSE
4545
#error SSE is only for floating-point
4646
#endif
4747
#if ((defined (ARM4_ASM)||defined (ARM4_ASM)) && defined(BFIN_ASM)) || (defined (ARM4_ASM)&&defined(ARM5E_ASM))

libspeexdsp/resample.c

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
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
@@ -63,9 +63,12 @@
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

208208
struct 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)

libspeexdsp/resample_sse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static inline float interpolate_product_single(const float *a, const float *b, u
7171
return ret;
7272
}
7373

74-
#ifdef _USE_SSE2
74+
#ifdef USE_SSE2
7575
#include <emmintrin.h>
7676
#define OVERRIDE_INNER_PRODUCT_DOUBLE
7777

win32/VS2003/libspeexdsp/libspeexdsp.vcproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
FavorSizeOrSpeed="1"
121121
OptimizeForProcessor="3"
122122
AdditionalIncludeDirectories="..\..\..\include;..\.."
123-
PreprocessorDefinitions="_USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H"
123+
PreprocessorDefinitions="USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H"
124124
StringPooling="TRUE"
125125
ExceptionHandling="FALSE"
126126
RuntimeLibrary="0"
@@ -181,7 +181,7 @@
181181
FavorSizeOrSpeed="1"
182182
OptimizeForProcessor="3"
183183
AdditionalIncludeDirectories="..\..\..\include;..\.."
184-
PreprocessorDefinitions="_USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H"
184+
PreprocessorDefinitions="USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H"
185185
StringPooling="TRUE"
186186
ExceptionHandling="FALSE"
187187
RuntimeLibrary="2"

win32/VS2005/libspeexdsp/libspeexdsp.vcproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@
696696
EnableIntrinsicFunctions="true"
697697
FavorSizeOrSpeed="1"
698698
AdditionalIncludeDirectories="..\..\..\include;..\.."
699-
PreprocessorDefinitions="_USE_SSE;WIN32;NDEBUG;_LIB;HAVE_CONFIG_H"
699+
PreprocessorDefinitions="USE_SSE;WIN32;NDEBUG;_LIB;HAVE_CONFIG_H"
700700
StringPooling="true"
701701
ExceptionHandling="0"
702702
RuntimeLibrary="0"

win32/VS2008/libspeexdsp/libspeexdsp.vcproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
EnableIntrinsicFunctions="true"
183183
FavorSizeOrSpeed="1"
184184
AdditionalIncludeDirectories="..\..\..\include;..\.."
185-
PreprocessorDefinitions="_USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H"
185+
PreprocessorDefinitions="USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H"
186186
StringPooling="true"
187187
ExceptionHandling="0"
188188
RuntimeLibrary="2"
@@ -269,7 +269,7 @@
269269
EnableIntrinsicFunctions="true"
270270
FavorSizeOrSpeed="1"
271271
AdditionalIncludeDirectories="..\..\..\include;..\.."
272-
PreprocessorDefinitions="_USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H"
272+
PreprocessorDefinitions="USE_SSE;WIN32;NDEBUG;_WINDOWS;_USRDLL;HAVE_CONFIG_H"
273273
StringPooling="true"
274274
ExceptionHandling="0"
275275
RuntimeLibrary="2"

win32/config.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33

44
// In Visual Studio, _M_IX86_FP=1 means /arch:SSE was used, likewise
55
// _M_IX86_FP=2 means /arch:SSE2 was used.
6-
// Also, enable both _USE_SSE and _USE_SSE2 if we're compiling for x86-64
6+
// Also, enable both USE_SSE and USE_SSE2 if we're compiling for x86-64
77
#if _M_IX86_FP >= 1 || defined(_M_X64)
8-
#define _USE_SSE
8+
#define USE_SSE
99
#endif
1010

1111
#if _M_IX86_FP >= 2 || defined(_M_X64)
12-
#define _USE_SSE2
12+
#define USE_SSE2
1313
#endif
1414

1515
// Visual Studio support alloca(), but it always align variables to 16-bit
1616
// boundary, while SSE need 128-bit alignment. So we disable alloca() when
1717
// SSE is enabled.
18-
#ifndef _USE_SSE
18+
#ifndef USE_SSE
1919
# define USE_ALLOCA
2020
#endif
2121

0 commit comments

Comments
 (0)