Skip to content

Commit 6f5a598

Browse files
kinetiknzpadenot
authored andcommitted
speexdsp: Update to 7a158783df74efe7c2d1c6ee8363c1e695c71226.
1 parent 19994eb commit 6f5a598

File tree

6 files changed

+215
-195
lines changed

6 files changed

+215
-195
lines changed

subprojects/speex/arch.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
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
47-
#if ((defined (ARM4_ASM)||defined (ARM4_ASM)) && defined(BFIN_ASM)) || (defined (ARM4_ASM)&&defined(ARM5E_ASM))
47+
#if defined(ARM4_ASM) + defined(ARM5E_ASM) + defined(BFIN_ASM) > 1
4848
#error Make up your mind. What CPU do you have?
4949
#endif
5050
#ifdef VORBIS_PSYCHO
@@ -56,10 +56,10 @@
5656
#ifndef FLOATING_POINT
5757
#error You now need to define either FIXED_POINT or FLOATING_POINT
5858
#endif
59-
#if defined (ARM4_ASM) || defined(ARM5E_ASM) || defined(BFIN_ASM)
59+
#if defined(ARM4_ASM) || defined(ARM5E_ASM) || defined(BFIN_ASM)
6060
#error I suppose you can have a [ARM4/ARM5E/Blackfin] that has float instructions?
6161
#endif
62-
#ifdef FIXED_POINT_DEBUG
62+
#ifdef FIXED_DEBUG
6363
#error "Don't you think enabling fixed-point is a good thing to do if you want to debug that?"
6464
#endif
6565

@@ -117,9 +117,9 @@ typedef spx_word32_t spx_sig_t;
117117

118118
#ifdef ARM5E_ASM
119119
#include "fixed_arm5e.h"
120-
#elif defined (ARM4_ASM)
120+
#elif defined(ARM4_ASM)
121121
#include "fixed_arm4.h"
122-
#elif defined (BFIN_ASM)
122+
#elif defined(BFIN_ASM)
123123
#include "fixed_bfin.h"
124124
#endif
125125

@@ -177,16 +177,13 @@ typedef float spx_word32_t;
177177
#define ADD32(a,b) ((a)+(b))
178178
#define SUB32(a,b) ((a)-(b))
179179
#define MULT16_16_16(a,b) ((a)*(b))
180+
#define MULT16_32_32(a,b) ((a)*(b))
180181
#define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b))
181182
#define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b))
182183

183-
#define MULT16_32_Q11(a,b) ((a)*(b))
184-
#define MULT16_32_Q13(a,b) ((a)*(b))
185-
#define MULT16_32_Q14(a,b) ((a)*(b))
186184
#define MULT16_32_Q15(a,b) ((a)*(b))
187185
#define MULT16_32_P15(a,b) ((a)*(b))
188186

189-
#define MAC16_32_Q11(c,a,b) ((c)+(a)*(b))
190187
#define MAC16_32_Q15(c,a,b) ((c)+(a)*(b))
191188

192189
#define MAC16_16_Q11(c,a,b) ((c)+(a)*(b))
@@ -210,7 +207,7 @@ typedef float spx_word32_t;
210207
#endif
211208

212209

213-
#if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
210+
#if defined(CONFIG_TI_C54X) || defined(CONFIG_TI_C55X)
214211

215212
/* 2 on TI C5x DSP */
216213
#define BYTES_PER_CHAR 2

subprojects/speex/fixed_generic.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,18 @@
6969

7070

7171
/* result fits in 16 bits */
72-
#define MULT16_16_16(a,b) ((((spx_word16_t)(a))*((spx_word16_t)(b))))
72+
#define MULT16_16_16(a,b) (((spx_word16_t)(a))*((spx_word16_t)(b)))
73+
/* result fits in 32 bits */
74+
#define MULT16_32_32(a,b) (((spx_word16_t)(a))*((spx_word32_t)(b)))
7375

7476
/* (spx_word32_t)(spx_word16_t) gives TI compiler a hint that it's 16x16->32 multiply */
7577
#define MULT16_16(a,b) (((spx_word32_t)(spx_word16_t)(a))*((spx_word32_t)(spx_word16_t)(b)))
7678

7779
#define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b))))
78-
#define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12))
79-
#define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))
80-
#define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14))
8180

82-
#define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))
83-
#define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11)))
84-
85-
#define MULT16_32_P15(a,b) ADD32(MULT16_16((a),SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15))
86-
#define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
87-
#define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
81+
#define MULT16_32_P15(a,b) ADD32(MULT16_32_32(a,SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15))
82+
#define MULT16_32_Q15(a,b) ADD32(MULT16_32_32(a,SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
83+
#define MAC16_32_Q15(c,a,b) ADD32(c,MULT16_32_Q15(a,b))
8884

8985

9086
#define MAC16_16_Q11(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),11)))

subprojects/speex/resample.c

Lines changed: 46 additions & 44 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

@@ -91,18 +93,18 @@ static void speex_free (void *ptr) {free(ptr);}
9193
#endif
9294

9395
#ifndef UINT32_MAX
94-
#define UINT32_MAX 4294967296U
96+
#define UINT32_MAX 4294967295U
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

105-
/* Numer of elements to allocate on the stack */
107+
/* Number of elements to allocate on the stack */
106108
#ifdef VAR_ARRAYS
107109
#define FIXED_STACK_ALLOC 8192
108110
#else
@@ -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;
@@ -473,7 +473,7 @@ static int resampler_basic_interpolate_single(SpeexResamplerState *st, spx_uint3
473473
}
474474

475475
cubic_coef(frac, interp);
476-
sum = MULT16_32_Q15(interp[0],SHR32(accum[0], 1)) + MULT16_32_Q15(interp[1],SHR32(accum[1], 1)) + MULT16_32_Q15(interp[2],SHR32(accum[2], 1)) + MULT16_32_Q15(interp[3],SHR32(accum[3], 1));
476+
sum = MULT16_32_Q15(interp[0],accum[0]) + MULT16_32_Q15(interp[1],accum[1]) + MULT16_32_Q15(interp[2],accum[2]) + MULT16_32_Q15(interp[3],accum[3]);
477477
sum = SATURATE32PSHR(sum, 15, 32767);
478478
#else
479479
cubic_coef(frac, interp);
@@ -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
@@ -733,34 +733,37 @@ static int update_filter(SpeexResamplerState *st)
733733
{
734734
spx_uint32_t j;
735735
spx_uint32_t olen = old_length;
736+
spx_uint32_t start = i*st->mem_alloc_size;
737+
spx_uint32_t magic_samples = st->magic_samples[i];
736738
/*if (st->magic_samples[i])*/
737739
{
738740
/* Try and remove the magic samples as if nothing had happened */
739741

740742
/* FIXME: This is wrong but for now we need it to avoid going over the array bounds */
741-
olen = old_length + 2*st->magic_samples[i];
742-
for (j=old_length-1+st->magic_samples[i];j--;)
743-
st->mem[i*st->mem_alloc_size+j+st->magic_samples[i]] = st->mem[i*old_alloc_size+j];
744-
for (j=0;j<st->magic_samples[i];j++)
745-
st->mem[i*st->mem_alloc_size+j] = 0;
743+
olen = old_length + 2*magic_samples;
744+
for (j=old_length-1+magic_samples;j--;)
745+
st->mem[start+j+magic_samples] = st->mem[i*old_alloc_size+j];
746+
for (j=0;j<magic_samples;j++)
747+
st->mem[start+j] = 0;
746748
st->magic_samples[i] = 0;
747749
}
748750
if (st->filt_len > olen)
749751
{
750752
/* If the new filter length is still bigger than the "augmented" length */
751753
/* Copy data going backward */
752754
for (j=0;j<olen-1;j++)
753-
st->mem[i*st->mem_alloc_size+(st->filt_len-2-j)] = st->mem[i*st->mem_alloc_size+(olen-2-j)];
755+
st->mem[start+(st->filt_len-2-j)] = st->mem[start+(olen-2-j)];
754756
/* Then put zeros for lack of anything better */
755757
for (;j<st->filt_len-1;j++)
756-
st->mem[i*st->mem_alloc_size+(st->filt_len-2-j)] = 0;
758+
st->mem[start+(st->filt_len-2-j)] = 0;
757759
/* Adjust last_sample */
758760
st->last_sample[i] += (st->filt_len - olen)/2;
759761
} else {
760762
/* Put back some of the magic! */
761-
st->magic_samples[i] = (olen - st->filt_len)/2;
762-
for (j=0;j<st->filt_len-1+st->magic_samples[i];j++)
763-
st->mem[i*st->mem_alloc_size+j] = st->mem[i*st->mem_alloc_size+j+st->magic_samples[i]];
763+
magic_samples = (olen - st->filt_len)/2;
764+
for (j=0;j<st->filt_len-1+magic_samples;j++)
765+
st->mem[start+j] = st->mem[start+j+magic_samples];
766+
st->magic_samples[i] = magic_samples;
764767
}
765768
}
766769
} else if (st->filt_len < old_length)
@@ -977,8 +980,7 @@ EXPORT int speex_resampler_process_int(SpeexResamplerState *st, spx_uint32_t cha
977980
const spx_uint32_t xlen = st->mem_alloc_size - (st->filt_len - 1);
978981
#ifdef VAR_ARRAYS
979982
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);
983+
spx_word16_t ystack[ylen];
982984
#else
983985
const unsigned int ylen = FIXED_STACK_ALLOC;
984986
spx_word16_t ystack[FIXED_STACK_ALLOC];
@@ -1093,7 +1095,7 @@ EXPORT void speex_resampler_get_rate(SpeexResamplerState *st, spx_uint32_t *in_r
10931095
*out_rate = st->out_rate;
10941096
}
10951097

1096-
static inline spx_uint32_t _gcd(spx_uint32_t a, spx_uint32_t b)
1098+
static inline spx_uint32_t compute_gcd(spx_uint32_t a, spx_uint32_t b)
10971099
{
10981100
while (b != 0)
10991101
{
@@ -1123,7 +1125,7 @@ EXPORT int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t r
11231125
st->num_rate = ratio_num;
11241126
st->den_rate = ratio_den;
11251127

1126-
fact = _gcd (st->num_rate, st->den_rate);
1128+
fact = compute_gcd(st->num_rate, st->den_rate);
11271129

11281130
st->num_rate /= fact;
11291131
st->den_rate /= fact;
@@ -1132,7 +1134,7 @@ EXPORT int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t r
11321134
{
11331135
for (i=0;i<st->nb_channels;i++)
11341136
{
1135-
if (_muldiv(&st->samp_frac_num[i],st->samp_frac_num[i],st->den_rate,old_den) != RESAMPLER_ERR_SUCCESS)
1137+
if (multiply_frac(&st->samp_frac_num[i],st->samp_frac_num[i],st->den_rate,old_den) != RESAMPLER_ERR_SUCCESS)
11361138
return RESAMPLER_ERR_OVERFLOW;
11371139
/* Safety net */
11381140
if (st->samp_frac_num[i] >= st->den_rate)

0 commit comments

Comments
 (0)