From be6df4d61427c04b6609205fab079a1e6a05cb69 Mon Sep 17 00:00:00 2001 From: Tristan Matthews Date: Wed, 1 Apr 2015 12:35:06 -0400 Subject: remove trailing whitespace --- doc/nb_celp.c | 14 +- doc/sampledec.c | 6 +- doc/sampleenc.c | 4 +- libspeex/bits.c | 12 +- libspeex/cb_search.c | 48 +++---- libspeex/exc_10_16_table.c | 10 +- libspeex/exc_10_32_table.c | 10 +- libspeex/exc_20_32_table.c | 10 +- libspeex/exc_5_256_table.c | 10 +- libspeex/exc_5_64_table.c | 10 +- libspeex/exc_8_128_table.c | 10 +- libspeex/fftwrap.c | 18 +-- libspeex/filters.c | 52 ++++---- libspeex/gain_table.c | 6 +- libspeex/gain_table_lbr.c | 6 +- libspeex/hexc_10_32_table.c | 74 +++++------ libspeex/hexc_table.c | 266 +++++++++++++++++++------------------- libspeex/high_lsp_tables.c | 8 +- libspeex/kiss_fft.c | 40 +++--- libspeex/kiss_fftr.c | 38 +++--- libspeex/lpc.c | 30 ++--- libspeex/lsp.c | 32 ++--- libspeex/lsp_tables_nb.c | 6 +- libspeex/ltp.c | 58 ++++----- libspeex/modes.c | 10 +- libspeex/modes_wb.c | 10 +- libspeex/nb_celp.c | 180 +++++++++++++------------- libspeex/quant_lsp.c | 28 ++-- libspeex/sb_celp.c | 118 ++++++++--------- libspeex/smallft.c | 16 +-- libspeex/speex.c | 12 +- libspeex/speex_callbacks.c | 10 +- libspeex/speex_header.c | 24 ++-- libspeex/stereo.c | 40 +++--- libspeex/testenc.c | 2 +- libspeex/testenc_uwb.c | 4 +- libspeex/testenc_wb.c | 4 +- libspeex/vbr.c | 24 ++-- libspeex/vorbis_psy.c | 112 ++++++++-------- libspeex/vq.c | 8 +- libspeex/window.c | 58 ++++----- speexclient/alsa_device.c | 32 ++--- speexclient/speex_jitter_buffer.c | 4 +- speexclient/speexclient.c | 50 +++---- ti/config.h | 12 +- ti/testenc-TI-C5x.c | 32 ++--- ti/testenc-TI-C64x.c | 26 ++-- tmv/config.h | 28 ++-- 48 files changed, 811 insertions(+), 811 deletions(-) diff --git a/doc/nb_celp.c b/doc/nb_celp.c index 90bda10..50d5ffa 100644 --- a/doc/nb_celp.c +++ b/doc/nb_celp.c @@ -86,7 +86,7 @@ int nb_decode(struct speex_decode_state *st, SpeexBits *bits, float *out) mode = speex_bits_unpack_unsigned(bits, 4); if (mode == 15) return -1; - + } while (mode > 8); if (mode != 3) { @@ -108,7 +108,7 @@ int nb_decode(struct speex_decode_state *st, SpeexBits *bits, float *out) for (i=0; iold_qlsp[i] = qlsp[i]; } - + /* Get global excitation gain */ qe = speex_bits_unpack_unsigned(bits, 5); ol_gain = SIG_SCALING*exp(qe/3.5); @@ -130,14 +130,14 @@ int nb_decode(struct speex_decode_state *st, SpeexBits *bits, float *out) NB_SUBFRAME_SIZE, bits, 0); sanitize_values32(exc32, -32000, 32000, NB_SUBFRAME_SIZE); - + /* Unquantize the innovation */ SPEEX_MEMSET(innov, 0, NB_SUBFRAME_SIZE); /* Decode sub-frame gain correction */ q_energy = speex_bits_unpack_unsigned(bits, 1); ener = exc_gain_quant_scal1[q_energy] * ol_gain; - + /* Fixed codebook contribution */ split_cb_shape_sign_unquant(innov, bits); @@ -148,9 +148,9 @@ int nb_decode(struct speex_decode_state *st, SpeexBits *bits, float *out) exc[i] = exc32[i] + innov[i]; } } - + SPEEX_COPY(out, &st->exc[-NB_SUBFRAME_SIZE], NB_FRAME_SIZE); - + /* Loop on subframes */ for (sub=0; sub<4; sub++) { const int offset = NB_SUBFRAME_SIZE*sub; @@ -173,7 +173,7 @@ int nb_decode(struct speex_decode_state *st, SpeexBits *bits, float *out) for (i=0; iinterp_qlpc[i] = ak[i]; } - + /* Store the LSPs for interpolation in the next frame */ for (i=0; iold_qlsp[i] = qlsp[i]; diff --git a/doc/sampledec.c b/doc/sampledec.c index 2878c47..8e89e12 100644 --- a/doc/sampledec.c +++ b/doc/sampledec.c @@ -33,13 +33,13 @@ int main(int argc, char **argv) speex_bits_init(&bits); while (1) { - /*Read the size encoded by sampleenc, this part will likely be + /*Read the size encoded by sampleenc, this part will likely be different in your application*/ fread(&nbBytes, sizeof(int), 1, stdin); fprintf (stderr, "nbBytes: %d\n", nbBytes); if (feof(stdin)) break; - + /*Read the "packet" encoded by sampleenc*/ fread(cbits, 1, nbBytes, stdin); /*Copy the data into the bit-stream struct*/ @@ -55,7 +55,7 @@ int main(int argc, char **argv) /*Write the decoded audio to file*/ fwrite(out, sizeof(short), FRAME_SIZE, fout); } - + /*Destroy the decoder state*/ speex_decoder_destroy(state); /*Destroy the bit-stream truct*/ diff --git a/doc/sampleenc.c b/doc/sampleenc.c index d508181..a0ec8b6 100644 --- a/doc/sampleenc.c +++ b/doc/sampleenc.c @@ -52,9 +52,9 @@ int main(int argc, char **argv) fwrite(&nbBytes, sizeof(int), 1, stdout); /*Write the compressed data*/ fwrite(cbits, 1, nbBytes, stdout); - + } - + /*Destroy the encoder state*/ speex_encoder_destroy(state); /*Destroy the bit-packing struct*/ diff --git a/libspeex/bits.c b/libspeex/bits.c index 94c280a..2d782a2 100644 --- a/libspeex/bits.c +++ b/libspeex/bits.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002 Jean-Marc Valin +/* Copyright (C) 2002 Jean-Marc Valin File: speex_bits.c Handles bit packing/unpacking @@ -6,18 +6,18 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -79,7 +79,7 @@ EXPORT void speex_bits_set_bit_buffer(SpeexBits *bits, void *buff, int buf_size) bits->charPtr=0; bits->bitPtr=0; bits->overflow=0; - + } EXPORT void speex_bits_destroy(SpeexBits *bits) diff --git a/libspeex/cb_search.c b/libspeex/cb_search.c index 26c2329..7f5649e 100644 --- a/libspeex/cb_search.c +++ b/libspeex/cb_search.c @@ -1,21 +1,21 @@ -/* Copyright (C) 2002-2006 Jean-Marc Valin +/* Copyright (C) 2002-2006 Jean-Marc Valin File: cb_search.c Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -60,7 +60,7 @@ static void compute_weighted_codebook(const signed char *shape_cb, const spx_wor for (i=0;isubvect_size; nb_subvect = params->nb_subvect; @@ -148,7 +148,7 @@ int update_target #endif ALLOC(t, nsf, spx_word16_t); ALLOC(e, nsf, spx_sig_t); - + /* FIXME: Do we still need to copy the target? */ SPEEX_COPY(t, target, nsf); @@ -164,9 +164,9 @@ int update_target else #endif /* DISABLE_WIDEBAND */ vq_nbest(x, resp2, subvect_size, shape_cb_size, E, 1, &best_index, &best_dist, stack); - + speex_bits_pack(bits,best_index,params->shape_bits+have_sign); - + { int rind; spx_word16_t *res; @@ -198,9 +198,9 @@ int update_target for (j=0;jshape_bits+have_sign); } - + /* Put everything back together */ for (i=0;iifft); - + for(i=0;i4) filtID=4; - + den = Pcoef[filtID]; num = Zcoef[filtID]; /*return;*/ for (i=0;i>1; N2 = N>>1; ALLOC(xx1, M2+N2, spx_word16_t); @@ -676,11 +676,11 @@ spx_word16_t comb_gain, /*gain of comb filter*/ char *stack ) { - int i; + int i; VARDECL(spx_word16_t *iexc); spx_word16_t old_ener, new_ener; int corr_pitch; - + spx_word16_t iexc0_mag, iexc1_mag, exc_mag; spx_word32_t corr0, corr1; spx_word16_t gain0, gain1; @@ -696,7 +696,7 @@ char *stack int nol_pitch[6]; spx_word16_t nol_pitch_coef[6]; spx_word16_t ol_pitch_coef; - open_loop_nbest_pitch(exc, 20, 120, nsf, + open_loop_nbest_pitch(exc, 20, 120, nsf, nol_pitch, nol_pitch_coef, 6, stack); corr_pitch=nol_pitch[0]; ol_pitch_coef = nol_pitch_coef[0]; @@ -704,11 +704,11 @@ char *stack for (i=1;i<6;i++) { #ifdef FIXED_POINT - if ((nol_pitch_coef[i]>MULT16_16_Q15(nol_pitch_coef[0],19661)) && + if ((nol_pitch_coef[i]>MULT16_16_Q15(nol_pitch_coef[0],19661)) && #else - if ((nol_pitch_coef[i]>.6*nol_pitch_coef[0]) && + if ((nol_pitch_coef[i]>.6*nol_pitch_coef[0]) && #endif - (ABS(2*nol_pitch[i]-corr_pitch)<=2 || ABS(3*nol_pitch[i]-corr_pitch)<=3 || + (ABS(2*nol_pitch[i]-corr_pitch)<=2 || ABS(3*nol_pitch[i]-corr_pitch)<=3 || ABS(4*nol_pitch[i]-corr_pitch)<=4 || ABS(5*nol_pitch[i]-corr_pitch)<=5)) { corr_pitch = nol_pitch[i]; @@ -717,9 +717,9 @@ char *stack #else corr_pitch = pitch; #endif - + ALLOC(iexc, 2*nsf, spx_word16_t); - + interp_pitch(exc, iexc, corr_pitch, 80); if (corr_pitch>max_pitch) interp_pitch(exc, iexc+nsf, 2*corr_pitch, 80); @@ -744,7 +744,7 @@ char *stack } #endif /*interp_pitch(exc, iexc+2*nsf, 2*corr_pitch, 80);*/ - + /*printf ("%d %d %f\n", pitch, corr_pitch, max_corr*ener_1);*/ iexc0_mag = spx_sqrt(1000+inner_prod(iexc,iexc,nsf)); iexc1_mag = spx_sqrt(1000+inner_prod(iexc+nsf,iexc+nsf,nsf)); @@ -781,7 +781,7 @@ char *stack c1 = .4*comb_gain+.07; c2 = .5+1.72*(c1-.07); #endif - } else + } else { c1=c2=0; } @@ -811,7 +811,7 @@ char *stack /* FIXME: compute_rms16 is currently not quite accurate enough (but close) */ new_ener = compute_rms16(new_exc, nsf); old_ener = compute_rms16(exc, nsf); - + if (old_ener < 1) old_ener = 1; if (new_ener < 1) @@ -819,7 +819,7 @@ char *stack if (old_ener > new_ener) old_ener = new_ener; ngain = PDIV32_16(SHL32(EXTEND32(old_ener),14),new_ener); - + for (i=0;ir = PSHR16(Fout->r, 2); Fout->i = PSHR16(Fout->i, 2); C_SUB( scratch[5] , *Fout, scratch[1] ); @@ -154,7 +154,7 @@ static void kf_bfly4( tw2 += fstride*2; tw3 += fstride*3; C_ADDTO( *Fout , scratch[3] ); - + Fout[m].r = scratch[5].r + scratch[4].i; Fout[m].i = scratch[5].i - scratch[4].r; Fout[m3].r = scratch[5].r - scratch[4].i; @@ -292,7 +292,7 @@ static void kf_bfly_generic( /*CHECKBUF(scratchbuf,nscratchbuf,p);*/ if (p>17) speex_fatal("KissFFT: max radix supported is 17"); - + for ( u=0; unfft); diff --git a/libspeex/kiss_fftr.c b/libspeex/kiss_fftr.c index f6275b8..827e0b1 100644 --- a/libspeex/kiss_fftr.c +++ b/libspeex/kiss_fftr.c @@ -24,9 +24,9 @@ struct kiss_fftr_state{ kiss_fft_cfg substate; kiss_fft_cpx * tmpbuf; kiss_fft_cpx * super_twiddles; -#ifdef USE_SIMD +#ifdef USE_SIMD long pad; -#endif +#endif }; kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem) @@ -96,12 +96,12 @@ void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *fr * contains the sum of the even-numbered elements of the input time sequence * The imag part is the sum of the odd-numbered elements * - * The sum of tdc.r and tdc.i is the sum of the input time sequence. + * The sum of tdc.r and tdc.i is the sum of the input time sequence. * yielding DC of input time sequence - * The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1... + * The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1... * yielding Nyquist bin of input time sequence */ - + tdc.r = st->tmpbuf[0].r; tdc.i = st->tmpbuf[0].i; C_FIXDIV(tdc,2); @@ -109,14 +109,14 @@ void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *fr CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i); freqdata[0].r = tdc.r + tdc.i; freqdata[ncfft].r = tdc.r - tdc.i; -#ifdef USE_SIMD +#ifdef USE_SIMD freqdata[ncfft].i = freqdata[0].i = _mm_set1_ps(0); #else freqdata[ncfft].i = freqdata[0].i = 0; #endif for ( k=1;k <= ncfft/2 ; ++k ) { - fpk = st->tmpbuf[k]; + fpk = st->tmpbuf[k]; fpnk.r = st->tmpbuf[ncfft-k].r; fpnk.i = - st->tmpbuf[ncfft-k].i; C_FIXDIV(fpk,2); @@ -161,7 +161,7 @@ void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx *freqdata, kiss_fft_scalar * C_MUL (fok, tmp, st->super_twiddles[k]); C_ADD (st->tmpbuf[k], fek, fok); C_SUB (st->tmpbuf[ncfft - k], fek, fok); -#ifdef USE_SIMD +#ifdef USE_SIMD st->tmpbuf[ncfft - k].i *= _mm_set1_ps(-1.0); #else st->tmpbuf[ncfft - k].i *= -1; @@ -189,12 +189,12 @@ void kiss_fftr2(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_scalar * contains the sum of the even-numbered elements of the input time sequence * The imag part is the sum of the odd-numbered elements * - * The sum of tdc.r and tdc.i is the sum of the input time sequence. + * The sum of tdc.r and tdc.i is the sum of the input time sequence. * yielding DC of input time sequence - * The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1... + * The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1... * yielding Nyquist bin of input time sequence */ - + tdc.r = st->tmpbuf[0].r; tdc.i = st->tmpbuf[0].i; C_FIXDIV(tdc,2); @@ -205,7 +205,7 @@ void kiss_fftr2(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_scalar for ( k=1;k <= ncfft/2 ; ++k ) { - /*fpk = st->tmpbuf[k]; + /*fpk = st->tmpbuf[k]; fpnk.r = st->tmpbuf[ncfft-k].r; fpnk.i = - st->tmpbuf[ncfft-k].i; C_FIXDIV(fpk,2); @@ -213,7 +213,7 @@ void kiss_fftr2(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_scalar C_ADD( f1k, fpk , fpnk ); C_SUB( f2k, fpk , fpnk ); - + C_MUL( tw , f2k , st->super_twiddles[k]); freqdata[2*k-1] = HALF_OF(f1k.r + tw.r); @@ -226,7 +226,7 @@ void kiss_fftr2(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_scalar f1k.i = PSHR32(SUB32(EXTEND32(st->tmpbuf[k].i), EXTEND32(st->tmpbuf[ncfft-k].i)),1); f2k.r = PSHR32(SUB32(EXTEND32(st->tmpbuf[k].r), EXTEND32(st->tmpbuf[ncfft-k].r)),1); f2k.i = SHR32(ADD32(EXTEND32(st->tmpbuf[k].i), EXTEND32(st->tmpbuf[ncfft-k].i)),1); - + C_MUL( tw , f2k , st->super_twiddles[k]); freqdata[2*k-1] = HALF_OF(f1k.r + tw.r); @@ -236,13 +236,13 @@ void kiss_fftr2(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_scalar */ f2k.r = SHR32(SUB32(EXTEND32(st->tmpbuf[k].r), EXTEND32(st->tmpbuf[ncfft-k].r)),1); f2k.i = PSHR32(ADD32(EXTEND32(st->tmpbuf[k].i), EXTEND32(st->tmpbuf[ncfft-k].i)),1); - + f1kr = SHL32(ADD32(EXTEND32(st->tmpbuf[k].r), EXTEND32(st->tmpbuf[ncfft-k].r)),13); f1ki = SHL32(SUB32(EXTEND32(st->tmpbuf[k].i), EXTEND32(st->tmpbuf[ncfft-k].i)),13); - + twr = SHR32(SUB32(MULT16_16(f2k.r,st->super_twiddles[k].r),MULT16_16(f2k.i,st->super_twiddles[k].i)), 1); twi = SHR32(ADD32(MULT16_16(f2k.i,st->super_twiddles[k].r),MULT16_16(f2k.r,st->super_twiddles[k].i)), 1); - + #ifdef FIXED_POINT freqdata[2*k-1] = PSHR32(f1kr + twr, 15); freqdata[2*k] = PSHR32(f1ki + twi, 15); @@ -253,7 +253,7 @@ void kiss_fftr2(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_scalar freqdata[2*k] = .5f*(f1ki + twi); freqdata[2*(ncfft-k)-1] = .5f*(f1kr - twr); freqdata[2*(ncfft-k)] = .5f*(twi - f1ki); - + #endif } } @@ -287,7 +287,7 @@ void kiss_fftri2(kiss_fftr_cfg st,const kiss_fft_scalar *freqdata,kiss_fft_scala C_MUL (fok, tmp, st->super_twiddles[k]); C_ADD (st->tmpbuf[k], fek, fok); C_SUB (st->tmpbuf[ncfft - k], fek, fok); -#ifdef USE_SIMD +#ifdef USE_SIMD st->tmpbuf[ncfft - k].i *= _mm_set1_ps(-1.0); #else st->tmpbuf[ncfft - k].i *= -1; diff --git a/libspeex/lpc.c b/libspeex/lpc.c index 141fd9d..fca4d9e 100644 --- a/libspeex/lpc.c +++ b/libspeex/lpc.c @@ -24,18 +24,18 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -78,7 +78,7 @@ const spx_word16_t *ac, /* in: [0...p] autocorrelation values */ int p ) { - int i, j; + int i, j; spx_word16_t r; spx_word16_t error = ac[0]; @@ -86,7 +86,7 @@ int p /* Sum up this iteration's reflection coefficient */ spx_word32_t rr = NEG32(SHL32(EXTEND32(ac[i + 1]),13)); - for (j = 0; j < i; j++) + for (j = 0; j < i; j++) rr = SUB32(rr,MULT16_16(lpc[j],ac[i - j])); #ifdef FIXED_POINT r = DIV32_16(rr+PSHR32(error,1),ADD16(error,8)); @@ -95,7 +95,7 @@ int p #endif /* Update LPC coefficients and total error */ lpc[i] = r; - for (j = 0; j < (i+1)>>1; j++) + for (j = 0; j < (i+1)>>1; j++) { spx_word16_t tmp1, tmp2; /* It could be that j == i-1-j, in which case, we're updating the same value twice, which is OK */ @@ -124,7 +124,7 @@ int p void _spx_autocorr( const spx_word16_t *x, /* in: [0...n-1] samples x */ spx_word16_t *ac, /* out: [0...lag-1] ac values */ -int lag, +int lag, int n ) { @@ -132,7 +132,7 @@ int n int i, j; spx_word32_t ac0=1; int shift, ac_shift; - + for (j=0;j>1; - /* - + /* + Reconstruct P(z) and Q(z) by cascading second order polynomials in form 1 - 2cos(w)z(-1) + z(-2), where w is the LSP frequency. In the time domain this is: y(n) = x(n) - 2cos(w)x(n-1) + x(n-2) - + This is what the ALLOCS below are trying to do: int xp[m+1][lpcrdr+1+2]; // P matrix in QIMP @@ -446,7 +446,7 @@ void lsp_to_lpc(const spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack) ALLOC(xq, (m+1), spx_word32_t*); ALLOC(xqmem, (m+1)*(lpcrdr+1+2), spx_word32_t); - + for(i=0; i<=m; i++) { xp[i] = xpmem + i*(lpcrdr+1+2); xq[i] = xqmem + i*(lpcrdr+1+2); @@ -455,15 +455,15 @@ void lsp_to_lpc(const spx_lsp_t *freq,spx_coef_t *ak,int lpcrdr, char *stack) /* work out 2cos terms in Q14 */ ALLOC(freqn, lpcrdr, spx_word16_t); - for (i=0;i 32767) a = 32767; ak[j-1] = (short)a; - + } } diff --git a/libspeex/lsp_tables_nb.c b/libspeex/lsp_tables_nb.c index 16f2e1b..8015b9a 100644 --- a/libspeex/lsp_tables_nb.c +++ b/libspeex/lsp_tables_nb.c @@ -1,13 +1,13 @@ -/* Copyright (C) 2002 Jean-Marc Valin +/* Copyright (C) 2002 Jean-Marc Valin File: lsp_tables_nb.c Codebooks for LSPs in narrowband CELP mode - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the diff --git a/libspeex/ltp.c b/libspeex/ltp.c index e9e6c5a..347a9db 100644 --- a/libspeex/ltp.c +++ b/libspeex/ltp.c @@ -1,22 +1,22 @@ -/* Copyright (C) 2002-2006 Jean-Marc Valin +/* Copyright (C) 2002-2006 Jean-Marc Valin File: ltp.c Long-Term Prediction functions Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -126,7 +126,7 @@ static void pitch_xcorr(const spx_word16_t *_x, const spx_word16_t *_y, spx_word part4 = MAC16_16(part4,*x,y2); x++; y3=*y++; - + sum1 = ADD32(sum1,SHR32(part1,6)); sum2 = ADD32(sum2,SHR32(part2,6)); sum3 = ADD32(sum3,SHR32(part3,6)); @@ -179,7 +179,7 @@ void open_loop_nbest_pitch(spx_word16_t *sw, int start, int end, int len, int *p spx_word32_t e0; VARDECL(spx_word32_t *corr); #ifdef FIXED_POINT - /* In fixed-point, we need only one (temporary) array of 32-bit values and two (corr16, ener16) + /* In fixed-point, we need only one (temporary) array of 32-bit values and two (corr16, ener16) arrays for (normalized) 16-bit values */ VARDECL(spx_word16_t *corr16); VARDECL(spx_word16_t *ener16); @@ -200,7 +200,7 @@ void open_loop_nbest_pitch(spx_word16_t *sw, int start, int end, int len, int *p corr16 = corr; ener16 = energy; #endif - + ALLOC(best_score, N, spx_word32_t); ALLOC(best_ener, N, spx_word32_t); for (i=0;ibest_sum && gain_sum<=max_gain) { best_sum=sum; best_cdbk=i; @@ -384,11 +384,11 @@ int scaledown if (cumul_gain > 262144) max_gain = 31; - + x[0]=tmp1; x[1]=tmp1+nsf; x[2]=tmp1+2*nsf; - + for (j=0;jgain_bits; gain_cdbk = params->gain_cdbk + 4*gain_cdbk_size*cdbk_offset; - + N=complexity; if (N>10) N=10; @@ -588,7 +588,7 @@ spx_word32_t *cumul_gain SPEEX_MEMSET(exc, 0, nsf); return start; } - + #ifdef FIXED_POINT /* Check if we need to scale everything down in the pitch search to avoid overflows */ for (i=0;istack = (char*)speex_alloc_scratch(NB_ENC_STACK); #endif - + st->mode=m; st->gamma1=mode->gamma1; st->gamma2=mode->gamma2; st->lpc_floor = mode->lpc_floor; - + st->submodes=mode->submodes; st->submodeID=st->submodeSelect=mode->defaultSubmode; st->bounded_pitch = 1; @@ -142,7 +142,7 @@ void *nb_encoder_init(const SpeexMode *m) st->cumul_gain = 1024; st->window= lpc_window; - + /* Create the window for autocorrelation (lag-windowing) */ st->lagWindow = lag_window; @@ -151,7 +151,7 @@ void *nb_encoder_init(const SpeexMode *m) st->old_lsp[i]= DIV32(MULT16_16(QCONST16(3.1415927f, LSP_SHIFT), i+1), NB_ORDER+1); st->innov_rms_save = NULL; - + #ifndef DISABLE_VBR vbr_init(&st->vbr); st->vbr_quality = 8; @@ -170,7 +170,7 @@ void *nb_encoder_init(const SpeexMode *m) st->sampling_rate=8000; st->isWideband = 0; st->highpass_enabled = 1; - + #ifdef ENABLE_VALGRIND VALGRIND_MAKE_READABLE(st, NB_ENC_STACK); #endif @@ -204,7 +204,7 @@ void nb_encoder_destroy(void *state) int nb_encoder_ctl(void *state, int request, void *ptr) { EncState *st; - st=(EncState*)state; + st=(EncState*)state; switch(request) { case SPEEX_GET_FRAME_SIZE: @@ -240,7 +240,7 @@ int nb_encoder_ctl(void *state, int request, void *ptr) case SPEEX_SET_ABR: st->abr_enabled = (*(spx_int32_t*)ptr); st->vbr_enabled = st->abr_enabled!=0; - if (st->vbr_enabled) + if (st->vbr_enabled) { spx_int32_t i=10; spx_int32_t rate, target; @@ -262,7 +262,7 @@ int nb_encoder_ctl(void *state, int request, void *ptr) st->abr_drift=0; st->abr_drift2=0; } - + break; case SPEEX_GET_ABR: (*(spx_int32_t*)ptr) = st->abr_enabled; @@ -428,7 +428,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) VARDECL(spx_coef_t *interp_qlpc); char *stack; VARDECL(spx_word16_t *syn_resp); - + spx_word32_t ener=0; spx_word16_t fine_gain; spx_word16_t *in = (spx_word16_t*)vin; @@ -454,7 +454,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) if (st->highpass_enabled) highpass(in, in, NB_FRAME_SIZE, (st->isWideband?HIGHPASS_WIDEBAND:HIGHPASS_NARROWBAND)|HIGHPASS_INPUT, st->mem_hp); - + { VARDECL(spx_word16_t *w_sig); VARDECL(spx_word16_t *autocorr); @@ -506,7 +506,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) /*Open-loop pitch*/ - if (!st->submodes[st->submodeID] || (st->complexity>2 && SUBMODE(have_subframe_gain)<3) || SUBMODE(forced_pitch_gain) || SUBMODE(lbr_pitch) != -1 + if (!st->submodes[st->submodeID] || (st->complexity>2 && SUBMODE(have_subframe_gain)<3) || SUBMODE(forced_pitch_gain) || SUBMODE(lbr_pitch) != -1 #ifndef DISABLE_VBR || st->vbr_enabled || st->vad_enabled #endif @@ -514,7 +514,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) { int nol_pitch[6]; spx_word16_t nol_pitch_coef[6]; - + bw_lpc(0.9, interp_lpc, bw_lpc1, NB_ORDER); bw_lpc(0.55, interp_lpc, bw_lpc2, NB_ORDER); @@ -522,7 +522,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) SPEEX_COPY(st->sw+diff, in, NB_FRAME_SIZE-diff); filter10(st->sw, bw_lpc1, bw_lpc2, st->sw, NB_FRAME_SIZE, st->mem_sw_whole, stack); - open_loop_nbest_pitch(st->sw, NB_PITCH_START, NB_PITCH_END, NB_FRAME_SIZE, + open_loop_nbest_pitch(st->sw, NB_PITCH_START, NB_PITCH_END, NB_FRAME_SIZE, nol_pitch, nol_pitch_coef, 6, stack); ol_pitch=nol_pitch[0]; ol_pitch_coef = nol_pitch_coef[0]; @@ -530,11 +530,11 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) for (i=1;i<6;i++) { #ifdef FIXED_POINT - if ((nol_pitch_coef[i]>MULT16_16_Q15(nol_pitch_coef[0],27853)) && + if ((nol_pitch_coef[i]>MULT16_16_Q15(nol_pitch_coef[0],27853)) && #else - if ((nol_pitch_coef[i]>.85*nol_pitch_coef[0]) && + if ((nol_pitch_coef[i]>.85*nol_pitch_coef[0]) && #endif - (ABS(2*nol_pitch[i]-ol_pitch)<=2 || ABS(3*nol_pitch[i]-ol_pitch)<=3 || + (ABS(2*nol_pitch[i]-ol_pitch)<=2 || ABS(3*nol_pitch[i]-ol_pitch)<=3 || ABS(4*nol_pitch[i]-ol_pitch)<=4 || ABS(5*nol_pitch[i]-ol_pitch)<=5)) { /*ol_pitch_coef=nol_pitch_coef[i];*/ @@ -549,7 +549,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) ol_pitch=0; ol_pitch_coef=0; } - + /*Compute "real" excitation*/ /*SPEEX_COPY(st->exc, st->winBuf, diff); SPEEX_COPY(st->exc+diff, in, NB_FRAME_SIZE-diff);*/ @@ -584,7 +584,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) for (i=0;iold_lsp[i] - lsp[i])*(st->old_lsp[i] - lsp[i]); lsp_dist /= LSP_SCALING*LSP_SCALING; - + if (st->abr_enabled) { float qual_change=0; @@ -607,7 +607,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) st->relative_quality = vbr_analysis(&st->vbr, in, NB_FRAME_SIZE, ol_pitch, GAIN_SCALING_1*ol_pitch_coef); /*if (delta_qual<0)*/ /* delta_qual*=.1*(3+st->vbr_quality);*/ - if (st->vbr_enabled) + if (st->vbr_enabled) { spx_int32_t mode; int choice=0; @@ -622,7 +622,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) thresh = vbr_nb_thresh[mode][v1]; else thresh = (st->vbr_quality-v1)*vbr_nb_thresh[mode][v1+1] + (1+v1-st->vbr_quality)*vbr_nb_thresh[mode][v1]; - if (st->relative_quality > thresh && + if (st->relative_quality > thresh && st->relative_quality-threshabr_enabled) { spx_int32_t bitrate; @@ -685,7 +685,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) } /*speex_encoder_ctl(state, SPEEX_SET_MODE, &mode);*/ st->submodeID=mode; - } + } } else { st->relative_quality = -1; } @@ -741,7 +741,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) if (SUBMODE(lbr_pitch)!=-1) { speex_bits_pack(bits, ol_pitch-NB_PITCH_START, 7); - } + } if (SUBMODE(forced_pitch_gain)) { @@ -760,8 +760,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) speex_bits_pack(bits, quant, 4); ol_pitch_coef=MULT16_16_P15(QCONST16(0.066667,15),SHL16(quant,GAIN_SHIFT)); } - - + + /*Quantize and transmit open-loop excitation gain*/ #ifdef FIXED_POINT { @@ -813,7 +813,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) exc=st->exc+offset; /* Weighted signal */ sw=st->sw+offset; - + /* LSP interpolation (quantized and unquantized) */ lsp_interpolate(st->old_lsp, lsp, interp_lsp, NB_ORDER, sub, NB_NB_SUBFRAMES, LSP_MARGIN); lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, NB_ORDER, sub, NB_NB_SUBFRAMES, LSP_MARGIN); @@ -857,13 +857,13 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) inBuf = &in[((sub-1)*NB_SUBFRAME_SIZE)]; for (i=0;icomplexity==0) response_bound >>= 1; compute_impulse_response(interp_qlpc, bw_lpc1, bw_lpc2, syn_resp, response_bound, NB_ORDER, stack); for (i=response_bound;imem_sp[i],1); @@ -881,16 +881,16 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) mem[i]=SHL32(st->mem_sw[i],1); filter10(exc, bw_lpc1, bw_lpc2, exc, NB_SUBFRAME_SIZE, mem, stack); #endif - + /* Compute weighted signal */ for (i=0;imem_sw[i]; filter10(sw, bw_lpc1, bw_lpc2, sw, NB_SUBFRAME_SIZE, mem, stack); - + if (st->complexity==0) for (i=0;imem_sw[i]=mem[i]; - + /* Compute target signal (saturation prevents overflows on clipped input speech) */ for (i=0;ibounded_pitch && pit_max>offset) pit_max=offset; @@ -931,20 +931,20 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) /* Perform pitch search */ pitch = SUBMODE(ltp_quant)(target, sw, interp_qlpc, bw_lpc1, bw_lpc2, exc32, SUBMODE(ltp_params), pit_min, pit_max, ol_pitch_coef, - NB_ORDER, NB_SUBFRAME_SIZE, bits, stack, + NB_ORDER, NB_SUBFRAME_SIZE, bits, stack, exc, syn_resp, st->complexity, 0, st->plc_tuning, &st->cumul_gain); st->pitch[sub]=pitch; } /* Quantization of innovation */ SPEEX_MEMSET(innov, 0, NB_SUBFRAME_SIZE); - + /* FIXME: Make sure this is safe from overflows (so far so good) */ for (i=0;icomplexity, SUBMODE(double_codebook)); - + /* De-normalize innovation and update excitation */ signal_mul(innov, innov, ener, NB_SUBFRAME_SIZE); - + /* In some (rare) modes, we do a second search (more bits) to reduce noise even more */ if (SUBMODE(double_codebook)) { char *tmp_stack=stack; @@ -999,8 +999,8 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) SPEEX_MEMSET(innov2, 0, NB_SUBFRAME_SIZE); for (i=0;icomplexity, 0); signal_mul(innov2, innov2, MULT16_32_Q15(QCONST16(0.454545f,15),ener), NB_SUBFRAME_SIZE); for (i=0;icomplexity!=0) filter10(sw, bw_lpc1, bw_lpc2, sw, NB_SUBFRAME_SIZE, st->mem_sw, stack); - + } /* Store the LSPs for interpolation in the next frame */ @@ -1097,7 +1097,7 @@ void *nb_decoder_init(const SpeexMode *m) st->pitch_gain_buf[0] = st->pitch_gain_buf[1] = st->pitch_gain_buf[2] = 0; st->pitch_gain_buf_idx = 0; st->seed = 1000; - + st->sampling_rate=8000; st->last_ol_gain = 0; @@ -1122,7 +1122,7 @@ void nb_decoder_destroy(void *state) { DecState *st; st=(DecState*)state; - + #if !(defined(VAR_ARRAYS) || defined (USE_ALLOCA)) speex_free_scratch(st->stack); #endif @@ -1285,13 +1285,13 @@ static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack) gain_med = median3(st->pitch_gain_buf[0], st->pitch_gain_buf[1], st->pitch_gain_buf[2]); if (gain_med < st->last_pitch_gain) st->last_pitch_gain = gain_med; - + #ifdef FIXED_POINT pitch_gain = st->last_pitch_gain; if (pitch_gain>54) pitch_gain = 54; pitch_gain = SHL16(pitch_gain, 9); -#else +#else pitch_gain = GAIN_SCALING_1*st->last_pitch_gain; if (pitch_gain>.85) pitch_gain=.85; @@ -1302,7 +1302,7 @@ static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack) noise_gain = MULT16_16_Q15(innov_gain, MULT16_16_Q15(fact, SUB16(Q15ONE,MULT16_16_Q15(pitch_gain,pitch_gain)))); /* Shift all buffers by one frame */ SPEEX_MOVE(st->excBuf, st->excBuf+NB_FRAME_SIZE, 2*NB_PITCH_END + NB_SUBFRAME_SIZE + 12); - + pitch_val = st->last_pitch + SHR32((spx_int32_t)speex_rand(1+st->count_lost, &st->seed),SIG_SHIFT); if (pitch_val > NB_PITCH_END) @@ -1311,7 +1311,7 @@ static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack) pitch_val = NB_PITCH_START; for (i=0;iexc[i]= MULT16_16_Q15(pitch_gain, (st->exc[i-pitch_val]+VERY_SMALL)) + + st->exc[i]= MULT16_16_Q15(pitch_gain, (st->exc[i-pitch_val]+VERY_SMALL)) + speex_rand(noise_gain, &st->seed); } @@ -1319,7 +1319,7 @@ static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack) iir_mem16(&st->exc[-NB_SUBFRAME_SIZE], st->interp_qlpc, out, NB_FRAME_SIZE, NB_ORDER, st->mem_sp, stack); highpass(out, out, NB_FRAME_SIZE, HIGHPASS_NARROWBAND|HIGHPASS_OUTPUT, st->mem_hp); - + st->first = 0; st->count_lost++; st->pitch_gain_buf[st->pitch_gain_buf_idx++] = PSHR16(pitch_gain,9); @@ -1329,7 +1329,7 @@ static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack) /* Just so we don't need to carry the complete wideband mode information */ static const int wb_skip_table[8] = {0, 36, 112, 192, 352, 0, 0, 0}; - + int nb_decode(void *state, SpeexBits *bits, void *vout) { DecState *st; @@ -1349,7 +1349,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) VARDECL(spx_coef_t *ak); VARDECL(spx_lsp_t *qlsp); spx_word16_t pitch_average=0; - + spx_word16_t *out = (spx_word16_t*)vout; VARDECL(spx_lsp_t *interp_qlsp); @@ -1362,7 +1362,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) if (!bits && st->dtx_enabled) { st->submodeID=0; - } else + } else { /* If bits is NULL, consider the packet to be lost (what could we do anyway) */ if (!bits) @@ -1390,10 +1390,10 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) { speex_notify("Invalid mode encountered. The stream is corrupted."); return -2; - } + } advance -= (SB_SUBMODE_BITS+1); speex_bits_advance(bits, advance); - + if (speex_bits_remaining(bits)<5) return -1; wideband = speex_bits_unpack_unsigned(bits, 1); @@ -1406,7 +1406,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) { speex_notify("Invalid mode encountered. The stream is corrupted."); return -2; - } + } advance -= (SB_SUBMODE_BITS+1); speex_bits_advance(bits, advance); wideband = speex_bits_unpack_unsigned(bits, 1); @@ -1440,7 +1440,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) speex_notify("Invalid mode encountered. The stream is corrupted."); return -2; } - + } while (m>8); /* Get the sub-mode that was used */ @@ -1489,7 +1489,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) for (i=0;iold_qlsp[i] - qlsp[i]))); #ifdef FIXED_POINT - fact = SHR16(19661,SHR32(lsp_dist,LSP_SHIFT+2)); + fact = SHR16(19661,SHR32(lsp_dist,LSP_SHIFT+2)); #else fact = .6*exp(-.2*lsp_dist); #endif @@ -1509,15 +1509,15 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) if (SUBMODE(lbr_pitch)!=-1) { ol_pitch = NB_PITCH_START+speex_bits_unpack_unsigned(bits, 7); - } - + } + if (SUBMODE(forced_pitch_gain)) { int quant; quant = speex_bits_unpack_unsigned(bits, 4); ol_pitch_coef=MULT16_16_P15(QCONST16(0.066667,15),SHL16(quant,GAIN_SHIFT)); } - + /* Get global excitation gain */ { int qe; @@ -1604,20 +1604,20 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) - SUBMODE(ltp_unquant)(exc, exc32, pit_min, pit_max, ol_pitch_coef, SUBMODE(ltp_params), - NB_SUBFRAME_SIZE, &pitch, &pitch_gain[0], bits, stack, + SUBMODE(ltp_unquant)(exc, exc32, pit_min, pit_max, ol_pitch_coef, SUBMODE(ltp_params), + NB_SUBFRAME_SIZE, &pitch, &pitch_gain[0], bits, stack, st->count_lost, offset, st->last_pitch_gain, 0); - /* Ensuring that things aren't blowing up as would happen if e.g. an encoder is + /* Ensuring that things aren't blowing up as would happen if e.g. an encoder is crafting packets to make us produce NaNs and slow down the decoder (vague DoS threat). We can probably be even more aggressive and limit to 15000 or so. */ sanitize_values32(exc32, NEG32(QCONST32(32000,SIG_SHIFT-1)), QCONST32(32000,SIG_SHIFT-1), NB_SUBFRAME_SIZE); - + tmp = gain_3tap_to_1tap(pitch_gain); pitch_average += tmp; - if ((tmp>best_pitch_gain&&ABS(2*best_pitch-pitch)>=3&&ABS(3*best_pitch-pitch)>=4&&ABS(4*best_pitch-pitch)>=5) - || (tmp>MULT16_16_Q15(QCONST16(.6,15),best_pitch_gain)&&(ABS(best_pitch-2*pitch)<3||ABS(best_pitch-3*pitch)<4||ABS(best_pitch-4*pitch)<5)) + if ((tmp>best_pitch_gain&&ABS(2*best_pitch-pitch)>=3&&ABS(3*best_pitch-pitch)>=4&&ABS(4*best_pitch-pitch)>=5) + || (tmp>MULT16_16_Q15(QCONST16(.6,15),best_pitch_gain)&&(ABS(best_pitch-2*pitch)<3||ABS(best_pitch-3*pitch)<4||ABS(best_pitch-4*pitch)<5)) || (MULT16_16_Q15(QCONST16(.67,15),tmp)>best_pitch_gain&&(ABS(2*best_pitch-pitch)<3||ABS(3*best_pitch-pitch)<4||ABS(4*best_pitch-pitch)<5)) ) { best_pitch = pitch; @@ -1625,12 +1625,12 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) best_pitch_gain = tmp; } } - + /* Unquantize the innovation */ { int q_energy; spx_word32_t ener; - + SPEEX_MEMSET(innov, 0, NB_SUBFRAME_SIZE); /* Decode sub-frame gain correction */ @@ -1645,7 +1645,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) } else { ener = ol_gain; } - + speex_assert (SUBMODE(innovation_unquant)); { /*Fixed codebook contribution*/ @@ -1678,7 +1678,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) } /*Vocoder mode*/ - if (st->submodeID==1) + if (st->submodeID==1) { spx_word16_t g=ol_pitch_coef; g=MULT16_16_P14(QCONST16(1.5f,14),(g-QCONST16(.2f,6))); @@ -1686,7 +1686,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) g=0; if (g>GAIN_SCALING) g=GAIN_SCALING; - + SPEEX_MEMSET(exc, 0, NB_SUBFRAME_SIZE); while (st->voc_offsetvoc_offset+=ol_pitch; } st->voc_offset -= NB_SUBFRAME_SIZE; - + for (i=0;ilpc_enh_enabled && SUBMODE(comb_gain)>0 && !st->count_lost) @@ -1724,9 +1724,9 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) } else { SPEEX_COPY(out, &st->exc[-NB_SUBFRAME_SIZE], NB_FRAME_SIZE); } - + /* If the last packet was lost, re-scale the excitation to obtain the same energy as encoded in ol_gain */ - if (st->count_lost) + if (st->count_lost) { spx_word16_t exc_ener; spx_word32_t gain32; @@ -1778,10 +1778,10 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) } st->pi_gain[sub] = pi_g; } - - iir_mem16(sp, st->interp_qlpc, sp, NB_SUBFRAME_SIZE, NB_ORDER, + + iir_mem16(sp, st->interp_qlpc, sp, NB_SUBFRAME_SIZE, NB_ORDER, st->mem_sp, stack); - + for (i=0;iinterp_qlpc[i] = ak[i]; @@ -1799,7 +1799,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) if (st->max_level < st->min_level+1) st->max_level = st->min_level+1; /*printf ("%f %f %f %d\n", og, st->min_level, st->max_level, update);*/ - + /* Store the LSPs for interpolation in the next frame */ for (i=0;iold_qlsp[i] = qlsp[i]; @@ -1811,7 +1811,7 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) #ifdef FIXED_POINT st->last_pitch_gain = PSHR16(pitch_average,2); #else - st->last_pitch_gain = .25*pitch_average; + st->last_pitch_gain = .25*pitch_average; #endif st->pitch_gain_buf[st->pitch_gain_buf_idx++] = st->last_pitch_gain; if (st->pitch_gain_buf_idx > 2) /* rollover */ diff --git a/libspeex/quant_lsp.c b/libspeex/quant_lsp.c index 699716b..0d023ec 100644 --- a/libspeex/quant_lsp.c +++ b/libspeex/quant_lsp.c @@ -1,22 +1,22 @@ -/* Copyright (C) 2002 Jean-Marc Valin +/* Copyright (C) 2002 Jean-Marc Valin File: quant_lsp.c LSP vector quantization Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -111,7 +111,7 @@ static int lsp_quant(spx_word16_t *x, const signed char *cdbk, int nbVec, int nb { tmp=SUB16(x[j],SHL16((spx_word16_t)*ptr++,5)); dist=MAC16_16(dist,tmp,tmp); - } + } if (distencode_submode = 1; st->submodes=mode->submodes; st->submodeSelect = st->submodeID=mode->defaultSubmode; - + tmp=9; speex_encoder_ctl(st->st_low, SPEEX_SET_QUALITY, &tmp); tmp=1; @@ -201,7 +201,7 @@ void *sb_encoder_init(const SpeexMode *m) st->pi_gain = (spx_word32_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word32_t)); st->exc_rms = (spx_word16_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word16_t)); st->innov_rms_save = NULL; - + st->mem_sp = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); st->mem_sp2 = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); st->mem_sw = (spx_mem_t*)speex_alloc((st->lpcSize)*sizeof(spx_mem_t)); @@ -251,7 +251,7 @@ void sb_encoder_destroy(void *state) speex_free(st->mem_sp2); speex_free(st->mem_sw); - + speex_free(st); } @@ -322,7 +322,7 @@ int sb_encoder_ctl(void *state, int request, void *ptr) st->abr_enabled = (*(spx_int32_t*)ptr); st->vbr_enabled = st->abr_enabled!=0; speex_encoder_ctl(st->st_low, SPEEX_SET_VBR, &st->vbr_enabled); - if (st->vbr_enabled) + if (st->vbr_enabled) { spx_int32_t i=10, rate, target; float vbr_qual; @@ -343,7 +343,7 @@ int sb_encoder_ctl(void *state, int request, void *ptr) st->abr_drift=0; st->abr_drift2=0; } - + break; case SPEEX_GET_ABR: (*(spx_int32_t*)ptr) = st->abr_enabled; @@ -541,17 +541,17 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) VARDECL(spx_lsp_t *qlsp); VARDECL(spx_lsp_t *interp_lsp); VARDECL(spx_lsp_t *interp_qlsp); - + st = (SBEncState*)state; stack=st->stack; mode = (const SpeexSBMode*)(st->mode->mode); low = in; high = in+st->frame_size; - + /* High-band buffering / sync with low band */ /* Compute the two sub-bands by filtering with QMF h0*/ qmf_decomp(in, h0, low, high, st->full_frame_size, QMF_ORDER, st->h0_mem, stack); - + #ifndef DISABLE_VBR if (st->vbr_enabled || st->vad_enabled) { @@ -570,13 +570,13 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) high = high - (st->windowSize-st->frame_size); SPEEX_COPY(high, st->high, st->windowSize-st->frame_size); SPEEX_COPY(st->high, &high[st->frame_size], st->windowSize-st->frame_size); - + ALLOC(low_pi_gain, st->nbSubframes, spx_word32_t); ALLOC(low_exc_rms, st->nbSubframes, spx_word16_t); speex_encoder_ctl(st->st_low, SPEEX_GET_PI_GAIN, low_pi_gain); speex_encoder_ctl(st->st_low, SPEEX_GET_EXC, low_exc_rms); - + speex_encoder_ctl(st->st_low, SPEEX_GET_LOW_MODE, &dtx); if (dtx==0) @@ -588,12 +588,12 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) ALLOC(interp_lpc, st->lpcSize, spx_coef_t); ALLOC(bw_lpc1, st->lpcSize, spx_coef_t); ALLOC(bw_lpc2, st->lpcSize, spx_coef_t); - + ALLOC(lsp, st->lpcSize, spx_lsp_t); ALLOC(qlsp, st->lpcSize, spx_lsp_t); ALLOC(interp_lsp, st->lpcSize, spx_lsp_t); ALLOC(interp_qlsp, st->lpcSize, spx_lsp_t); - + { VARDECL(spx_word16_t *autocorr); VARDECL(spx_word16_t *w_sig); @@ -661,14 +661,14 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) ratio = 2*log((1.f+e_high)/(1.f+e_low)); - + speex_encoder_ctl(st->st_low, SPEEX_GET_RELATIVE_QUALITY, &st->relative_quality); if (ratio<-4) ratio=-4; if (ratio>2) ratio=2; /*if (ratio>-2)*/ - if (st->vbr_enabled) + if (st->vbr_enabled) { spx_int32_t modeid; modeid = mode->nb_modes-1; @@ -683,7 +683,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) if (v1==10) thresh = mode->vbr_thresh[modeid][v1]; else - thresh = (st->vbr_quality-v1) * mode->vbr_thresh[modeid][v1+1] + + thresh = (st->vbr_quality-v1) * mode->vbr_thresh[modeid][v1+1] + (1+v1-st->vbr_quality) * mode->vbr_thresh[modeid][v1]; if (st->relative_quality >= thresh && st->sampling_rate*st->submodes[modeid]->bits_per_frame/st->full_frame_size <= st->vbr_max_high) break; @@ -744,7 +744,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) /* LSP quantization */ - SUBMODE(lsp_quant)(lsp, qlsp, st->lpcSize, bits); + SUBMODE(lsp_quant)(lsp, qlsp, st->lpcSize, bits); if (st->first) { @@ -753,7 +753,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) for (i=0;ilpcSize;i++) st->old_qlsp[i] = qlsp[i]; } - + ALLOC(mem, st->lpcSize, spx_mem_t); ALLOC(syn_resp, st->subframeSize, spx_word16_t); ALLOC(innov, st->subframeSize, spx_sig_t); @@ -775,7 +775,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) ALLOC(exc, st->subframeSize, spx_word16_t); ALLOC(res, st->subframeSize, spx_word16_t); ALLOC(sw, st->subframeSize, spx_word16_t); - + /* LSP interpolation (quantized and unquantized) */ lsp_interpolate(st->old_lsp, lsp, interp_lsp, st->lpcSize, sub, st->nbSubframes, LSP_MARGIN); lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes, LSP_MARGIN); @@ -795,14 +795,14 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) rh += st->interp_qlpc[i+1] - st->interp_qlpc[i]; st->pi_gain[sub] += st->interp_qlpc[i] + st->interp_qlpc[i+1]; } - + rl = low_pi_gain[sub]; #ifdef FIXED_POINT filter_ratio=EXTRACT16(SATURATE(PDIV32(SHL32(ADD32(rl,82),7),ADD32(82,rh)),32767)); #else filter_ratio=(rl+.01)/(rh+.01); #endif - + /* Compute "real excitation" */ fir_mem16(sp, st->interp_qlpc, exc, st->subframeSize, st->lpcSize, st->mem_sp2, stack); /* Compute energy of low-band and high-band excitation */ @@ -816,7 +816,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) /* Gain to use if we want to use the low-band excitation for high-band */ g=PDIV32(MULT16_16(filter_ratio,eh),EXTEND32(ADD16(1,el))); - + #if 0 { char *tmp_stack=stack; @@ -873,11 +873,11 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) compute_impulse_response(st->interp_qlpc, bw_lpc1, bw_lpc2, syn_resp, st->subframeSize, st->lpcSize, stack); - + /* Reset excitation */ for (i=0;isubframeSize;i++) res[i]=VERY_SMALL; - + /* Compute zero response (ringing) of A(z/g1) / ( A(z/g2) * Aq(z) ) */ for (i=0;ilpcSize;i++) mem[i]=st->mem_sp[i]; @@ -902,8 +902,8 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) SPEEX_MEMSET(innov, 0, st->subframeSize); /*print_vec(target, st->subframeSize, "\ntarget");*/ - SUBMODE(innovation_quant)(target, st->interp_qlpc, bw_lpc1, bw_lpc2, - SUBMODE(innovation_params), st->lpcSize, st->subframeSize, + SUBMODE(innovation_quant)(target, st->interp_qlpc, bw_lpc1, bw_lpc2, + SUBMODE(innovation_params), st->lpcSize, st->subframeSize, innov, syn_resp, bits, stack, st->complexity, SUBMODE(double_codebook)); /*print_vec(target, st->subframeSize, "after");*/ @@ -917,8 +917,8 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) for (i=0;isubframeSize;i++) target[i]=MULT16_16_P13(QCONST16(2.5f,13), target[i]); - SUBMODE(innovation_quant)(target, st->interp_qlpc, bw_lpc1, bw_lpc2, - SUBMODE(innovation_params), st->lpcSize, st->subframeSize, + SUBMODE(innovation_quant)(target, st->interp_qlpc, bw_lpc1, bw_lpc2, + SUBMODE(innovation_params), st->lpcSize, st->subframeSize, innov2, syn_resp, bits, stack, st->complexity, 0); signal_mul(innov2, innov2, MULT16_32_P15(QCONST16(0.4f,15),scale), st->subframeSize); @@ -934,17 +934,17 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) st->innov_rms_save[sub] = MULT16_16_Q15(QCONST16(.70711f, 15), compute_rms(innov, st->subframeSize)); } st->exc_rms[sub] = compute_rms16(exc, st->subframeSize); - + } - + /*Keep the previous memory*/ for (i=0;ilpcSize;i++) mem[i]=st->mem_sp[i]; /* Final signal synthesis from excitation */ iir_mem16(exc, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp, stack); - + /* Compute weighted signal again, from synthesized speech (not sure it's the right thing) */ filter_mem16(sp, bw_lpc1, bw_lpc2, sw, st->subframeSize, st->lpcSize, st->mem_sw, stack); } @@ -1009,7 +1009,7 @@ void *sb_decoder_init(const SpeexMode *m) st->pi_gain = (spx_word32_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word32_t)); st->exc_rms = (spx_word16_t*)speex_alloc((st->nbSubframes)*sizeof(spx_word16_t)); st->mem_sp = (spx_mem_t*)speex_alloc((2*st->lpcSize)*sizeof(spx_mem_t)); - + st->innov_save = NULL; @@ -1187,8 +1187,8 @@ static void sb_decode_lost(SBDecState *st, spx_word16_t *out, int dtx, char *sta } st->first=1; - - + + /* Final signal synthesis from excitation */ if (!dtx) { @@ -1197,10 +1197,10 @@ static void sb_decode_lost(SBDecState *st, spx_word16_t *out, int dtx, char *sta for (i=0;iframe_size;i++) out[i+st->frame_size] = speex_rand(st->last_ener, &st->seed); - iir_mem16(out+st->frame_size, st->interp_qlpc, out+st->frame_size, st->frame_size, st->lpcSize, + iir_mem16(out+st->frame_size, st->interp_qlpc, out+st->frame_size, st->frame_size, st->lpcSize, st->mem_sp, stack); - - + + /* Reconstruct the original */ qmf_synth(out, out+st->frame_size, h0, out, st->full_frame_size, QMF_ORDER, st->g0_mem, st->g1_mem, stack); if (dtx) @@ -1228,7 +1228,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) spx_word16_t *out = (spx_word16_t*)vout; spx_word16_t *low_innov_alias; spx_word32_t exc_ener_sum = 0; - + st = (SBDecState*)state; stack=st->stack; mode = (const SpeexSBMode*)(st->mode->mode); @@ -1308,13 +1308,13 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) ALLOC(qlsp, st->lpcSize, spx_lsp_t); ALLOC(interp_qlsp, st->lpcSize, spx_lsp_t); SUBMODE(lsp_unquant)(qlsp, st->lpcSize, bits); - + if (st->first) { for (i=0;ilpcSize;i++) st->old_qlsp[i] = qlsp[i]; } - + ALLOC(ak, st->lpcSize, spx_coef_t); for (sub=0;subnbSubframes;sub++) @@ -1326,7 +1326,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) spx_word16_t el=0; int offset; spx_word32_t rl=0,rh=0; - + offset = st->subframeSize*sub; sp=out+st->frame_size+offset; ALLOC(exc, st->subframeSize, spx_word32_t); @@ -1336,7 +1336,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) innov_save = st->innov_save+2*offset; SPEEX_MEMSET(innov_save, 0, 2*st->subframeSize); } - + /* LSP interpolation */ lsp_interpolate(st->old_qlsp, qlsp, interp_qlsp, st->lpcSize, sub, st->nbSubframes, LSP_MARGIN); @@ -1345,7 +1345,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) /* Calculate reponse ratio between the low and high filter in the middle of the band (4000 Hz) */ - + st->pi_gain[sub]=LPC_SCALING; rh = LPC_SCALING; for (i=0;ilpcSize;i+=2) @@ -1360,7 +1360,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) #else filter_ratio=(rl+.01)/(rh+.01); #endif - + SPEEX_MEMSET(exc, 0, st->subframeSize); if (!SUBMODE(innovation_unquant)) { @@ -1369,20 +1369,20 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) quant = speex_bits_unpack_unsigned(bits, 5); g= spx_exp(MULT16_16(QCONST16(.125f,11),(quant-10))); - + g = PDIV32(g, filter_ratio); - + for (i=0;isubframeSize;i+=2) { exc[i]=SHL32(MULT16_32_P15(MULT16_16_Q15(mode->folding_gain,low_innov_alias[offset+i]),SHL32(g,6)),SIG_SHIFT); exc[i+1]=NEG32(SHL32(MULT16_32_P15(MULT16_16_Q15(mode->folding_gain,low_innov_alias[offset+i+1]),SHL32(g,6)),SIG_SHIFT)); } - + } else { spx_word16_t gc; spx_word32_t scale; int qgc = speex_bits_unpack_unsigned(bits, 4); - + el = low_exc_rms[sub]; gc = MULT16_16_Q15(QCONST16(0.87360,15),gc_quant_bound[qgc]); @@ -1390,7 +1390,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) gc = MULT16_16_P14(QCONST16(1.4142f,14),gc); scale = SHL32(PDIV32(SHL32(MULT16_16(gc, el),3), filter_ratio),SIG_SHIFT-3); - SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize, + SUBMODE(innovation_unquant)(exc, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed); signal_mul(exc,exc,scale,st->subframeSize); @@ -1400,7 +1400,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) VARDECL(spx_sig_t *innov2); ALLOC(innov2, st->subframeSize, spx_sig_t); SPEEX_MEMSET(innov2, 0, st->subframeSize); - SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, + SUBMODE(innovation_unquant)(innov2, SUBMODE(innovation_params), st->subframeSize, bits, stack, &st->seed); signal_mul(innov2, innov2, MULT16_32_P15(QCONST16(0.4f,15),scale), st->subframeSize); for (i=0;isubframeSize;i++) @@ -1409,14 +1409,14 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) } } - + if (st->innov_save) { for (i=0;isubframeSize;i++) innov_save[2*i]=EXTRACT16(PSHR32(exc[i],SIG_SHIFT)); } - - iir_mem16(st->excBuf, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, + + iir_mem16(st->excBuf, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp, stack); for (i=0;isubframeSize;i++) st->excBuf[i]=EXTRACT16(PSHR32(exc[i],SIG_SHIFT)); @@ -1426,7 +1426,7 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) exc_ener_sum = ADD32(exc_ener_sum, DIV32(MULT16_16(st->exc_rms[sub],st->exc_rms[sub]), st->nbSubframes)); } st->last_ener = spx_sqrt(exc_ener_sum); - + qmf_synth(out, out+st->frame_size, h0, out, st->full_frame_size, QMF_ORDER, st->g0_mem, st->g1_mem, stack); for (i=0;ilpcSize;i++) st->old_qlsp[i] = qlsp[i]; diff --git a/libspeex/smallft.c b/libspeex/smallft.c index 5c26d01..82c3b0a 100644 --- a/libspeex/smallft.c +++ b/libspeex/smallft.c @@ -127,7 +127,7 @@ static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){ t1+=ido; t2+=ido; } - + if(ido<2)return; if(ido==2)goto L105; @@ -174,7 +174,7 @@ static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1, int i,k,t0,t1,t2,t3,t4,t5,t6; float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4; t0=l1*ido; - + t1=t0; t4=t1<<1; t2=t1+(t1<<1); @@ -246,7 +246,7 @@ static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1, if(ido&1)return; L105: - + t2=(t1=t0+ido-1)+(t0<<1); t3=ido<<2; t4=ido; @@ -280,7 +280,7 @@ static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1, int nbd; float dcp,arg,dsp,ar1h,ar2h; int idp2,ipp2; - + arg=tpi/(float)ip; dcp=cos(arg); dsp=sin(arg); @@ -638,7 +638,7 @@ static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){ float ti2,tr2; t0=l1*ido; - + t1=0; t2=0; t3=(ido<<1)-1; @@ -754,7 +754,7 @@ static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1, int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8; float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4; t0=l1*ido; - + t1=0; t2=ido<<2; t3=0; @@ -763,7 +763,7 @@ static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1, t4=t3+t6; t5=t1; tr3=cc[t4-1]+cc[t4-1]; - tr4=cc[t4]+cc[t4]; + tr4=cc[t4]+cc[t4]; tr1=cc[t3]-cc[(t4+=t6)-1]; tr2=cc[t3]+cc[t4-1]; ch[t5]=tr2+tr3; @@ -858,7 +858,7 @@ static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1, ipp2=ip; ipph=(ip+1)>>1; if(idospeex_version[i]=SPEEX_VERSION[i]; for (;ispeex_version[i]=0; - + header->speex_version_id = 1; header->header_size = sizeof(SpeexHeader); - + header->rate = rate; header->mode = m->modeID; header->mode_bitstream_version = m->bitstream_version; @@ -111,7 +111,7 @@ EXPORT void speex_init_header(SpeexHeader *header, int rate, int nb_channels, co header->bitrate = -1; speex_mode_query(m, SPEEX_MODE_FRAME_SIZE, &header->frame_size); header->vbr = 0; - + header->frames_per_packet = 0; header->extra_headers = 0; header->reserved1 = 0; @@ -122,9 +122,9 @@ EXPORT char *speex_header_to_packet(SpeexHeader *header, int *size) { SpeexHeader *le_header; le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader)); - + SPEEX_COPY(le_header, header, 1); - + /*Make sure everything is now little-endian*/ ENDIAN_SWITCH(le_header->speex_version_id); ENDIAN_SWITCH(le_header->header_size); @@ -164,9 +164,9 @@ EXPORT SpeexHeader *speex_packet_to_header(char *packet, int size) } le_header = (SpeexHeader*)speex_alloc(sizeof(SpeexHeader)); - + SPEEX_COPY(le_header, (SpeexHeader*)packet, 1); - + /*Make sure everything is converted correctly from little-endian*/ ENDIAN_SWITCH(le_header->speex_version_id); ENDIAN_SWITCH(le_header->header_size); diff --git a/libspeex/stereo.c b/libspeex/stereo.c index 8fee55e..83642cb 100644 --- a/libspeex/stereo.c +++ b/libspeex/stereo.c @@ -1,21 +1,21 @@ -/* Copyright (C) 2002 Jean-Marc Valin +/* Copyright (C) 2002 Jean-Marc Valin File: stereo.c Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -69,7 +69,7 @@ static const spx_word16_t balance_bounds[31] = {18, 23, 30, 38, 49, 63, 81, 104 #ifdef FIXED_POINT #define COMPATIBILITY_HACK(s) do {if ((s)->reserved1 != 0xdeadbeef) speex_stereo_state_reset((SpeexStereoState*)s); } while (0); #else -#define COMPATIBILITY_HACK(s) +#define COMPATIBILITY_HACK(s) #endif EXPORT SpeexStereoState *speex_stereo_state_init() @@ -96,7 +96,7 @@ EXPORT void speex_stereo_state_reset(SpeexStereoState *_stereo) stereo->smooth_right = 1.f; stereo->reserved1 = 0; stereo->reserved2 = 0; -#endif +#endif } EXPORT void speex_stereo_state_destroy(SpeexStereoState *stereo) @@ -124,7 +124,7 @@ EXPORT void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits) /*Quantization*/ speex_bits_pack(bits, 14, 5); speex_bits_pack(bits, SPEEX_INBAND_STEREO, 4); - + balance=4*log(balance); /*Pack sign*/ @@ -135,9 +135,9 @@ EXPORT void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits) balance=floor(.5+fabs(balance)); if (balance>30) balance=31; - + speex_bits_pack(bits, (int)balance, 5); - + /* FIXME: this is a hack */ tmp=scal_quant(e_ratio*Q15_ONE, e_ratio_quant_bounds, 4); speex_bits_pack(bits, tmp, 2); @@ -154,7 +154,7 @@ EXPORT void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits #ifdef FIXED_POINT int shift; #endif - + /* In band marker */ speex_bits_pack(bits, 14, 5); /* Stereo marker */ @@ -199,9 +199,9 @@ EXPORT void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits if (balance_id>30) balance_id=31; #endif - + speex_bits_pack(bits, balance_id, 5); - + /* "coherence" quantisation */ #ifdef FIXED_POINT shift = spx_ilog2(e_tot); @@ -212,7 +212,7 @@ EXPORT void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits #else e_ratio = e_tot/(1.+e_left+e_right); #endif - + tmp=scal_quant(EXTRACT16(e_ratio), e_ratio_quant_bounds, 4); /*fprintf (stderr, "%d %d %d %d\n", largest, smallest, balance_id, e_ratio);*/ speex_bits_pack(bits, tmp, 2); @@ -231,12 +231,12 @@ EXPORT void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *_ spx_word32_t balance; spx_word16_t e_left, e_right, e_ratio; RealSpeexStereoState *stereo = (RealSpeexStereoState*)_stereo; - + COMPATIBILITY_HACK(stereo); - + balance=stereo->balance; e_ratio=stereo->e_ratio; - + /* These two are Q14, with max value just below 2. */ e_right = DIV32(QCONST32(1., 22), spx_sqrt(MULT16_32_Q15(e_ratio, ADD32(QCONST32(1., 16), balance)))); e_left = SHR32(MULT16_16(spx_sqrt(balance), e_right), 8); @@ -260,10 +260,10 @@ EXPORT void speex_decode_stereo_int(spx_int16_t *data, int frame_size, SpeexSter RealSpeexStereoState *stereo = (RealSpeexStereoState*)_stereo; COMPATIBILITY_HACK(stereo); - + balance=stereo->balance; e_ratio=stereo->e_ratio; - + /* These two are Q14, with max value just below 2. */ e_right = DIV32(QCONST32(1., 22), spx_sqrt(MULT16_32_Q15(e_ratio, ADD32(QCONST32(1., 16), balance)))); e_left = SHR32(MULT16_16(spx_sqrt(balance), e_right), 8); @@ -285,7 +285,7 @@ EXPORT int speex_std_stereo_request_handler(SpeexBits *bits, void *state, void * int tmp; stereo = (RealSpeexStereoState*)data; - + COMPATIBILITY_HACK(stereo); if (speex_bits_unpack_unsigned(bits, 1)) diff --git a/libspeex/testenc.c b/libspeex/testenc.c index 88a6492..1f634ed 100644 --- a/libspeex/testenc.c +++ b/libspeex/testenc.c @@ -114,7 +114,7 @@ int main(int argc, char **argv) rewind(fin); rewind(fout); - while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) + while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) && FRAME_SIZE == fread(out_short, sizeof(short), FRAME_SIZE,fout) ) { diff --git a/libspeex/testenc_uwb.c b/libspeex/testenc_uwb.c index 2dfd695..16da3cc 100644 --- a/libspeex/testenc_uwb.c +++ b/libspeex/testenc_uwb.c @@ -107,7 +107,7 @@ int main(int argc, char **argv) rewind(fin); rewind(fout); - while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) + while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) && FRAME_SIZE == fread(out_short, sizeof(short), FRAME_SIZE,fout) ) { @@ -131,6 +131,6 @@ int main(int argc, char **argv) #ifdef FIXED_DEBUG printf ("Total: %f MIPS\n", (float)(1e-6*50*spx_mips/snr_frames)); #endif - + return 1; } diff --git a/libspeex/testenc_wb.c b/libspeex/testenc_wb.c index 64ba237..c1beb43 100644 --- a/libspeex/testenc_wb.c +++ b/libspeex/testenc_wb.c @@ -110,7 +110,7 @@ int main(int argc, char **argv) rewind(fin); rewind(fout); - while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) + while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) && FRAME_SIZE == fread(out_short, sizeof(short), FRAME_SIZE,fout) ) { @@ -134,6 +134,6 @@ int main(int argc, char **argv) #ifdef FIXED_DEBUG printf ("Total: %f MIPS\n", (float)(1e-6*50*spx_mips/snr_frames)); #endif - + return 1; } diff --git a/libspeex/vbr.c b/libspeex/vbr.c index 8b014d1..16d5dc0 100644 --- a/libspeex/vbr.c +++ b/libspeex/vbr.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002 Jean-Marc Valin +/* Copyright (C) 2002 Jean-Marc Valin File: vbr.c VBR-related routines @@ -6,18 +6,18 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -55,7 +55,7 @@ const float vbr_nb_thresh[9][11]={ {11.0f, 11.0f, 9.9f, 8.5f, 7.0f, 5.25f, 4.5f, 4.0f, 4.0f, 4.0f, 2.0f}, /* 11 kbps */ {11.0f, 11.0f, 11.0f, 11.0f, 9.5f, 9.25f, 8.0f, 7.0f, 5.0f, 4.0f, 3.0f}, /* 15 kbps */ {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 9.5f, 8.5f, 6.2f, 5.2f, 5.0f}, /* 18 kbps */ - {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 10.0f, 9.8f, 7.5f}, /* 24 kbps */ + {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 10.0f, 9.8f, 7.5f}, /* 24 kbps */ { 7.0f, 4.5f, 3.7f, 3.0f, 2.5f, 1.0f, 1.8f, 1.5f, 1.0f, 0.0f, 0.0f} /* 4 kbps */ }; @@ -65,7 +65,7 @@ const float vbr_hb_thresh[5][11]={ {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}, /* 2 kbps */ {11.0f, 11.0f, 9.5f, 8.5f, 7.5f, 6.0f, 5.0f, 3.9f, 3.0f, 2.0f, 1.0f}, /* 6 kbps */ {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 9.5f, 8.7f, 7.8f, 7.0f, 6.5f, 4.0f}, /* 10 kbps */ - {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 9.8f, 7.5f, 5.5f} /* 18 kbps */ + {11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 11.0f, 9.8f, 7.5f, 5.5f} /* 18 kbps */ }; const float vbr_uhb_thresh[2][11]={ @@ -115,7 +115,7 @@ void vbr_init(VBRState *vbr) -Decrease bit-rate for males (low pitch)? - -(wideband only) less bits in the high-band when signal is very + -(wideband only) less bits in the high-band when signal is very non-stationary (harder to notice high-frequency noise)??? */ @@ -162,7 +162,7 @@ float vbr_analysis(VBRState *vbr, spx_word16_t *sig, int len, int pitch, float p vbr->consec_noise++; if (pow_ener > 3*vbr->noise_level) tmp = 3*vbr->noise_level; - else + else tmp = pow_ener; if (vbr->consec_noise>=4) { @@ -177,7 +177,7 @@ float vbr_analysis(VBRState *vbr, spx_word16_t *sig, int len, int pitch, float p if (pow_ener < vbr->noise_level && ener>MIN_ENERGY) { vbr->noise_accum = .95*vbr->noise_accum + .05*pow_ener; - vbr->noise_accum_count = .95*vbr->noise_accum_count + .05; + vbr->noise_accum_count = .95*vbr->noise_accum_count + .05; } /* Checking for very low absolute energy */ @@ -223,7 +223,7 @@ float vbr_analysis(VBRState *vbr, spx_word16_t *sig, int len, int pitch, float p qual=4; if (qual>10) qual=10; - + /* if (vbr->consec_noise>=2) qual-=1.3; @@ -239,7 +239,7 @@ float vbr_analysis(VBRState *vbr, spx_word16_t *sig, int len, int pitch, float p qual -= 1.0 * (log(3.0 + vbr->consec_noise)-log(3)); if (qual<0) qual=0; - + if (ener<1600000) { if (vbr->consec_noise>2) diff --git a/libspeex/vorbis_psy.c b/libspeex/vorbis_psy.c index 68a6fe9..cb385b7 100644 --- a/libspeex/vorbis_psy.c +++ b/libspeex/vorbis_psy.c @@ -4,18 +4,18 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -48,15 +48,15 @@ /* psychoacoustic setup ********************************************/ static VorbisPsyInfo example_tuning = { - - .5,.5, + + .5,.5, 3,3,25, - + /*63 125 250 500 1k 2k 4k 8k 16k*/ // vorbis mode 4 style //{-32,-32,-32,-32,-28,-24,-22,-20,-20, -20, -20, -8, -6, -6, -6, -6, -6}, { -4, -6, -6, -6, -6, -6, -6, -6, -8, -8,-10,-10, -8, -6, -4, -4, -2}, - + { 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */ 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */ @@ -78,16 +78,16 @@ static void _analysis_output(char *base,int i,float *v,int n,int bark,int dB){ sprintf(buffer,"%s_%d.m",base,i); of=fopen(buffer,"w"); - + if(!of)perror("failed to open data dump file"); - + for(j=0;j> 16; if( lo>=0 ) break; hi = b[i] & 0xffff; - + tN = N[hi] + N[-lo]; tX = X[hi] - X[-lo]; tXX = XX[hi] + XX[-lo]; - tY = Y[hi] + Y[-lo]; + tY = Y[hi] + Y[-lo]; tXY = XY[hi] - XY[-lo]; - + A = tY * tXX - tX * tXY; B = tN * tXY - tX * tY; D = tN * tXX - tX * tX; R = (A + x * B) / D; if (R < 0.f) R = 0.f; - + noise[i] = R - offset; } - + for ( ;; i++, x += 1.f) { - + lo = b[i] >> 16; hi = b[i] & 0xffff; if(hi>=n)break; - + tN = N[hi] - N[lo]; tX = X[hi] - X[lo]; tXX = XX[hi] - XX[lo]; tY = Y[hi] - Y[lo]; tXY = XY[hi] - XY[lo]; - + A = tY * tXX - tX * tXY; B = tN * tXY - tX * tY; D = tN * tXX - tX * tX; R = (A + x * B) / D; if (R < 0.f) R = 0.f; - + noise[i] = R - offset; } for ( ; i < n; i++, x += 1.f) { - + R = (A + x * B) / D; if (R < 0.f) R = 0.f; - + noise[i] = R - offset; } - + if (fixed <= 0) return; - + for (i = 0, x = 0.f;; i++, x += 1.f) { hi = i + fixed / 2; lo = hi - fixed; @@ -220,8 +220,8 @@ static void bark_noise_hybridmp(int n,const long *b, tXX = XX[hi] + XX[-lo]; tY = Y[hi] + Y[-lo]; tXY = XY[hi] - XY[-lo]; - - + + A = tY * tXX - tX * tXY; B = tN * tXY - tX * tY; D = tN * tXX - tX * tX; @@ -230,22 +230,22 @@ static void bark_noise_hybridmp(int n,const long *b, if (R - offset < noise[i]) noise[i] = R - offset; } for ( ;; i++, x += 1.f) { - + hi = i + fixed / 2; lo = hi - fixed; if(hi>=n)break; - + tN = N[hi] - N[lo]; tX = X[hi] - X[lo]; tXX = XX[hi] - XX[lo]; tY = Y[hi] - Y[lo]; tXY = XY[hi] - XY[lo]; - + A = tY * tXX - tX * tXY; B = tN * tXY - tX * tY; D = tN * tXX - tX * tX; R = (A + x * B) / D; - + if (R - offset < noise[i]) noise[i] = R - offset; } for ( ; i < n; i++, x += 1.f) { @@ -255,7 +255,7 @@ static void bark_noise_hybridmp(int n,const long *b, } static void _vp_noisemask(VorbisPsy *p, - float *logfreq, + float *logfreq, float *logmask){ int i,n=p->n/2; @@ -270,15 +270,15 @@ static void _vp_noisemask(VorbisPsy *p, p->vi->noisewindowfixed); for(i=0;in = n; spx_drft_init(&p->lookup, n); p->bark = speex_alloc(n*sizeof(*p->bark)); @@ -317,35 +317,35 @@ VorbisPsy *vorbis_psy_init(int rate, int n) sin((i+.5)/n * M_PI)*sin((i+.5)/n * M_PI); /* bark scale lookups */ for(i=0;ivi->noisewindowlominvi->noisewindowlominvi->noisewindowlo);lo++); - + for(;hi<=n && (hivi->noisewindowhimin || toBARK(rate/(2*n)*hi)<(bark+p->vi->noisewindowhi));hi++); - + p->bark[i]=((lo-1)<<16)+(hi-1); } /* set up rolling noise median */ p->noiseoffset=speex_alloc(n*sizeof(*p->noiseoffset)); - + for(i=0;i=P_BANDS-1)halfoc=P_BANDS-1; inthalfoc=(int)halfoc; del=halfoc-inthalfoc; - + p->noiseoffset[i]= - p->vi->noiseoff[inthalfoc]*(1.-del) + + p->vi->noiseoff[inthalfoc]*(1.-del) + p->vi->noiseoff[inthalfoc+1]*del; - + } #if 0 _analysis_output_always("noiseoff0",ls,p->noiseoffset,n,1,0,0); @@ -378,14 +378,14 @@ void compute_curve(VorbisPsy *psy, float *audio, float *curve) float scale_dB; scale_dB=todB(scale); - + /* window the PCM data; use a BH4 window, not vorbis */ for(i=0;in;i++) work[i]=audio[i] * psy->window[i]; { static int seq=0; - + //_analysis_output("win",seq,work,psy->n,0,0); seq++; @@ -432,7 +432,7 @@ void curve_to_lpc(VorbisPsy *psy, float *curve, float *awk1, float *awk2, int or ac[2*i-1] = curve[i]; ac[0] = curve[0]; ac[2*len-1] = curve[len-1]; - + spx_drft_backward(&psy->lookup, ac); _spx_lpc(awk1, ac, ord); tmp = 1.; @@ -447,7 +447,7 @@ void curve_to_lpc(VorbisPsy *psy, float *curve, float *awk1, float *awk2, int or #else /* Use the second (awk2) filter to correct the first one */ for (i=0;i<2*len;i++) - ac[i] = 0; + ac[i] = 0; for (i=0;ilookup, ac); _spx_lpc(awk2, ac, ord); tmp = 1; diff --git a/libspeex/vq.c b/libspeex/vq.c index e95e1f2..c7f1396 100644 --- a/libspeex/vq.c +++ b/libspeex/vq.c @@ -5,18 +5,18 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR diff --git a/libspeex/window.c b/libspeex/window.c index fe5ee70..a89d4d7 100644 --- a/libspeex/window.c +++ b/libspeex/window.c @@ -1,21 +1,21 @@ -/* Copyright (C) 2006 Jean-Marc Valin +/* Copyright (C) 2006 Jean-Marc Valin File: window.c Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -41,30 +41,30 @@ const spx_word16_t lag_window[11] = { }; const spx_word16_t lpc_window[200] = { -2621, 2627, 2642, 2668, 2704, 2750, 2807, 2874, -2951, 3038, 3135, 3242, 3359, 3486, 3623, 3769, -3925, 4090, 4264, 4448, 4641, 4843, 5053, 5272, -5500, 5736, 5981, 6233, 6493, 6761, 7036, 7319, -7609, 7905, 8209, 8519, 8835, 9157, 9485, 9819, -10158, 10502, 10852, 11206, 11564, 11926, 12293, 12663, -13037, 13414, 13793, 14176, 14561, 14948, 15337, 15727, -16119, 16512, 16906, 17300, 17695, 18089, 18484, 18877, -19270, 19662, 20053, 20442, 20829, 21214, 21596, 21976, -22353, 22726, 23096, 23463, 23826, 24184, 24538, 24887, -25231, 25570, 25904, 26232, 26555, 26871, 27181, 27484, -27781, 28070, 28353, 28628, 28896, 29157, 29409, 29653, -29889, 30117, 30336, 30547, 30749, 30941, 31125, 31300, -31465, 31621, 31767, 31903, 32030, 32147, 32254, 32352, -32439, 32516, 32582, 32639, 32685, 32722, 32747, 32763, -32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, -32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, -32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, -32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, -32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, -32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, -32767, 32767, 32767, 32723, 32590, 32368, 32058, 31661, -31177, 30610, 29959, 29227, 28416, 27528, 26566, 25532, -24430, 23263, 22034, 20747, 19406, 18015, 16579, 15104, +2621, 2627, 2642, 2668, 2704, 2750, 2807, 2874, +2951, 3038, 3135, 3242, 3359, 3486, 3623, 3769, +3925, 4090, 4264, 4448, 4641, 4843, 5053, 5272, +5500, 5736, 5981, 6233, 6493, 6761, 7036, 7319, +7609, 7905, 8209, 8519, 8835, 9157, 9485, 9819, +10158, 10502, 10852, 11206, 11564, 11926, 12293, 12663, +13037, 13414, 13793, 14176, 14561, 14948, 15337, 15727, +16119, 16512, 16906, 17300, 17695, 18089, 18484, 18877, +19270, 19662, 20053, 20442, 20829, 21214, 21596, 21976, +22353, 22726, 23096, 23463, 23826, 24184, 24538, 24887, +25231, 25570, 25904, 26232, 26555, 26871, 27181, 27484, +27781, 28070, 28353, 28628, 28896, 29157, 29409, 29653, +29889, 30117, 30336, 30547, 30749, 30941, 31125, 31300, +31465, 31621, 31767, 31903, 32030, 32147, 32254, 32352, +32439, 32516, 32582, 32639, 32685, 32722, 32747, 32763, +32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, +32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, +32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, +32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, +32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, +32767, 32767, 32767, 32767, 32767, 32767, 32767, 32767, +32767, 32767, 32767, 32723, 32590, 32368, 32058, 31661, +31177, 30610, 29959, 29227, 28416, 27528, 26566, 25532, +24430, 23263, 22034, 20747, 19406, 18015, 16579, 15104, 13594, 12058, 10503, 8941, 7391, 5887, 4498, 3392 }; #else diff --git a/speexclient/alsa_device.c b/speexclient/alsa_device.c index a3a4abb..90b9fe4 100644 --- a/speexclient/alsa_device.c +++ b/speexclient/alsa_device.c @@ -2,7 +2,7 @@ Copyright (C) 2004-2006 Jean-Marc Valin Copyright (C) 2006 Commonwealth Scientific and Industrial Research Organisation (CSIRO) Australia - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -66,7 +66,7 @@ AlsaDevice *alsa_device_open(char *device_name, unsigned int rate, int channels, dev->channels = channels; dev->period = period; err = snd_output_stdio_attach(&jcd_out, stdout, 0); - + if ((err = snd_pcm_open (&dev->capture_handle, dev->device_name, SND_PCM_STREAM_CAPTURE, 0)) < 0) { fprintf (stderr, "cannot open audio device %s (%s)\n", dev->device_name, @@ -110,7 +110,7 @@ AlsaDevice *alsa_device_open(char *device_name, unsigned int rate, int channels, snd_strerror (err)); assert(0); } - + period_size = period; dir = 0; if ((err = snd_pcm_hw_params_set_period_size_near (dev->capture_handle, hw_params, &period_size, &dir)) < 0) { @@ -118,13 +118,13 @@ AlsaDevice *alsa_device_open(char *device_name, unsigned int rate, int channels, snd_strerror (err)); assert(0); } - + if ((err = snd_pcm_hw_params_set_periods (dev->capture_handle, hw_params, 2, 0)) < 0) { fprintf (stderr, "cannot set number of periods (%s)\n", snd_strerror (err)); assert(0); } - + buffer_size = period_size * 2; dir=0; if ((err = snd_pcm_hw_params_set_buffer_size_near (dev->capture_handle, hw_params, &buffer_size)) < 0) { @@ -132,7 +132,7 @@ AlsaDevice *alsa_device_open(char *device_name, unsigned int rate, int channels, snd_strerror (err)); assert(0); } - + if ((err = snd_pcm_hw_params (dev->capture_handle, hw_params)) < 0) { fprintf (stderr, "cannot set capture parameters (%s)\n", snd_strerror (err)); @@ -160,16 +160,16 @@ AlsaDevice *alsa_device_open(char *device_name, unsigned int rate, int channels, fprintf (stderr, "cannot set software parameters (%s)\n", snd_strerror (err)); assert(0); - } - - + } + + if ((err = snd_pcm_open (&dev->playback_handle, dev->device_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { fprintf (stderr, "cannot open audio device %s (%s)\n", dev->device_name, snd_strerror (err)); assert(0); } - + if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) { fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n", snd_strerror (err)); @@ -206,7 +206,7 @@ AlsaDevice *alsa_device_open(char *device_name, unsigned int rate, int channels, snd_strerror (err)); assert(0); } - + period_size = period; dir = 0; if ((err = snd_pcm_hw_params_set_period_size_near (dev->playback_handle, hw_params, &period_size, &dir)) < 0) { @@ -237,7 +237,7 @@ AlsaDevice *alsa_device_open(char *device_name, unsigned int rate, int channels, /*snd_pcm_dump_setup(dev->playback_handle, jcd_out);*/ snd_pcm_hw_params_free (hw_params); - + if ((err = snd_pcm_sw_params_malloc (&sw_params)) < 0) { fprintf (stderr, "cannot allocate software parameters structure (%s)\n", snd_strerror (err)); @@ -263,8 +263,8 @@ AlsaDevice *alsa_device_open(char *device_name, unsigned int rate, int channels, snd_strerror (err)); assert(0); } - - + + snd_pcm_link(dev->capture_handle, dev->playback_handle); if ((err = snd_pcm_prepare (dev->capture_handle)) < 0) { fprintf (stderr, "cannot prepare audio interface for use (%s)\n", @@ -276,7 +276,7 @@ AlsaDevice *alsa_device_open(char *device_name, unsigned int rate, int channels, snd_strerror (err)); assert(0); } - + dev->readN = snd_pcm_poll_descriptors_count(dev->capture_handle); dev->writeN = snd_pcm_poll_descriptors_count(dev->playback_handle); @@ -288,7 +288,7 @@ AlsaDevice *alsa_device_open(char *device_name, unsigned int rate, int channels, snd_strerror (err)); assert(0); } - + dev->write_fd = malloc(dev->writeN*sizeof(*dev->read_fd)); if (snd_pcm_poll_descriptors(dev->playback_handle, dev->write_fd, dev->writeN) != dev->writeN) { diff --git a/speexclient/speex_jitter_buffer.c b/speexclient/speex_jitter_buffer.c index 9df6659..aa76d26 100644 --- a/speexclient/speex_jitter_buffer.c +++ b/speexclient/speex_jitter_buffer.c @@ -43,7 +43,7 @@ void speex_jitter_get(SpeexJitter *jitter, spx_int16_t *out, int *current_timest JitterBufferPacket packet; packet.data = data; packet.len = 2048; - + if (jitter->valid_bits) { /* Try decoding last received packet */ @@ -58,7 +58,7 @@ void speex_jitter_get(SpeexJitter *jitter, spx_int16_t *out, int *current_timest } ret = jitter_buffer_get(jitter->packets, &packet, jitter->frame_size, NULL); - + if (ret != JITTER_BUFFER_OK) { /* No packet found */ diff --git a/speexclient/speexclient.c b/speexclient/speexclient.c index cb375c9..116befe 100644 --- a/speexclient/speexclient.c +++ b/speexclient/speexclient.c @@ -6,18 +6,18 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -29,9 +29,9 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - + ****************************************************************************/ - + #ifdef HAVE_CONFIG_H #include #endif @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) { - + int sd, rc, n; int i; struct sockaddr_in cliAddr, remoteAddr; @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "wrong options\n"); exit(1); } - + h = gethostbyname(argv[2]); if(h==NULL) { fprintf(stderr, "%s: unknown host '%s' \n", argv[0], argv[1]); @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) local_port = atoi(argv[3]); remote_port = atoi(argv[4]); - + printf("%s: sending data to '%s' (IP : %s) \n", argv[0], h->h_name, inet_ntoa(*(struct in_addr *)h->h_addr_list[0])); @@ -119,7 +119,7 @@ int main(int argc, char *argv[]) /* Setup audio device */ audio_dev = alsa_device_open(argv[1], SAMPLING_RATE, 1, FRAME_SIZE); - + /* Setup the encoder and decoder in wideband */ void *enc_state, *dec_state; enc_state = speex_encoder_init(&speex_wb_mode); @@ -133,8 +133,8 @@ int main(int argc, char *argv[]) SpeexBits enc_bits, dec_bits; speex_bits_init(&enc_bits); speex_bits_init(&dec_bits); - - + + struct sched_param param; /*param.sched_priority = 40; */ param.sched_priority = sched_get_priority_min(SCHED_FIFO); @@ -143,7 +143,7 @@ int main(int argc, char *argv[]) int send_timestamp = 0; int recv_started=0; - + /* Setup all file descriptors for poll()ing */ nfds = alsa_device_nfds(audio_dev); pfds = malloc(sizeof(*pfds)*(nfds+1)); @@ -154,7 +154,7 @@ int main(int argc, char *argv[]) /* Setup jitter buffer using decoder */ SpeexJitter jitter; speex_jitter_init(&jitter, dec_state, SAMPLING_RATE); - + /* Echo canceller with 200 ms tail length */ SpeexEchoState *echo_state = speex_echo_state_init(FRAME_SIZE, 10*FRAME_SIZE); tmp = SAMPLING_RATE; @@ -163,9 +163,9 @@ int main(int argc, char *argv[]) /* Setup preprocessor and associate with echo canceller for residual echo suppression */ preprocess = speex_preprocess_state_init(FRAME_SIZE, SAMPLING_RATE); speex_preprocess_ctl(preprocess, SPEEX_PREPROCESS_SET_ECHO_STATE, echo_state); - + alsa_device_start(audio_dev); - + /* Infinite loop on capture, playback and receiving packets */ while (1) { @@ -178,8 +178,8 @@ int main(int argc, char *argv[]) n = recv(sd, msg, MAX_MSG, 0); int recv_timestamp = ((int*)msg)[1]; int payload = ((int*)msg)[0]; - - if ((payload & 0x80000000) == 0) + + if ((payload & 0x80000000) == 0) { /* Put content of the packet into the jitter buffer, except for the pseudo-header */ speex_jitter_put(&jitter, msg+8, n-8, recv_timestamp); @@ -212,21 +212,21 @@ int main(int argc, char *argv[]) char outpacket[MAX_MSG]; /* Get audio from the soundcard */ alsa_device_read(audio_dev, pcm, FRAME_SIZE); - + /* Perform echo cancellation */ speex_echo_capture(echo_state, pcm, pcm2); for (i=0;i 2150 * 1 -> 3950 @@ -72,12 +72,12 @@ extern long long spx_mips; #include #ifdef MANUAL_ALLOC -/* Take all Speex space from this private heap */ +/* Take all Speex space from this private heap */ /* This is useful for multichannel applications */ -#pragma DATA_SECTION(spxHeap, ".myheap"); +#pragma DATA_SECTION(spxHeap, ".myheap"); static char spxHeap[SPEEX_PERSIST_STACK_SIZE]; -#pragma DATA_SECTION(spxScratch, ".myheap"); +#pragma DATA_SECTION(spxScratch, ".myheap"); static char spxScratch[SPEEX_SCRATCH_STACK_SIZE]; char *spxGlobalHeapPtr, *spxGlobalHeapEnd; @@ -88,7 +88,7 @@ void byte2word(short* pInBuf, short* pOutBuf, int nWords) { short *pIn, *pOut, sNext; int i; - + pIn = pInBuf; pOut = pOutBuf; for(i=0;i> 8); } } - + void main() { char *outFile, *bitsFile; @@ -140,7 +140,7 @@ void main() spx_int32_t skip_group_delay; SpeexCallback callback; - /* C54xx defaults to max wait states, even for parts like C5416 with + /* C54xx defaults to max wait states, even for parts like C5416 with larger internal memory. Need to force the wait state register to zero */ #ifdef CONFIG_TI_C54X @@ -209,7 +209,7 @@ void main() #endif outFile = "c:\\speextrunktest\\samples\\maleout5x.snd"; fout = fopen(outFile, "wb+"); - + speex_bits_init(&bits); #ifndef DECODE_ONLY while (!feof(fin)) @@ -222,7 +222,7 @@ void main() speex_bits_reset(&bits); speex_encode_int(st, in_short, &bits); - nbChars = speex_bits_write(&bits, cbits, + nbChars = speex_bits_write(&bits, cbits, sizeof(cbits)*BYTES_PER_CHAR) /BYTES_PER_CHAR; bitCount+=bits.nbBits; @@ -260,7 +260,7 @@ void main() rewind(fin); rewind(fout); - while ( FRAME_SIZE == fread(inout_byte, 2, FRAME_SIZE, fin)) + while ( FRAME_SIZE == fread(inout_byte, 2, FRAME_SIZE, fin)) { float s=0, e=0; diff --git a/ti/testenc-TI-C64x.c b/ti/testenc-TI-C64x.c index 8d6e97a..5902717 100644 --- a/ti/testenc-TI-C64x.c +++ b/ti/testenc-TI-C64x.c @@ -1,5 +1,5 @@ /* Copyright (C) 2005 Psi Systems, Inc. - Author: Jean-Marc Valin + Author: Jean-Marc Valin File: testenc-TI-C64x.c Encoder/Decoder Loop Main file for TI TMS320C64xx processor for use with TI Code Composer (TM) DSP development tools. @@ -9,18 +9,18 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + - Neither the name of the Xiph.org Foundation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR @@ -50,7 +50,7 @@ //#define TESTENC_BYTES_PER_FRAME 28 /* 11kbps */ //#define TESTENC_QUALITY 5 /* 11 kbps */ -/* For narrowband, QUALITY maps to these bit rates (see modes.c, manual.pdf) +/* For narrowband, QUALITY maps to these bit rates (see modes.c, manual.pdf) * {1, 8, 2, 3, 3, 4, 4, 5, 5, 6, 7} * 0 -> 2150 * 1 -> 3950 @@ -69,12 +69,12 @@ extern long long spx_mips; #endif #ifdef MANUAL_ALLOC -/* Take all Speex space from this private heap */ +/* Take all Speex space from this private heap */ /* This is useful for multichannel applications */ -#pragma DATA_SECTION(spxHeap, ".myheap"); +#pragma DATA_SECTION(spxHeap, ".myheap"); static char spxHeap[SPEEX_PERSIST_STACK_SIZE]; -#pragma DATA_SECTION(spxScratch, ".myheap"); +#pragma DATA_SECTION(spxScratch, ".myheap"); static char spxScratch[SPEEX_SCRATCH_STACK_SIZE]; char *spxGlobalHeapPtr, *spxGlobalHeapEnd; @@ -171,7 +171,7 @@ void main() #endif outFile = "c:\\speextrunktest\\samples\\maleout6x.snd"; fout = fopen(outFile, "wb+"); - + speex_bits_init(&bits); #ifndef DECODE_ONLY while (!feof(fin)) @@ -200,7 +200,7 @@ void main() // bitCount+=160; /* only correct for 8kbps, but just for the printf */ bitCount+=bits.nbBits; #endif - + speex_decode_int(dec, &bits, out_short); speex_bits_reset(&bits); @@ -214,11 +214,11 @@ void main() speex_encoder_destroy(st); speex_decoder_destroy(dec); -#ifdef CHECK_RESULT +#ifdef CHECK_RESULT rewind(fin); rewind(fout); - while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) + while ( FRAME_SIZE == fread(in_short, sizeof(short), FRAME_SIZE, fin) && FRAME_SIZE == fread(out_short, sizeof(short), FRAME_SIZE,fout) ) { diff --git a/tmv/config.h b/tmv/config.h index 0b68fb8..ea7abe1 100644 --- a/tmv/config.h +++ b/tmv/config.h @@ -19,23 +19,23 @@ #define TM_DEBUGMEM_ALIGNNMENT 1 -#define TM_PROFILE 1 -#define TM_PROFILE_FIRMEM16 0 -#define TM_PROFILE_IIRMEM16 0 -#define TM_PROFILE_FILTERMEM16 0 -#define TM_PROFILE_VQNBEST 0 -#define TM_PROFILE_VQNBESTSIGN 0 -#define TM_PROFILE_COMPUTEQUANTWEIGHTS 0 -#define TM_PROFILE_LSPQUANT 0 +#define TM_PROFILE 1 +#define TM_PROFILE_FIRMEM16 0 +#define TM_PROFILE_IIRMEM16 0 +#define TM_PROFILE_FILTERMEM16 0 +#define TM_PROFILE_VQNBEST 0 +#define TM_PROFILE_VQNBESTSIGN 0 +#define TM_PROFILE_COMPUTEQUANTWEIGHTS 0 +#define TM_PROFILE_LSPQUANT 0 #define TM_PROFILE_LSPWEIGHTQUANT 0 #define TM_PROFILE_LSPENFORCEMARGIN 0 #define TM_PROFILE_LSPTOLPC 0 -#define TM_PROFILE_INNERPROD 0 -#define TM_PROFILE_PITCHXCORR 0 -#define TM_PROFILE_LSP_INTERPOLATE 0 -#define TM_PROFILE_CHEBPOLYEVA 0 -#define TM_PROFILE_COMPUTEWEIGHTEDCODEBOOK 0 -#define TM_PROFILE_TARGETUPDATE 0 +#define TM_PROFILE_INNERPROD 0 +#define TM_PROFILE_PITCHXCORR 0 +#define TM_PROFILE_LSP_INTERPOLATE 0 +#define TM_PROFILE_CHEBPOLYEVA 0 +#define TM_PROFILE_COMPUTEWEIGHTEDCODEBOOK 0 +#define TM_PROFILE_TARGETUPDATE 0 #define TM_PROFILE_SPXAUTOCORR 0 #define TM_PROFILE_COMPUTEPITCHERROR 0 #define TM_PROFILE_COMPUTERMS16 0 -- cgit v1.2.3