History

delete bundled libgsm

The bundled libgsm is outdated, and packages are available for most systems. Delete the local copy.

Mans Rullgard committed 6 years ago

Commit e5488271 parent 0aced4626 files · +31 −4430Browse files

Unified · Split

26 files
  1. Makefile.am +2 −2
  2. configure.ac +3 −19
  3. libgsm/.gitignore +0 −7
  4. libgsm/Makefile.am +0 −40
  5. libgsm/add.c +0 −234
  6. libgsm/aliases.h +0 −40
  7. libgsm/code.c +0 −91
  8. libgsm/decode.c +0 −62
  9. libgsm/gsm.3 +0 −105
  10. libgsm/gsm.h +0 −69
  11. libgsm/gsm_create.c +0 −27
  12. libgsm/gsm_decode.c +0 −360
  13. libgsm/gsm_destroy.c +0 −16
  14. libgsm/gsm_encode.c +0 −450
  15. libgsm/gsm_option.3 +0 −183
  16. libgsm/gsm_option.c +0 −69
  17. libgsm/long_term.c +0 −949
  18. libgsm/lpc.c +0 −339
  19. libgsm/preprocess.c +0 −112
  20. libgsm/private.h +0 −265
  21. libgsm/rpe.c +0 −489
  22. libgsm/short_term.c +0 −428
  23. libgsm/table.c +0 −63
  24. src/Makefile.am +0 −1
  25. src/gsm.c +0 −6
  26. src/wav.c +26 −4
Makefile.am+2−2
@@ -2,8 +2,8 @@ · 1 unmodified line
22
33 ACLOCAL_AMFLAGS = -I m4
44
5−SUBDIRS = lpc10 libgsm src
6−DIST_SUBDIRS = lpc10 libgsm src
5+SUBDIRS = lpc10 src
6+DIST_SUBDIRS = lpc10 src
77
88 RM = rm -f
99
configure.ac+3−19
@@ -420,13 +420,6 @@ found_libgsm=yes · 419 unmodified lines
420420 AC_CHECK_HEADERS(gsm/gsm.h, ,
421421 [AC_CHECK_HEADERS(gsm.h, ,found_libgsm=no)])
422422 AC_CHECK_LIB(gsm, gsm_create, GSM_LIBS="$GSM_LIBS -lgsm", found_libgsm=no)
423−if test "$found_libgsm" = yes; then
424− AC_DEFINE(EXTERNAL_GSM, 1, [Define if you are using an external GSM library])
425−else
426− LIBGSM_LIBADD=../libgsm/libgsm.la
427−fi
428−AM_CONDITIONAL(EXTERNAL_GSM, test x$found_libgsm = xyes)
429−AC_SUBST(LIBGSM_LIBADD)
430423
431424
432425
@@ -584,8 +577,7 @@ AC_OPTIONAL_FORMAT(mp3, MP3, [ · 151 unmodified lines
584577
585578
586579 # GSM format depends on libgsm
587−# No need to check; GSM is always found
588−AC_OPTIONAL_FORMAT(gsm, GSM)
580+AC_OPTIONAL_FORMAT(gsm, GSM, [using_gsm=$found_libgsm])
589581
590582
591583
@@ -622,17 +614,9 @@ AC_SUBST(PLAYRECLINKS) · 30 unmodified lines
622614 AM_CONDITIONAL(STATIC_LIBSOX_ONLY, test "$enable_shared" = "no" -a "$enable_static" = "yes")
623615
624616 dnl Generate output files.
625−AC_CONFIG_FILES(Makefile src/Makefile libgsm/Makefile lpc10/Makefile sox.pc)
617+AC_CONFIG_FILES(Makefile src/Makefile lpc10/Makefile sox.pc)
626618 AC_OUTPUT
627619
628−if test "$using_gsm" != "no"; then
629− if test "$found_libgsm" = "yes"; then
630− gsm_option="(external)"
631− else
632− gsm_option="(in-tree)"
633− fi
634−fi
635−
636620 if test "$using_lpc10" != "no"; then
637621 if test "$found_liblpc10" = "yes"; then
638622 lpc10_option="(external)"
@@ -677,7 +661,7 @@ if test "x$using_amrwb" = "xyes"; then · 38 unmodified lines
677661 echo " dlopen amrwb..............$enable_dl_amrwb"
678662 fi
679663 echo "flac.......................$using_flac"
680−echo "gsm........................$using_gsm $gsm_option"
664+echo "gsm........................$using_gsm"
681665 echo "lpc10......................$using_lpc10 $lpc10_option"
682666 echo "mp2/mp3....................$using_mp3"
683667 echo " id3tag....................$using_id3tag"
libgsm/.gitignore+0−7
@@ -1,7 +0,0 @@
1−Makefile
2−Makefile.in
3−.deps
4−*.o
5−*.lo
6−*.la
7−.libs
libgsm/Makefile.am+0−40
@@ -1,40 +0,0 @@
1−SASR = -DSASR
2−######### Define SASR if >> is a signed arithmetic shift (-1 >> 1 == -1)
3−
4−MULHACK = -DUSE_FLOAT_MUL
5−######### Define this if your host multiplies floats faster than integers,
6−######### e.g. on a SPARCstation.
7−
8−FAST = -DFAST
9−######### Define together with USE_FLOAT_MUL to enable the GSM library's
10−######### approximation option for incorrect, but good-enough results.
11−
12−# LTP_CUT = -DLTP_CUT
13−LTP_CUT =
14−######### Define to enable the GSM library's long-term correlation
15−######### approximation option---faster, but worse; works for
16−######### both integer and floating point multiplications.
17−######### This flag is still in the experimental stage.
18−
19−WAV49 = -DWAV49
20−#WAV49 =
21−######### Define to enable the GSM library's option to pack GSM frames
22−######### in the style used by the WAV #49 format. If you want to write
23−######### a tool that produces .WAV files which contain GSM-encoded data,
24−######### define this, and read about the GSM_OPT_WAV49 option in the
25−######### manual page on gsm_option(3).
26−
27−AM_CFLAGS = $(SASR) $(MULHAC) $(FAST) $(LTP_CUT) $(WAV49)
28−
29−if EXTERNAL_GSM
30−EXTRA_DIST = add.c code.c decode.c long_term.c lpc.c preprocess.c \
31− rpe.c gsm_destroy.c gsm_decode.c gsm_encode.c gsm_create.c \
32− gsm_option.c short_term.c table.c private.h gsm.h \
33− aliases.h
34−else
35−noinst_LTLIBRARIES = libgsm.la
36−noinst_HEADERS = gsm.h
37−libgsm_la_SOURCES = add.c code.c decode.c long_term.c lpc.c preprocess.c \
38− rpe.c gsm_destroy.c gsm_decode.c gsm_encode.c gsm_create.c \
39− gsm_option.c short_term.c table.c private.h aliases.h
40−endif
libgsm/add.c+0−234
@@ -1,234 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/add.c,v 1.1 2007/09/06 16:50:55 cbagwell Exp $ */
8−
9−/*
10− * See private.h for the more commonly used macro versions.
11− */
12−
13−#include <stdio.h>
14−#include <assert.h>
15−
16−#include "private.h"
17−#include "gsm.h"
18−
19−#define saturate(x) \
20− ((x) < MIN_WORD ? MIN_WORD : (x) > MAX_WORD ? MAX_WORD: (x))
21−
22−word gsm_add (word a, word b)
23−{
24− longword sum = (longword)a + (longword)b;
25− return saturate(sum);
26−}
27−
28−word gsm_sub (word a, word b)
29−{
30− longword diff = (longword)a - (longword)b;
31− return saturate(diff);
32−}
33−
34−word gsm_mult (word a, word b)
35−{
36− if (a == MIN_WORD && b == MIN_WORD) return MAX_WORD;
37− else return SASR( (longword)a * (longword)b, 15 );
38−}
39−
40−word gsm_mult_r (word a, word b)
41−{
42− if (b == MIN_WORD && a == MIN_WORD) return MAX_WORD;
43− else {
44− longword prod = (longword)a * (longword)b + 16384;
45− prod >>= 15;
46− return prod & 0xFFFF;
47− }
48−}
49−
50−word gsm_abs (word a)
51−{
52− return a < 0 ? (a == MIN_WORD ? MAX_WORD : -a) : a;
53−}
54−
55−longword gsm_L_mult (word a, word b)
56−{
57− assert( a != MIN_WORD || b != MIN_WORD );
58− return ((longword)a * (longword)b) << 1;
59−}
60−
61−longword gsm_L_add (longword a, longword b)
62−{
63− if (a < 0) {
64− if (b >= 0) return a + b;
65− else {
66− ulongword A = (ulongword)-(a + 1) + (ulongword)-(b + 1);
67− return A >= MAX_LONGWORD ? MIN_LONGWORD :-(longword)A-2;
68− }
69− }
70− else if (b <= 0) return a + b;
71− else {
72− ulongword A = (ulongword)a + (ulongword)b;
73− return A > MAX_LONGWORD ? MAX_LONGWORD : A;
74− }
75−}
76−
77−longword gsm_L_sub (longword a, longword b)
78−{
79− if (a >= 0) {
80− if (b >= 0) return a - b;
81− else {
82− /* a>=0, b<0 */
83−
84− ulongword A = (ulongword)a + -(b + 1);
85− return A >= MAX_LONGWORD ? MAX_LONGWORD : (A + 1);
86− }
87− }
88− else if (b <= 0) return a - b;
89− else {
90− /* a<0, b>0 */
91−
92− ulongword A = (ulongword)-(a + 1) + b;
93− return A >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)A - 1;
94− }
95−}
96−
97−static unsigned char const bitoff[ 256 ] = {
98− 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
99− 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
100− 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
101− 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
102− 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
103− 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
104− 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
105− 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
106− 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
107− 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
108− 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
109− 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110− 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
111− 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
112− 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
113− 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
114−};
115−
116−word gsm_norm (longword a )
117−/*
118− * the number of left shifts needed to normalize the 32 bit
119− * variable L_var1 for positive values on the interval
120− *
121− * with minimum of
122− * minimum of 1073741824 (01000000000000000000000000000000) and
123− * maximum of 2147483647 (01111111111111111111111111111111)
124− *
125− *
126− * and for negative values on the interval with
127− * minimum of -2147483648 (-10000000000000000000000000000000) and
128− * maximum of -1073741824 ( -1000000000000000000000000000000).
129− *
130− * in order to normalize the result, the following
131− * operation must be done: L_norm_var1 = L_var1 << norm( L_var1 );
132− *
133− * (That's 'ffs', only from the left, not the right..)
134− */
135−{
136− assert(a != 0);
137−
138− if (a < 0) {
139− if (a <= -1073741824) return 0;
140− a = ~a;
141− }
142−
143− return a & 0xffff0000
144− ? ( a & 0xff000000
145− ? -1 + bitoff[ 0xFF & (a >> 24) ]
146− : 7 + bitoff[ 0xFF & (a >> 16) ] )
147− : ( a & 0xff00
148− ? 15 + bitoff[ 0xFF & (a >> 8) ]
149− : 23 + bitoff[ 0xFF & a ] );
150−}
151−
152−longword gsm_L_asl (longword a, int n)
153−{
154− if (n >= 32) return 0;
155− if (n <= -32) return -(a < 0);
156− if (n < 0) return gsm_L_asr(a, -n);
157− return a << n;
158−}
159−
160−word gsm_asl (word a, int n)
161−{
162− if (n >= 16) return 0;
163− if (n <= -16) return -(a < 0);
164− if (n < 0) return gsm_asr(a, -n);
165− return a << n;
166−}
167−
168−longword gsm_L_asr (longword a, int n)
169−{
170− if (n >= 32) return -(a < 0);
171− if (n <= -32) return 0;
172− if (n < 0) return a << -n;
173−
174−# ifdef SASR
175− return a >> n;
176−# else
177− if (a >= 0) return a >> n;
178− else return -(longword)( -(ulongword)a >> n );
179−# endif
180−}
181−
182−word gsm_asr (word a, int n)
183−{
184− if (n >= 16) return -(a < 0);
185− if (n <= -16) return 0;
186− if (n < 0) return a << -n;
187−
188−# ifdef SASR
189− return a >> n;
190−# else
191− if (a >= 0) return a >> n;
192− else return -(word)( -(uword)a >> n );
193−# endif
194−}
195−
196−/*
197− * (From p. 46, end of section 4.2.5)
198− *
199− * NOTE: The following lines gives [sic] one correct implementation
200− * of the div(num, denum) arithmetic operation. Compute div
201− * which is the integer division of num by denum: with denum
202− * >= num > 0
203− */
204−
205−word gsm_div (word num, word denum)
206−{
207− longword L_num = num;
208− longword L_denum = denum;
209− word div = 0;
210− int k = 15;
211−
212− /* The parameter num sometimes becomes zero.
213− * Although this is explicitly guarded against in 4.2.5,
214− * we assume that the result should then be zero as well.
215− */
216−
217− /* assert(num != 0); */
218−
219− assert(num >= 0 && denum >= num);
220− if (num == 0)
221− return 0;
222−
223− while (k--) {
224− div <<= 1;
225− L_num <<= 1;
226−
227− if (L_num >= L_denum) {
228− L_num -= L_denum;
229− div++;
230− }
231− }
232−
233− return div;
234−}
libgsm/aliases.h+0−40
@@ -1,40 +0,0 @@
1−#define gsm_add lsx_gsm_add
2−#define gsm_sub lsx_gsm_sub
3−#define gsm_mult lsx_gsm_mult
4−#define gsm_mult_r lsx_gsm_mult_r
5−#define gsm_abs lsx_gsm_abs
6−#define gsm_L_mult lsx_gsm_L_mult
7−#define gsm_L_add lsx_gsm_L_add
8−#define gsm_L_sub lsx_gsm_L_sub
9−#define gsm_norm lsx_gsm_norm
10−#define gsm_L_asl lsx_gsm_L_asl
11−#define gsm_L_asr lsx_gsm_L_asr
12−#define gsm_asl lsx_gsm_asl
13−#define gsm_asr lsx_gsm_asr
14−#define gsm_div lsx_gsm_div
15−#define Gsm_Coder lsx_Gsm_Coder
16−#define Gsm_Decoder lsx_Gsm_Decoder
17−#define gsm_create lsx_gsm_create
18−#define gsm_decode lsx_gsm_decode
19−#define gsm_destroy lsx_gsm_destroy
20−#define gsm_encode lsx_gsm_encode
21−#define gsm_option lsx_gsm_option
22−#define Gsm_Long_Term_Predictor lsx_Gsm_Long_Term_Predictor
23−#define Gsm_Long_Term_Synthesis_Filtering lsx_Gsm_Long_Term_Synthesis_Filtering
24−#define Gsm_LPC_Analysis lsx_Gsm_LPC_Analysis
25−#define Gsm_Preprocess lsx_Gsm_Preprocess
26−#define Gsm_RPE_Encoding lsx_Gsm_RPE_Encoding
27−#define Gsm_RPE_Decoding lsx_Gsm_RPE_Decoding
28−#define Gsm_Short_Term_Analysis_Filter lsx_Gsm_Short_Term_Analysis_Filter
29−#define Gsm_Short_Term_Synthesis_Filter lsx_Gsm_Short_Term_Synthesis_Filter
30−#define gsm_A lsx_gsm_A
31−#define gsm_B lsx_gsm_B
32−#define gsm_MIC lsx_gsm_MIC
33−#define gsm_MAC lsx_gsm_MAC
34−#define gsm_INVA lsx_gsm_INVA
35−#define gsm_DLB lsx_gsm_DLB
36−#define gsm_QLB lsx_gsm_QLB
37−#define gsm_H lsx_gsm_H
38−#define gsm_NRFAC lsx_gsm_NRFAC
39−#define gsm_FAC lsx_gsm_FAC
40−
libgsm/code.c+0−91
@@ -1,91 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/code.c,v 1.1 2007/09/06 16:50:55 cbagwell Exp $ */
8−
9−#include <stdlib.h>
10−#include <string.h>
11−
12−#include "private.h"
13−#include "gsm.h"
14−
15−/*
16− * 4.2 FIXED POINT IMPLEMENTATION OF THE RPE-LTP CODER
17− */
18−
19−void Gsm_Coder (
20−
21− struct gsm_state * S,
22−
23− word * s, /* [0..159] samples IN */
24−
25−/*
26− * The RPE-LTD coder works on a frame by frame basis. The length of
27− * the frame is equal to 160 samples. Some computations are done
28− * once per frame to produce at the output of the coder the
29− * LARc[1..8] parameters which are the coded LAR coefficients and
30− * also to realize the inverse filtering operation for the entire
31− * frame (160 samples of signal d[0..159]). These parts produce at
32− * the output of the coder:
33− */
34−
35− word * LARc, /* [0..7] LAR coefficients OUT */
36−
37−/*
38− * Procedure 4.2.11 to 4.2.18 are to be executed four times per
39− * frame. That means once for each sub-segment RPE-LTP analysis of
40− * 40 samples. These parts produce at the output of the coder:
41− */
42−
43− word * Nc, /* [0..3] LTP lag OUT */
44− word * bc, /* [0..3] coded LTP gain OUT */
45− word * Mc, /* [0..3] RPE grid selection OUT */
46− word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
47− word * xMc /* [13*4] normalized RPE samples OUT */
48−)
49−{
50− int k;
51− word * dp = S->dp0 + 120; /* [ -120...-1 ] */
52− word * dpp = dp; /* [ 0...39 ] */
53−
54− static word e[50];
55−
56− word so[160];
57−
58− Gsm_Preprocess (S, s, so);
59− Gsm_LPC_Analysis (S, so, LARc);
60− Gsm_Short_Term_Analysis_Filter (S, LARc, so);
61−
62− for (k = 0; k <= 3; k++, xMc += 13) {
63−
64− Gsm_Long_Term_Predictor ( S,
65− so+k*40, /* d [0..39] IN */
66− dp, /* dp [-120..-1] IN */
67− e + 5, /* e [0..39] OUT */
68− dpp, /* dpp [0..39] OUT */
69− Nc++,
70− bc++);
71−
72− Gsm_RPE_Encoding ( S,
73− e + 5, /* e ][0..39][ IN/OUT */
74− xmaxc++, Mc++, xMc );
75− /*
76− * Gsm_Update_of_reconstructed_short_time_residual_signal
77− * ( dpp, e + 5, dp );
78− */
79−
80− { register int i;
81− register longword ltmp;
82− for (i = 0; i <= 39; i++)
83− dp[ i ] = GSM_ADD( e[5 + i], dpp[i] );
84− }
85− dp += 40;
86− dpp += 40;
87−
88− }
89− (void)memcpy( (char *)S->dp0, (char *)(S->dp0 + 160),
90− 120 * sizeof(*S->dp0) );
91−}
libgsm/decode.c+0−62
@@ -1,62 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/decode.c,v 1.1 2007/09/06 16:50:55 cbagwell Exp $ */
8−
9−#include <stdio.h>
10−
11−#include "private.h"
12−#include "gsm.h"
13−
14−/*
15− * 4.3 FIXED POINT IMPLEMENTATION OF THE RPE-LTP DECODER
16− */
17−
18−static void Postprocessing (
19− struct gsm_state * S,
20− register word * s)
21−{
22− register int k;
23− register word msr = S->msr;
24− register longword ltmp; /* for GSM_ADD */
25− register word tmp;
26−
27− for (k = 160; k--; s++) {
28− tmp = GSM_MULT_R( msr, 28180 );
29− msr = GSM_ADD(*s, tmp); /* Deemphasis */
30− *s = GSM_ADD(msr, msr) & 0xFFF8; /* Truncation & Upscaling */
31− }
32− S->msr = msr;
33−}
34−
35−void Gsm_Decoder (
36− struct gsm_state * S,
37−
38− word * LARcr, /* [0..7] IN */
39−
40− word * Ncr, /* [0..3] IN */
41− word * bcr, /* [0..3] IN */
42− word * Mcr, /* [0..3] IN */
43− word * xmaxcr, /* [0..3] IN */
44− word * xMcr, /* [0..13*4] IN */
45−
46− word * s) /* [0..159] OUT */
47−{
48− int j, k;
49− word erp[40], wt[160];
50− word * drp = S->dp0 + 120;
51−
52− for (j=0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) {
53−
54− Gsm_RPE_Decoding( S, *xmaxcr, *Mcr, xMcr, erp );
55− Gsm_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp );
56−
57− for (k = 0; k <= 39; k++) wt[ j * 40 + k ] = drp[ k ];
58− }
59−
60− Gsm_Short_Term_Synthesis_Filter( S, LARcr, wt, s );
61− Postprocessing(S, s);
62−}
libgsm/gsm.3+0−105
@@ -1,105 +0,0 @@
1−.\"
2−.\" Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3−.\" Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4−.\" details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5−.\"
6−.PU
7−.TH GSM 3
8−.SH NAME
9−gsm_create, gsm_destroy, gsm_encode, gsm_decode \(em GSM\ 06.10 lossy sound compression
10−.SH SYNOPSIS
11−.PP
12−#include "gsm.h"
13−.PP
14−gsm gsm_create();
15−.PP
16−void gsm_encode(handle, src, dst)
17−.br
18−gsm handle;
19−.br
20−gsm_signal src[160];
21−.br
22−gsm_frame dst;
23−.PP
24−int gsm_decode(handle, src, dst)
25−.br
26−gsm handle;
27−.br
28−gsm_frame src;
29−.br
30−gsm_signal dst[160];
31−.PP
32−void gsm_destroy(handle)
33−.br
34−gsm handle;
35−.br
36−.SH "DESCRIPTION"
37−Gsm is an implementation of the final draft GSM 06.10
38−standard for full-rate speech transcoding.
39−.PP
40−gsm_create() initializes a gsm pass and returns a 'gsm' object
41−which can be used as a handle in subsequent calls to gsm_decode(),
42−gsm_encode() or gsm_destroy().
43−.PP
44−gsm_encode() encodes an array of 160 13-bit samples (given as
45−gsm_signal's, signed integral values of at least 16 bits) into
46−a gsm_frame of 33 bytes.
47−(gsm_frame is a type defined as an array of 33 gsm_bytes in gsm.h.)
48−.PP
49−gsm_decode() decodes a gsm_frame into an array of 160 13-bit samples
50−(given as gsm_signals), which sound rather like what you handed to
51−gsm_encode() on the other side of the wire.
52−.PP
53−gsm_destroy() finishes a gsm pass and frees all storage associated
54−with it.
55−.SS "Sample format"
56−The following scaling is assumed for input to the algorithm:
57−.br
58−.nf
59− 0 1 11 12
60− S..v..v..v..v..v..v..v..v..v..v..v..v..*..*..*
61−.nf
62−.br
63−Only the top 13 bits are used as a signed input value.
64−The output of gsm_decode() has the three lower bits set to zero.
65−.\" .SH OPTIONS
66−.SH "RETURN VALUE"
67−gsm_create() returns an opaque handle object of type gsm, or 0 on error.
68−gsm_decode() returns -1 if the passed frame is invalid, else 0.
69−.SH EXAMPLE
70−.nf
71−#include "gsm.h"
72−
73−gsm handle;
74−gsm_frame buf;
75−gsm_signal sample[160];
76−int cc, soundfd;
77−
78−play() { /* read compressed data from standard input, write to soundfd */
79−
80− if (!(handle = gsm_create())) error...
81− while (cc = read(0, (char *)buf, sizeof buf)) {
82− if (cc != sizeof buf) error...
83− if (gsm_decode(handle, buf, sample) < 0) error...
84− if (write(soundfd, sample, sizeof sample) != sizeof sample)
85− error...
86− }
87− gsm_destroy(handle);
88−}
89−
90−record() { /* read from soundfd, write compressed to standard output */
91−
92− if (!(handle = gsm_create())) error...
93− while (cc = read(soundfd, sample, sizeof sample)) {
94− if (cc != sizeof sample) error...
95− gsm_encode(handle, sample, buf);
96− if (write(1, (char *)buf, sizeof buf) != sizeof sample)
97− error...
98− }
99− gsm_destroy(handle);
100−}
101−.nf
102−.SH BUGS
103−Please direct bug reports to jutta@cs.tu-berlin.de and cabo@cs.tu-berlin.de.
104−.SH "SEE ALSO"
105−toast(1), gsm_print(3), gsm_explode(3), gsm_option(3)
libgsm/gsm.h+0−69
@@ -1,69 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/*$Header: /cvsroot/sox/sox/libgsm/gsm.h,v 1.2 2008/03/21 13:34:21 robs Exp $*/
8−
9−#ifndef GSM_H
10−#define GSM_H
11−
12−#include "aliases.h"
13−
14−#ifdef __cplusplus
15−# define NeedFunctionPrototypes 1
16−#endif
17−
18−#if __STDC__
19−# define NeedFunctionPrototypes 1
20−#endif
21−
22−#ifdef _NO_PROTO
23−# undef NeedFunctionPrototypes
24−#endif
25−
26−#ifdef NeedFunctionPrototypes
27−# include <stdio.h> /* for FILE * */
28−#endif
29−
30−#undef GSM_P
31−#if NeedFunctionPrototypes
32−# define GSM_P( protos ) protos
33−#else
34−# define GSM_P( protos ) ( /* protos */ )
35−#endif
36−
37−/*
38− * Interface
39− */
40−
41−typedef struct gsm_state * gsm;
42−typedef short gsm_signal; /* signed 16 bit */
43−typedef unsigned char gsm_byte;
44−typedef gsm_byte gsm_frame[33]; /* 33 * 8 bits */
45−
46−#define GSM_MAGIC 0xD /* 13 kbit/s RPE-LTP */
47−
48−#define GSM_PATCHLEVEL 10
49−#define GSM_MINOR 0
50−#define GSM_MAJOR 1
51−
52−#define GSM_OPT_VERBOSE 1
53−#define GSM_OPT_FAST 2
54−#define GSM_OPT_LTP_CUT 3
55−#define GSM_OPT_WAV49 4
56−#define GSM_OPT_FRAME_INDEX 5
57−#define GSM_OPT_FRAME_CHAIN 6
58−
59−extern gsm gsm_create GSM_P((void));
60−extern void gsm_destroy GSM_P((gsm));
61−
62−extern int gsm_option GSM_P((gsm, int, int *));
63−
64−extern void gsm_encode GSM_P((gsm, gsm_signal *, gsm_byte *));
65−extern int gsm_decode GSM_P((gsm, gsm_byte *, gsm_signal *));
66−
67−#undef GSM_P
68−
69−#endif /* GSM_H */
libgsm/gsm_create.c+0−27
@@ -1,27 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−static char const ident[] = "$Header: /cvsroot/sox/sox/libgsm/gsm_create.c,v 1.1 2007/09/06 16:50:55 cbagwell Exp $";
8−
9−#include <string.h>
10−#include <stdlib.h>
11−#include <stdio.h>
12−
13−#include "gsm.h"
14−#include "private.h"
15−
16−gsm gsm_create ()
17−{
18− gsm r;
19−
20− r = (gsm)malloc(sizeof(struct gsm_state));
21− if (!r) return r;
22−
23− memset((char *)r, 0, sizeof(*r));
24− r->nrp = 40;
25−
26− return r;
27−}
libgsm/gsm_decode.c+0−360
@@ -1,360 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/gsm_decode.c,v 1.1 2007/09/06 16:50:55 cbagwell Exp $ */
8−
9−#include "private.h"
10−
11−#include "gsm.h"
12−
13−int gsm_decode (gsm s, gsm_byte * c, gsm_signal * target)
14−{
15− word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
16−
17−#ifdef WAV49
18− if (s->wav_fmt) {
19−
20− uword sr = 0;
21−
22− s->frame_index = !s->frame_index;
23− if (s->frame_index) {
24−
25− sr = *c++;
26− LARc[0] = sr & 0x3f; sr >>= 6;
27− sr |= (uword)*c++ << 2;
28− LARc[1] = sr & 0x3f; sr >>= 6;
29− sr |= (uword)*c++ << 4;
30− LARc[2] = sr & 0x1f; sr >>= 5;
31− LARc[3] = sr & 0x1f; sr >>= 5;
32− sr |= (uword)*c++ << 2;
33− LARc[4] = sr & 0xf; sr >>= 4;
34− LARc[5] = sr & 0xf; sr >>= 4;
35− sr |= (uword)*c++ << 2; /* 5 */
36− LARc[6] = sr & 0x7; sr >>= 3;
37− LARc[7] = sr & 0x7; sr >>= 3;
38− sr |= (uword)*c++ << 4;
39− Nc[0] = sr & 0x7f; sr >>= 7;
40− bc[0] = sr & 0x3; sr >>= 2;
41− Mc[0] = sr & 0x3; sr >>= 2;
42− sr |= (uword)*c++ << 1;
43− xmaxc[0] = sr & 0x3f; sr >>= 6;
44− xmc[0] = sr & 0x7; sr >>= 3;
45− sr = *c++;
46− xmc[1] = sr & 0x7; sr >>= 3;
47− xmc[2] = sr & 0x7; sr >>= 3;
48− sr |= (uword)*c++ << 2;
49− xmc[3] = sr & 0x7; sr >>= 3;
50− xmc[4] = sr & 0x7; sr >>= 3;
51− xmc[5] = sr & 0x7; sr >>= 3;
52− sr |= (uword)*c++ << 1; /* 10 */
53− xmc[6] = sr & 0x7; sr >>= 3;
54− xmc[7] = sr & 0x7; sr >>= 3;
55− xmc[8] = sr & 0x7; sr >>= 3;
56− sr = *c++;
57− xmc[9] = sr & 0x7; sr >>= 3;
58− xmc[10] = sr & 0x7; sr >>= 3;
59− sr |= (uword)*c++ << 2;
60− xmc[11] = sr & 0x7; sr >>= 3;
61− xmc[12] = sr & 0x7; sr >>= 3;
62− sr |= (uword)*c++ << 4;
63− Nc[1] = sr & 0x7f; sr >>= 7;
64− bc[1] = sr & 0x3; sr >>= 2;
65− Mc[1] = sr & 0x3; sr >>= 2;
66− sr |= (uword)*c++ << 1;
67− xmaxc[1] = sr & 0x3f; sr >>= 6;
68− xmc[13] = sr & 0x7; sr >>= 3;
69− sr = *c++; /* 15 */
70− xmc[14] = sr & 0x7; sr >>= 3;
71− xmc[15] = sr & 0x7; sr >>= 3;
72− sr |= (uword)*c++ << 2;
73− xmc[16] = sr & 0x7; sr >>= 3;
74− xmc[17] = sr & 0x7; sr >>= 3;
75− xmc[18] = sr & 0x7; sr >>= 3;
76− sr |= (uword)*c++ << 1;
77− xmc[19] = sr & 0x7; sr >>= 3;
78− xmc[20] = sr & 0x7; sr >>= 3;
79− xmc[21] = sr & 0x7; sr >>= 3;
80− sr = *c++;
81− xmc[22] = sr & 0x7; sr >>= 3;
82− xmc[23] = sr & 0x7; sr >>= 3;
83− sr |= (uword)*c++ << 2;
84− xmc[24] = sr & 0x7; sr >>= 3;
85− xmc[25] = sr & 0x7; sr >>= 3;
86− sr |= (uword)*c++ << 4; /* 20 */
87− Nc[2] = sr & 0x7f; sr >>= 7;
88− bc[2] = sr & 0x3; sr >>= 2;
89− Mc[2] = sr & 0x3; sr >>= 2;
90− sr |= (uword)*c++ << 1;
91− xmaxc[2] = sr & 0x3f; sr >>= 6;
92− xmc[26] = sr & 0x7; sr >>= 3;
93− sr = *c++;
94− xmc[27] = sr & 0x7; sr >>= 3;
95− xmc[28] = sr & 0x7; sr >>= 3;
96− sr |= (uword)*c++ << 2;
97− xmc[29] = sr & 0x7; sr >>= 3;
98− xmc[30] = sr & 0x7; sr >>= 3;
99− xmc[31] = sr & 0x7; sr >>= 3;
100− sr |= (uword)*c++ << 1;
101− xmc[32] = sr & 0x7; sr >>= 3;
102− xmc[33] = sr & 0x7; sr >>= 3;
103− xmc[34] = sr & 0x7; sr >>= 3;
104− sr = *c++; /* 25 */
105− xmc[35] = sr & 0x7; sr >>= 3;
106− xmc[36] = sr & 0x7; sr >>= 3;
107− sr |= (uword)*c++ << 2;
108− xmc[37] = sr & 0x7; sr >>= 3;
109− xmc[38] = sr & 0x7; sr >>= 3;
110− sr |= (uword)*c++ << 4;
111− Nc[3] = sr & 0x7f; sr >>= 7;
112− bc[3] = sr & 0x3; sr >>= 2;
113− Mc[3] = sr & 0x3; sr >>= 2;
114− sr |= (uword)*c++ << 1;
115− xmaxc[3] = sr & 0x3f; sr >>= 6;
116− xmc[39] = sr & 0x7; sr >>= 3;
117− sr = *c++;
118− xmc[40] = sr & 0x7; sr >>= 3;
119− xmc[41] = sr & 0x7; sr >>= 3;
120− sr |= (uword)*c++ << 2; /* 30 */
121− xmc[42] = sr & 0x7; sr >>= 3;
122− xmc[43] = sr & 0x7; sr >>= 3;
123− xmc[44] = sr & 0x7; sr >>= 3;
124− sr |= (uword)*c++ << 1;
125− xmc[45] = sr & 0x7; sr >>= 3;
126− xmc[46] = sr & 0x7; sr >>= 3;
127− xmc[47] = sr & 0x7; sr >>= 3;
128− sr = *c++;
129− xmc[48] = sr & 0x7; sr >>= 3;
130− xmc[49] = sr & 0x7; sr >>= 3;
131− sr |= (uword)*c++ << 2;
132− xmc[50] = sr & 0x7; sr >>= 3;
133− xmc[51] = sr & 0x7; sr >>= 3;
134−
135− s->frame_chain = sr & 0xf;
136− }
137− else {
138− sr = s->frame_chain;
139− sr |= (uword)*c++ << 4; /* 1 */
140− LARc[0] = sr & 0x3f; sr >>= 6;
141− LARc[1] = sr & 0x3f; sr >>= 6;
142− sr = *c++;
143− LARc[2] = sr & 0x1f; sr >>= 5;
144− sr |= (uword)*c++ << 3;
145− LARc[3] = sr & 0x1f; sr >>= 5;
146− LARc[4] = sr & 0xf; sr >>= 4;
147− sr |= (uword)*c++ << 2;
148− LARc[5] = sr & 0xf; sr >>= 4;
149− LARc[6] = sr & 0x7; sr >>= 3;
150− LARc[7] = sr & 0x7; sr >>= 3;
151− sr = *c++; /* 5 */
152− Nc[0] = sr & 0x7f; sr >>= 7;
153− sr |= (uword)*c++ << 1;
154− bc[0] = sr & 0x3; sr >>= 2;
155− Mc[0] = sr & 0x3; sr >>= 2;
156− sr |= (uword)*c++ << 5;
157− xmaxc[0] = sr & 0x3f; sr >>= 6;
158− xmc[0] = sr & 0x7; sr >>= 3;
159− xmc[1] = sr & 0x7; sr >>= 3;
160− sr |= (uword)*c++ << 1;
161− xmc[2] = sr & 0x7; sr >>= 3;
162− xmc[3] = sr & 0x7; sr >>= 3;
163− xmc[4] = sr & 0x7; sr >>= 3;
164− sr = *c++;
165− xmc[5] = sr & 0x7; sr >>= 3;
166− xmc[6] = sr & 0x7; sr >>= 3;
167− sr |= (uword)*c++ << 2; /* 10 */
168− xmc[7] = sr & 0x7; sr >>= 3;
169− xmc[8] = sr & 0x7; sr >>= 3;
170− xmc[9] = sr & 0x7; sr >>= 3;
171− sr |= (uword)*c++ << 1;
172− xmc[10] = sr & 0x7; sr >>= 3;
173− xmc[11] = sr & 0x7; sr >>= 3;
174− xmc[12] = sr & 0x7; sr >>= 3;
175− sr = *c++;
176− Nc[1] = sr & 0x7f; sr >>= 7;
177− sr |= (uword)*c++ << 1;
178− bc[1] = sr & 0x3; sr >>= 2;
179− Mc[1] = sr & 0x3; sr >>= 2;
180− sr |= (uword)*c++ << 5;
181− xmaxc[1] = sr & 0x3f; sr >>= 6;
182− xmc[13] = sr & 0x7; sr >>= 3;
183− xmc[14] = sr & 0x7; sr >>= 3;
184− sr |= (uword)*c++ << 1; /* 15 */
185− xmc[15] = sr & 0x7; sr >>= 3;
186− xmc[16] = sr & 0x7; sr >>= 3;
187− xmc[17] = sr & 0x7; sr >>= 3;
188− sr = *c++;
189− xmc[18] = sr & 0x7; sr >>= 3;
190− xmc[19] = sr & 0x7; sr >>= 3;
191− sr |= (uword)*c++ << 2;
192− xmc[20] = sr & 0x7; sr >>= 3;
193− xmc[21] = sr & 0x7; sr >>= 3;
194− xmc[22] = sr & 0x7; sr >>= 3;
195− sr |= (uword)*c++ << 1;
196− xmc[23] = sr & 0x7; sr >>= 3;
197− xmc[24] = sr & 0x7; sr >>= 3;
198− xmc[25] = sr & 0x7; sr >>= 3;
199− sr = *c++;
200− Nc[2] = sr & 0x7f; sr >>= 7;
201− sr |= (uword)*c++ << 1; /* 20 */
202− bc[2] = sr & 0x3; sr >>= 2;
203− Mc[2] = sr & 0x3; sr >>= 2;
204− sr |= (uword)*c++ << 5;
205− xmaxc[2] = sr & 0x3f; sr >>= 6;
206− xmc[26] = sr & 0x7; sr >>= 3;
207− xmc[27] = sr & 0x7; sr >>= 3;
208− sr |= (uword)*c++ << 1;
209− xmc[28] = sr & 0x7; sr >>= 3;
210− xmc[29] = sr & 0x7; sr >>= 3;
211− xmc[30] = sr & 0x7; sr >>= 3;
212− sr = *c++;
213− xmc[31] = sr & 0x7; sr >>= 3;
214− xmc[32] = sr & 0x7; sr >>= 3;
215− sr |= (uword)*c++ << 2;
216− xmc[33] = sr & 0x7; sr >>= 3;
217− xmc[34] = sr & 0x7; sr >>= 3;
218− xmc[35] = sr & 0x7; sr >>= 3;
219− sr |= (uword)*c++ << 1; /* 25 */
220− xmc[36] = sr & 0x7; sr >>= 3;
221− xmc[37] = sr & 0x7; sr >>= 3;
222− xmc[38] = sr & 0x7; sr >>= 3;
223− sr = *c++;
224− Nc[3] = sr & 0x7f; sr >>= 7;
225− sr |= (uword)*c++ << 1;
226− bc[3] = sr & 0x3; sr >>= 2;
227− Mc[3] = sr & 0x3; sr >>= 2;
228− sr |= (uword)*c++ << 5;
229− xmaxc[3] = sr & 0x3f; sr >>= 6;
230− xmc[39] = sr & 0x7; sr >>= 3;
231− xmc[40] = sr & 0x7; sr >>= 3;
232− sr |= (uword)*c++ << 1;
233− xmc[41] = sr & 0x7; sr >>= 3;
234− xmc[42] = sr & 0x7; sr >>= 3;
235− xmc[43] = sr & 0x7; sr >>= 3;
236− sr = *c++; /* 30 */
237− xmc[44] = sr & 0x7; sr >>= 3;
238− xmc[45] = sr & 0x7; sr >>= 3;
239− sr |= (uword)*c++ << 2;
240− xmc[46] = sr & 0x7; sr >>= 3;
241− xmc[47] = sr & 0x7; sr >>= 3;
242− xmc[48] = sr & 0x7; sr >>= 3;
243− sr |= (uword)*c++ << 1;
244− xmc[49] = sr & 0x7; sr >>= 3;
245− xmc[50] = sr & 0x7; sr >>= 3;
246− xmc[51] = sr & 0x7; sr >>= 3;
247− }
248− }
249− else
250−#endif
251− {
252− /* GSM_MAGIC = (*c >> 4) & 0xF; */
253−
254− if (((*c >> 4) & 0x0F) != GSM_MAGIC) return -1;
255−
256− LARc[0] = (*c++ & 0xF) << 2; /* 1 */
257− LARc[0] |= (*c >> 6) & 0x3;
258− LARc[1] = *c++ & 0x3F;
259− LARc[2] = (*c >> 3) & 0x1F;
260− LARc[3] = (*c++ & 0x7) << 2;
261− LARc[3] |= (*c >> 6) & 0x3;
262− LARc[4] = (*c >> 2) & 0xF;
263− LARc[5] = (*c++ & 0x3) << 2;
264− LARc[5] |= (*c >> 6) & 0x3;
265− LARc[6] = (*c >> 3) & 0x7;
266− LARc[7] = *c++ & 0x7;
267− Nc[0] = (*c >> 1) & 0x7F;
268− bc[0] = (*c++ & 0x1) << 1;
269− bc[0] |= (*c >> 7) & 0x1;
270− Mc[0] = (*c >> 5) & 0x3;
271− xmaxc[0] = (*c++ & 0x1F) << 1;
272− xmaxc[0] |= (*c >> 7) & 0x1;
273− xmc[0] = (*c >> 4) & 0x7;
274− xmc[1] = (*c >> 1) & 0x7;
275− xmc[2] = (*c++ & 0x1) << 2;
276− xmc[2] |= (*c >> 6) & 0x3;
277− xmc[3] = (*c >> 3) & 0x7;
278− xmc[4] = *c++ & 0x7;
279− xmc[5] = (*c >> 5) & 0x7;
280− xmc[6] = (*c >> 2) & 0x7;
281− xmc[7] = (*c++ & 0x3) << 1; /* 10 */
282− xmc[7] |= (*c >> 7) & 0x1;
283− xmc[8] = (*c >> 4) & 0x7;
284− xmc[9] = (*c >> 1) & 0x7;
285− xmc[10] = (*c++ & 0x1) << 2;
286− xmc[10] |= (*c >> 6) & 0x3;
287− xmc[11] = (*c >> 3) & 0x7;
288− xmc[12] = *c++ & 0x7;
289− Nc[1] = (*c >> 1) & 0x7F;
290− bc[1] = (*c++ & 0x1) << 1;
291− bc[1] |= (*c >> 7) & 0x1;
292− Mc[1] = (*c >> 5) & 0x3;
293− xmaxc[1] = (*c++ & 0x1F) << 1;
294− xmaxc[1] |= (*c >> 7) & 0x1;
295− xmc[13] = (*c >> 4) & 0x7;
296− xmc[14] = (*c >> 1) & 0x7;
297− xmc[15] = (*c++ & 0x1) << 2;
298− xmc[15] |= (*c >> 6) & 0x3;
299− xmc[16] = (*c >> 3) & 0x7;
300− xmc[17] = *c++ & 0x7;
301− xmc[18] = (*c >> 5) & 0x7;
302− xmc[19] = (*c >> 2) & 0x7;
303− xmc[20] = (*c++ & 0x3) << 1;
304− xmc[20] |= (*c >> 7) & 0x1;
305− xmc[21] = (*c >> 4) & 0x7;
306− xmc[22] = (*c >> 1) & 0x7;
307− xmc[23] = (*c++ & 0x1) << 2;
308− xmc[23] |= (*c >> 6) & 0x3;
309− xmc[24] = (*c >> 3) & 0x7;
310− xmc[25] = *c++ & 0x7;
311− Nc[2] = (*c >> 1) & 0x7F;
312− bc[2] = (*c++ & 0x1) << 1; /* 20 */
313− bc[2] |= (*c >> 7) & 0x1;
314− Mc[2] = (*c >> 5) & 0x3;
315− xmaxc[2] = (*c++ & 0x1F) << 1;
316− xmaxc[2] |= (*c >> 7) & 0x1;
317− xmc[26] = (*c >> 4) & 0x7;
318− xmc[27] = (*c >> 1) & 0x7;
319− xmc[28] = (*c++ & 0x1) << 2;
320− xmc[28] |= (*c >> 6) & 0x3;
321− xmc[29] = (*c >> 3) & 0x7;
322− xmc[30] = *c++ & 0x7;
323− xmc[31] = (*c >> 5) & 0x7;
324− xmc[32] = (*c >> 2) & 0x7;
325− xmc[33] = (*c++ & 0x3) << 1;
326− xmc[33] |= (*c >> 7) & 0x1;
327− xmc[34] = (*c >> 4) & 0x7;
328− xmc[35] = (*c >> 1) & 0x7;
329− xmc[36] = (*c++ & 0x1) << 2;
330− xmc[36] |= (*c >> 6) & 0x3;
331− xmc[37] = (*c >> 3) & 0x7;
332− xmc[38] = *c++ & 0x7;
333− Nc[3] = (*c >> 1) & 0x7F;
334− bc[3] = (*c++ & 0x1) << 1;
335− bc[3] |= (*c >> 7) & 0x1;
336− Mc[3] = (*c >> 5) & 0x3;
337− xmaxc[3] = (*c++ & 0x1F) << 1;
338− xmaxc[3] |= (*c >> 7) & 0x1;
339− xmc[39] = (*c >> 4) & 0x7;
340− xmc[40] = (*c >> 1) & 0x7;
341− xmc[41] = (*c++ & 0x1) << 2;
342− xmc[41] |= (*c >> 6) & 0x3;
343− xmc[42] = (*c >> 3) & 0x7;
344− xmc[43] = *c++ & 0x7; /* 30 */
345− xmc[44] = (*c >> 5) & 0x7;
346− xmc[45] = (*c >> 2) & 0x7;
347− xmc[46] = (*c++ & 0x3) << 1;
348− xmc[46] |= (*c >> 7) & 0x1;
349− xmc[47] = (*c >> 4) & 0x7;
350− xmc[48] = (*c >> 1) & 0x7;
351− xmc[49] = (*c++ & 0x1) << 2;
352− xmc[49] |= (*c >> 6) & 0x3;
353− xmc[50] = (*c >> 3) & 0x7;
354− xmc[51] = *c & 0x7; /* 33 */
355− }
356−
357− Gsm_Decoder(s, LARc, Nc, bc, Mc, xmaxc, xmc, target);
358−
359− return 0;
360−}
libgsm/gsm_destroy.c+0−16
@@ -1,16 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/gsm_destroy.c,v 1.1 2007/09/06 16:50:55 cbagwell Exp $ */
8−
9−#include "gsm.h"
10−
11−# include <stdlib.h>
12−
13−void gsm_destroy (gsm S)
14−{
15− if (S) free((char *)S);
16−}
libgsm/gsm_encode.c+0−450
@@ -1,450 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/gsm_encode.c,v 1.1 2007/09/06 16:50:55 cbagwell Exp $ */
8−
9−#include "private.h"
10−#include "gsm.h"
11−
12−void gsm_encode (gsm s, gsm_signal * source, gsm_byte * c)
13−{
14− word LARc[8], Nc[4], Mc[4], bc[4], xmaxc[4], xmc[13*4];
15−
16− Gsm_Coder(s, source, LARc, Nc, bc, Mc, xmaxc, xmc);
17−
18−
19− /* variable size
20−
21− GSM_MAGIC 4
22−
23− LARc[0] 6
24− LARc[1] 6
25− LARc[2] 5
26− LARc[3] 5
27− LARc[4] 4
28− LARc[5] 4
29− LARc[6] 3
30− LARc[7] 3
31−
32− Nc[0] 7
33− bc[0] 2
34− Mc[0] 2
35− xmaxc[0] 6
36− xmc[0] 3
37− xmc[1] 3
38− xmc[2] 3
39− xmc[3] 3
40− xmc[4] 3
41− xmc[5] 3
42− xmc[6] 3
43− xmc[7] 3
44− xmc[8] 3
45− xmc[9] 3
46− xmc[10] 3
47− xmc[11] 3
48− xmc[12] 3
49−
50− Nc[1] 7
51− bc[1] 2
52− Mc[1] 2
53− xmaxc[1] 6
54− xmc[13] 3
55− xmc[14] 3
56− xmc[15] 3
57− xmc[16] 3
58− xmc[17] 3
59− xmc[18] 3
60− xmc[19] 3
61− xmc[20] 3
62− xmc[21] 3
63− xmc[22] 3
64− xmc[23] 3
65− xmc[24] 3
66− xmc[25] 3
67−
68− Nc[2] 7
69− bc[2] 2
70− Mc[2] 2
71− xmaxc[2] 6
72− xmc[26] 3
73− xmc[27] 3
74− xmc[28] 3
75− xmc[29] 3
76− xmc[30] 3
77− xmc[31] 3
78− xmc[32] 3
79− xmc[33] 3
80− xmc[34] 3
81− xmc[35] 3
82− xmc[36] 3
83− xmc[37] 3
84− xmc[38] 3
85−
86− Nc[3] 7
87− bc[3] 2
88− Mc[3] 2
89− xmaxc[3] 6
90− xmc[39] 3
91− xmc[40] 3
92− xmc[41] 3
93− xmc[42] 3
94− xmc[43] 3
95− xmc[44] 3
96− xmc[45] 3
97− xmc[46] 3
98− xmc[47] 3
99− xmc[48] 3
100− xmc[49] 3
101− xmc[50] 3
102− xmc[51] 3
103− */
104−
105−#ifdef WAV49
106−
107− if (s->wav_fmt) {
108− s->frame_index = !s->frame_index;
109− if (s->frame_index) {
110−
111− uword sr;
112−
113− sr = 0;
114− sr = sr >> 6 | LARc[0] << 10;
115− sr = sr >> 6 | LARc[1] << 10;
116− *c++ = sr >> 4;
117− sr = sr >> 5 | LARc[2] << 11;
118− *c++ = sr >> 7;
119− sr = sr >> 5 | LARc[3] << 11;
120− sr = sr >> 4 | LARc[4] << 12;
121− *c++ = sr >> 6;
122− sr = sr >> 4 | LARc[5] << 12;
123− sr = sr >> 3 | LARc[6] << 13;
124− *c++ = sr >> 7;
125− sr = sr >> 3 | LARc[7] << 13;
126− sr = sr >> 7 | Nc[0] << 9;
127− *c++ = sr >> 5;
128− sr = sr >> 2 | bc[0] << 14;
129− sr = sr >> 2 | Mc[0] << 14;
130− sr = sr >> 6 | xmaxc[0] << 10;
131− *c++ = sr >> 3;
132− sr = sr >> 3 | xmc[0] << 13;
133− *c++ = sr >> 8;
134− sr = sr >> 3 | xmc[1] << 13;
135− sr = sr >> 3 | xmc[2] << 13;
136− sr = sr >> 3 | xmc[3] << 13;
137− *c++ = sr >> 7;
138− sr = sr >> 3 | xmc[4] << 13;
139− sr = sr >> 3 | xmc[5] << 13;
140− sr = sr >> 3 | xmc[6] << 13;
141− *c++ = sr >> 6;
142− sr = sr >> 3 | xmc[7] << 13;
143− sr = sr >> 3 | xmc[8] << 13;
144− *c++ = sr >> 8;
145− sr = sr >> 3 | xmc[9] << 13;
146− sr = sr >> 3 | xmc[10] << 13;
147− sr = sr >> 3 | xmc[11] << 13;
148− *c++ = sr >> 7;
149− sr = sr >> 3 | xmc[12] << 13;
150− sr = sr >> 7 | Nc[1] << 9;
151− *c++ = sr >> 5;
152− sr = sr >> 2 | bc[1] << 14;
153− sr = sr >> 2 | Mc[1] << 14;
154− sr = sr >> 6 | xmaxc[1] << 10;
155− *c++ = sr >> 3;
156− sr = sr >> 3 | xmc[13] << 13;
157− *c++ = sr >> 8;
158− sr = sr >> 3 | xmc[14] << 13;
159− sr = sr >> 3 | xmc[15] << 13;
160− sr = sr >> 3 | xmc[16] << 13;
161− *c++ = sr >> 7;
162− sr = sr >> 3 | xmc[17] << 13;
163− sr = sr >> 3 | xmc[18] << 13;
164− sr = sr >> 3 | xmc[19] << 13;
165− *c++ = sr >> 6;
166− sr = sr >> 3 | xmc[20] << 13;
167− sr = sr >> 3 | xmc[21] << 13;
168− *c++ = sr >> 8;
169− sr = sr >> 3 | xmc[22] << 13;
170− sr = sr >> 3 | xmc[23] << 13;
171− sr = sr >> 3 | xmc[24] << 13;
172− *c++ = sr >> 7;
173− sr = sr >> 3 | xmc[25] << 13;
174− sr = sr >> 7 | Nc[2] << 9;
175− *c++ = sr >> 5;
176− sr = sr >> 2 | bc[2] << 14;
177− sr = sr >> 2 | Mc[2] << 14;
178− sr = sr >> 6 | xmaxc[2] << 10;
179− *c++ = sr >> 3;
180− sr = sr >> 3 | xmc[26] << 13;
181− *c++ = sr >> 8;
182− sr = sr >> 3 | xmc[27] << 13;
183− sr = sr >> 3 | xmc[28] << 13;
184− sr = sr >> 3 | xmc[29] << 13;
185− *c++ = sr >> 7;
186− sr = sr >> 3 | xmc[30] << 13;
187− sr = sr >> 3 | xmc[31] << 13;
188− sr = sr >> 3 | xmc[32] << 13;
189− *c++ = sr >> 6;
190− sr = sr >> 3 | xmc[33] << 13;
191− sr = sr >> 3 | xmc[34] << 13;
192− *c++ = sr >> 8;
193− sr = sr >> 3 | xmc[35] << 13;
194− sr = sr >> 3 | xmc[36] << 13;
195− sr = sr >> 3 | xmc[37] << 13;
196− *c++ = sr >> 7;
197− sr = sr >> 3 | xmc[38] << 13;
198− sr = sr >> 7 | Nc[3] << 9;
199− *c++ = sr >> 5;
200− sr = sr >> 2 | bc[3] << 14;
201− sr = sr >> 2 | Mc[3] << 14;
202− sr = sr >> 6 | xmaxc[3] << 10;
203− *c++ = sr >> 3;
204− sr = sr >> 3 | xmc[39] << 13;
205− *c++ = sr >> 8;
206− sr = sr >> 3 | xmc[40] << 13;
207− sr = sr >> 3 | xmc[41] << 13;
208− sr = sr >> 3 | xmc[42] << 13;
209− *c++ = sr >> 7;
210− sr = sr >> 3 | xmc[43] << 13;
211− sr = sr >> 3 | xmc[44] << 13;
212− sr = sr >> 3 | xmc[45] << 13;
213− *c++ = sr >> 6;
214− sr = sr >> 3 | xmc[46] << 13;
215− sr = sr >> 3 | xmc[47] << 13;
216− *c++ = sr >> 8;
217− sr = sr >> 3 | xmc[48] << 13;
218− sr = sr >> 3 | xmc[49] << 13;
219− sr = sr >> 3 | xmc[50] << 13;
220− *c++ = sr >> 7;
221− sr = sr >> 3 | xmc[51] << 13;
222− sr = sr >> 4;
223− *c = sr >> 8;
224− s->frame_chain = *c;
225− }
226− else {
227− uword sr;
228−
229− sr = 0;
230− sr = sr >> 4 | s->frame_chain << 12;
231− sr = sr >> 6 | LARc[0] << 10;
232− *c++ = sr >> 6;
233− sr = sr >> 6 | LARc[1] << 10;
234− *c++ = sr >> 8;
235− sr = sr >> 5 | LARc[2] << 11;
236− sr = sr >> 5 | LARc[3] << 11;
237− *c++ = sr >> 6;
238− sr = sr >> 4 | LARc[4] << 12;
239− sr = sr >> 4 | LARc[5] << 12;
240− *c++ = sr >> 6;
241− sr = sr >> 3 | LARc[6] << 13;
242− sr = sr >> 3 | LARc[7] << 13;
243− *c++ = sr >> 8;
244− sr = sr >> 7 | Nc[0] << 9;
245− sr = sr >> 2 | bc[0] << 14;
246− *c++ = sr >> 7;
247− sr = sr >> 2 | Mc[0] << 14;
248− sr = sr >> 6 | xmaxc[0] << 10;
249− *c++ = sr >> 7;
250− sr = sr >> 3 | xmc[0] << 13;
251− sr = sr >> 3 | xmc[1] << 13;
252− sr = sr >> 3 | xmc[2] << 13;
253− *c++ = sr >> 6;
254− sr = sr >> 3 | xmc[3] << 13;
255− sr = sr >> 3 | xmc[4] << 13;
256− *c++ = sr >> 8;
257− sr = sr >> 3 | xmc[5] << 13;
258− sr = sr >> 3 | xmc[6] << 13;
259− sr = sr >> 3 | xmc[7] << 13;
260− *c++ = sr >> 7;
261− sr = sr >> 3 | xmc[8] << 13;
262− sr = sr >> 3 | xmc[9] << 13;
263− sr = sr >> 3 | xmc[10] << 13;
264− *c++ = sr >> 6;
265− sr = sr >> 3 | xmc[11] << 13;
266− sr = sr >> 3 | xmc[12] << 13;
267− *c++ = sr >> 8;
268− sr = sr >> 7 | Nc[1] << 9;
269− sr = sr >> 2 | bc[1] << 14;
270− *c++ = sr >> 7;
271− sr = sr >> 2 | Mc[1] << 14;
272− sr = sr >> 6 | xmaxc[1] << 10;
273− *c++ = sr >> 7;
274− sr = sr >> 3 | xmc[13] << 13;
275− sr = sr >> 3 | xmc[14] << 13;
276− sr = sr >> 3 | xmc[15] << 13;
277− *c++ = sr >> 6;
278− sr = sr >> 3 | xmc[16] << 13;
279− sr = sr >> 3 | xmc[17] << 13;
280− *c++ = sr >> 8;
281− sr = sr >> 3 | xmc[18] << 13;
282− sr = sr >> 3 | xmc[19] << 13;
283− sr = sr >> 3 | xmc[20] << 13;
284− *c++ = sr >> 7;
285− sr = sr >> 3 | xmc[21] << 13;
286− sr = sr >> 3 | xmc[22] << 13;
287− sr = sr >> 3 | xmc[23] << 13;
288− *c++ = sr >> 6;
289− sr = sr >> 3 | xmc[24] << 13;
290− sr = sr >> 3 | xmc[25] << 13;
291− *c++ = sr >> 8;
292− sr = sr >> 7 | Nc[2] << 9;
293− sr = sr >> 2 | bc[2] << 14;
294− *c++ = sr >> 7;
295− sr = sr >> 2 | Mc[2] << 14;
296− sr = sr >> 6 | xmaxc[2] << 10;
297− *c++ = sr >> 7;
298− sr = sr >> 3 | xmc[26] << 13;
299− sr = sr >> 3 | xmc[27] << 13;
300− sr = sr >> 3 | xmc[28] << 13;
301− *c++ = sr >> 6;
302− sr = sr >> 3 | xmc[29] << 13;
303− sr = sr >> 3 | xmc[30] << 13;
304− *c++ = sr >> 8;
305− sr = sr >> 3 | xmc[31] << 13;
306− sr = sr >> 3 | xmc[32] << 13;
307− sr = sr >> 3 | xmc[33] << 13;
308− *c++ = sr >> 7;
309− sr = sr >> 3 | xmc[34] << 13;
310− sr = sr >> 3 | xmc[35] << 13;
311− sr = sr >> 3 | xmc[36] << 13;
312− *c++ = sr >> 6;
313− sr = sr >> 3 | xmc[37] << 13;
314− sr = sr >> 3 | xmc[38] << 13;
315− *c++ = sr >> 8;
316− sr = sr >> 7 | Nc[3] << 9;
317− sr = sr >> 2 | bc[3] << 14;
318− *c++ = sr >> 7;
319− sr = sr >> 2 | Mc[3] << 14;
320− sr = sr >> 6 | xmaxc[3] << 10;
321− *c++ = sr >> 7;
322− sr = sr >> 3 | xmc[39] << 13;
323− sr = sr >> 3 | xmc[40] << 13;
324− sr = sr >> 3 | xmc[41] << 13;
325− *c++ = sr >> 6;
326− sr = sr >> 3 | xmc[42] << 13;
327− sr = sr >> 3 | xmc[43] << 13;
328− *c++ = sr >> 8;
329− sr = sr >> 3 | xmc[44] << 13;
330− sr = sr >> 3 | xmc[45] << 13;
331− sr = sr >> 3 | xmc[46] << 13;
332− *c++ = sr >> 7;
333− sr = sr >> 3 | xmc[47] << 13;
334− sr = sr >> 3 | xmc[48] << 13;
335− sr = sr >> 3 | xmc[49] << 13;
336− *c++ = sr >> 6;
337− sr = sr >> 3 | xmc[50] << 13;
338− sr = sr >> 3 | xmc[51] << 13;
339− *c++ = sr >> 8;
340− }
341− }
342−
343− else
344−
345−#endif /* WAV49 */
346− {
347−
348− *c++ = ((GSM_MAGIC & 0xF) << 4) /* 1 */
349− | ((LARc[0] >> 2) & 0xF);
350− *c++ = ((LARc[0] & 0x3) << 6)
351− | (LARc[1] & 0x3F);
352− *c++ = ((LARc[2] & 0x1F) << 3)
353− | ((LARc[3] >> 2) & 0x7);
354− *c++ = ((LARc[3] & 0x3) << 6)
355− | ((LARc[4] & 0xF) << 2)
356− | ((LARc[5] >> 2) & 0x3);
357− *c++ = ((LARc[5] & 0x3) << 6)
358− | ((LARc[6] & 0x7) << 3)
359− | (LARc[7] & 0x7);
360− *c++ = ((Nc[0] & 0x7F) << 1)
361− | ((bc[0] >> 1) & 0x1);
362− *c++ = ((bc[0] & 0x1) << 7)
363− | ((Mc[0] & 0x3) << 5)
364− | ((xmaxc[0] >> 1) & 0x1F);
365− *c++ = ((xmaxc[0] & 0x1) << 7)
366− | ((xmc[0] & 0x7) << 4)
367− | ((xmc[1] & 0x7) << 1)
368− | ((xmc[2] >> 2) & 0x1);
369− *c++ = ((xmc[2] & 0x3) << 6)
370− | ((xmc[3] & 0x7) << 3)
371− | (xmc[4] & 0x7);
372− *c++ = ((xmc[5] & 0x7) << 5) /* 10 */
373− | ((xmc[6] & 0x7) << 2)
374− | ((xmc[7] >> 1) & 0x3);
375− *c++ = ((xmc[7] & 0x1) << 7)
376− | ((xmc[8] & 0x7) << 4)
377− | ((xmc[9] & 0x7) << 1)
378− | ((xmc[10] >> 2) & 0x1);
379− *c++ = ((xmc[10] & 0x3) << 6)
380− | ((xmc[11] & 0x7) << 3)
381− | (xmc[12] & 0x7);
382− *c++ = ((Nc[1] & 0x7F) << 1)
383− | ((bc[1] >> 1) & 0x1);
384− *c++ = ((bc[1] & 0x1) << 7)
385− | ((Mc[1] & 0x3) << 5)
386− | ((xmaxc[1] >> 1) & 0x1F);
387− *c++ = ((xmaxc[1] & 0x1) << 7)
388− | ((xmc[13] & 0x7) << 4)
389− | ((xmc[14] & 0x7) << 1)
390− | ((xmc[15] >> 2) & 0x1);
391− *c++ = ((xmc[15] & 0x3) << 6)
392− | ((xmc[16] & 0x7) << 3)
393− | (xmc[17] & 0x7);
394− *c++ = ((xmc[18] & 0x7) << 5)
395− | ((xmc[19] & 0x7) << 2)
396− | ((xmc[20] >> 1) & 0x3);
397− *c++ = ((xmc[20] & 0x1) << 7)
398− | ((xmc[21] & 0x7) << 4)
399− | ((xmc[22] & 0x7) << 1)
400− | ((xmc[23] >> 2) & 0x1);
401− *c++ = ((xmc[23] & 0x3) << 6)
402− | ((xmc[24] & 0x7) << 3)
403− | (xmc[25] & 0x7);
404− *c++ = ((Nc[2] & 0x7F) << 1) /* 20 */
405− | ((bc[2] >> 1) & 0x1);
406− *c++ = ((bc[2] & 0x1) << 7)
407− | ((Mc[2] & 0x3) << 5)
408− | ((xmaxc[2] >> 1) & 0x1F);
409− *c++ = ((xmaxc[2] & 0x1) << 7)
410− | ((xmc[26] & 0x7) << 4)
411− | ((xmc[27] & 0x7) << 1)
412− | ((xmc[28] >> 2) & 0x1);
413− *c++ = ((xmc[28] & 0x3) << 6)
414− | ((xmc[29] & 0x7) << 3)
415− | (xmc[30] & 0x7);
416− *c++ = ((xmc[31] & 0x7) << 5)
417− | ((xmc[32] & 0x7) << 2)
418− | ((xmc[33] >> 1) & 0x3);
419− *c++ = ((xmc[33] & 0x1) << 7)
420− | ((xmc[34] & 0x7) << 4)
421− | ((xmc[35] & 0x7) << 1)
422− | ((xmc[36] >> 2) & 0x1);
423− *c++ = ((xmc[36] & 0x3) << 6)
424− | ((xmc[37] & 0x7) << 3)
425− | (xmc[38] & 0x7);
426− *c++ = ((Nc[3] & 0x7F) << 1)
427− | ((bc[3] >> 1) & 0x1);
428− *c++ = ((bc[3] & 0x1) << 7)
429− | ((Mc[3] & 0x3) << 5)
430− | ((xmaxc[3] >> 1) & 0x1F);
431− *c++ = ((xmaxc[3] & 0x1) << 7)
432− | ((xmc[39] & 0x7) << 4)
433− | ((xmc[40] & 0x7) << 1)
434− | ((xmc[41] >> 2) & 0x1);
435− *c++ = ((xmc[41] & 0x3) << 6) /* 30 */
436− | ((xmc[42] & 0x7) << 3)
437− | (xmc[43] & 0x7);
438− *c++ = ((xmc[44] & 0x7) << 5)
439− | ((xmc[45] & 0x7) << 2)
440− | ((xmc[46] >> 1) & 0x3);
441− *c++ = ((xmc[46] & 0x1) << 7)
442− | ((xmc[47] & 0x7) << 4)
443− | ((xmc[48] & 0x7) << 1)
444− | ((xmc[49] >> 2) & 0x1);
445− *c++ = ((xmc[49] & 0x3) << 6)
446− | ((xmc[50] & 0x7) << 3)
447− | (xmc[51] & 0x7);
448−
449− }
450−}
libgsm/gsm_option.3+0−183
@@ -1,183 +0,0 @@
1−.\"
2−.\" Copyright 1992-1995 by Jutta Degener and Carsten Bormann, Technische
3−.\" Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4−.\" details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5−.\"
6−.PU
7−.TH GSM_OPTION 3
8−.SH NAME
9−gsm_option \(em customizing the GSM 06.10 implementation
10−.SH SYNOPSIS
11−#include "gsm.h"
12−.PP
13−int gsm_option(handle, option, valueP);
14−.br
15−gsm handle;
16−.br
17−int option;
18−.br
19−int * valueP;
20−.SH "DESCRIPTION"
21−The gsm library is an implementation of the final draft GSM 06.10
22−standard for full-rate speech transcoding, a lossy
23−speech compression algorithm.
24−.PP
25−The gsm_option() function can be used to set and query various
26−options or flags that are not needed for regular GSM 06.10 encoding
27−or decoding, but might be of interest in special cases.
28−.PP
29−The second argument to gsm_option specifies what parameter
30−should be changed or queried.
31−The third argument is either a null pointer, in which case
32−the current value of that parameter is returned;
33−or it is a pointer to an integer containing the value
34−you want to set, in which case the previous value will
35−be returned.
36−.PP
37−The following options are defined:
38−.PP
39−.I GSM_OPT_VERBOSE
40−Verbosity level.
41−.br
42−.in+5
43−This option is only supported if the library was compiled
44−with debugging turned on, and may be used by developers of
45−compression algorithms to aid debugging.
46−.br
47−The verbosity level can be changed at any time during encoding or decoding.
48−.in-5
49−.sp
50−.PP
51−.I GSM_OPT_FAST
52−Faster compression algorithm.
53−.br
54−.in+5
55−This implementation offers a not strictly standard-compliant, but
56−faster compression algorithm that is compatible with the regular
57−method and does not noticably degrade audio quality.
58−.br
59−The value passed to
60−.br
61−.nf
62− gsm_option(handle, GSM_OPT_FAST, & value)
63−.fi
64−.br
65−functions as a boolean flag; if it is zero, the regular algorithm
66−will be used, if not, the faster version will be used.
67−.br
68−The availability of this option depends on the hardware used;
69−if it is not available, gsm_option will return -1 on an attempt
70−to set or query it.
71−.br
72−This option can be set any time during encoding or decoding.
73−.in-5
74−.ne 5
75−.sp
76−.PP
77−.I GSM_OPT_LTP_CUT
78−Enable, disable, or query the LTP cut-off optimization.
79−.br
80−.in+5
81−During encoding, the search for the long-term correlation
82−lag forms the bottleneck of the algorithm.
83−The ltp-cut option enables an approximation that disregards most
84−of the samples for purposes of finding that correlation,
85−and hence speeds up the encoding at a noticable loss in quality.
86−.br
87−The value passed to
88−.br
89−.nf
90− gsm_option(handle, GSM_OPT_LTP_CUT, & value)
91−.fi
92−.br
93−turns the optimization on if nonzero, and off if zero.
94−.br
95−This option can be set any time during encoding
96−or decoding; it will only affect the encoding pass, not
97−the decoding.
98−.sp
99−.PP
100−.I GSM_OPT_WAV49
101−WAV-style byte ordering.
102−.br
103−.in+5
104−A WAV file of type #49 contains GSM 06.10-encoded frames.
105−Unfortunately, the framing and code ordering of the WAV version
106−are incompatible with the native ones of this GSM 06.10 library.
107−The GSM_OPT_WAV49 option turns on a different packing
108−algorithm that produces alternating frames of 32 and 33 bytes
109−(or makes it consume alternating frames of 33 and 32 bytes, note
110−the opposite order of the two numbers) which, when concatenated,
111−can be used in the body of a WAV #49 frame.
112−It is up to the user program to write a WAV header, if any;
113−neither the library itself nor the toast program produce
114−complete WAV files.
115−.br
116−The value passed to
117−.br
118−.nf
119− gsm_option(handle, GSM_OPT_WAV49, & value)
120−.fi
121−.br
122−functions as a boolean flag; if it is zero, the library's native
123−framing algorithm will be used, if nonzero, WAV-type packing is in effect.
124−.br
125−This option should be used before any frames are encoded.
126−Whether or not it is supported at all depends on a
127−compile-time switch, WAV49.
128−Both option and compile time switch are new to the library
129−as of patchlevel 9, and are considerably less tested than the
130−well-worn rest of the it.
131−.br
132−Thanks to Jeff Chilton for the detective work and first free
133−implementation of this version of the GSM 06.10 encoding.
134−.sp
135−.PP
136−.I GSM_OPT_FRAME_CHAIN
137−Query or set the chaining byte.
138−.br
139−.in+5
140−Between the two frames of a WAV-style encoding, the GSM 06.10 library
141−must keep track of one half-byte that is technically part of the first
142−frame, but will be written as the first four bits of the second.
143−This half-byte are the lowest four bits of the value returned by,
144−and optionally set by,
145−.br
146−.nf
147− gsm_option(handle, GSM_OPT_FRAME_CHAIN, & value)
148−.fi
149−.br
150−This option can be queried and set at any time.
151−.sp
152−.PP
153−.I GSM_OPT_FRAME_INDEX
154−Query or set the current frame's index in a format's
155−alternating list of frames.
156−.br
157−.in+5
158−The WAV #49 framing uses two alternating types of frames.
159−Which type the next GSM-coded frame belongs to can be queried, or,
160−when decoding, announced, using
161−.br
162−.nf
163− gsm_option(handle, GSM_OPT_FRAME_INDEX, & value)
164−.fi
165−.br
166−For WAV-style framing, the value should be 0 or 1; the first frame
167−of an encoding has an index of 0.
168−At library initialization, the index is set to zero.
169−.br
170−The frame index can be queried and set at any time.
171−Used in combination with the
172−.IR GSM_OPT_FRAME_CHAIN ,
173−option, it can be used to position on arbitrary GSM frames
174−within a format like WAV #49 (not accounting for the lost
175−internal GSM state).
176−.in-5
177−.SH "RETURN VALUE"
178−gsm_option() returns -1 if an option is not supported, the
179−previous value of the option otherwise.
180−.SH BUGS
181−Please direct bug reports to jutta@cs.tu-berlin.de and cabo@cs.tu-berlin.de.
182−.SH "SEE ALSO"
183−toast(1), gsm(3), gsm_explode(3), gsm_print(3)
libgsm/gsm_option.c+0−69
@@ -1,69 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/gsm_option.c,v 1.2 2008/02/16 18:30:03 robs Exp $ */
8−
9−#include "private.h"
10−
11−#include "gsm.h"
12−
13−int gsm_option (gsm r, int opt, int * val)
14−{
15− int result = -1;
16−
17− switch (opt) {
18− case GSM_OPT_LTP_CUT:
19−#ifdef LTP_CUT
20− result = r->ltp_cut;
21− if (val) r->ltp_cut = *val;
22−#endif
23− break;
24−
25− case GSM_OPT_VERBOSE:
26−#ifndef NDEBUG
27− result = r->verbose;
28− if (val) r->verbose = *val;
29−#endif
30− break;
31−
32− case GSM_OPT_FAST:
33−
34−#if defined(FAST) && defined(USE_FLOAT_MUL)
35− result = r->fast;
36− if (val) r->fast = !!*val;
37−#endif
38− break;
39−
40− case GSM_OPT_FRAME_CHAIN:
41−
42−#ifdef WAV49
43− result = r->frame_chain;
44− if (val) r->frame_chain = *val;
45−#endif
46− break;
47−
48− case GSM_OPT_FRAME_INDEX:
49−
50−#ifdef WAV49
51− result = r->frame_index;
52− if (val) r->frame_index = *val;
53−#endif
54− break;
55−
56− case GSM_OPT_WAV49:
57−
58−#ifdef WAV49
59− result = r->wav_fmt;
60− if (val) r->wav_fmt = !!*val;
61−#endif
62− break;
63−
64− default:
65− (void)r, (void)val;
66− break;
67− }
68− return result;
69−}
libgsm/long_term.c+0−949
@@ -1,949 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/long_term.c,v 1.2 2007/11/04 16:32:36 robs Exp $ */
8−
9−#include <stdio.h>
10−#include <assert.h>
11−
12−#include "private.h"
13−
14−#include "gsm.h"
15−
16−/*
17− * 4.2.11 .. 4.2.12 LONG TERM PREDICTOR (LTP) SECTION
18− */
19−
20−
21−/*
22− * This module computes the LTP gain (bc) and the LTP lag (Nc)
23− * for the long term analysis filter. This is done by calculating a
24− * maximum of the cross-correlation function between the current
25− * sub-segment short term residual signal d[0..39] (output of
26− * the short term analysis filter; for simplification the index
27− * of this array begins at 0 and ends at 39 for each sub-segment of the
28− * RPE-LTP analysis) and the previous reconstructed short term
29− * residual signal dp[ -120 .. -1 ]. A dynamic scaling must be
30− * performed to avoid overflow.
31− */
32−
33− /* The next procedure exists in six versions. First two integer
34− * version (if USE_FLOAT_MUL is not defined); then four floating
35− * point versions, twice with proper scaling (USE_FLOAT_MUL defined),
36− * once without (USE_FLOAT_MUL and FAST defined, and fast run-time
37− * option used). Every pair has first a Cut version (see the -C
38− * option to toast or the LTP_CUT option to gsm_option()), then the
39− * uncut one. (For a detailed explanation of why this is altogether
40− * a bad idea, see Henry Spencer and Geoff Collyer, ``#ifdef Considered
41− * Harmful''.)
42− */
43−
44−#ifndef USE_FLOAT_MUL
45−
46−#ifdef LTP_CUT
47−
48−static void Cut_Calculation_of_the_LTP_parameters (
49−
50− struct gsm_state * st,
51−
52− register word * d, /* [0..39] IN */
53− register word * dp, /* [-120..-1] IN */
54− word * bc_out, /* OUT */
55− word * Nc_out /* OUT */
56−)
57−{
58− register int k, lambda;
59− word Nc, bc;
60− word wt[40];
61−
62− longword L_result;
63− longword L_max, L_power;
64− word R, S, dmax, scal, best_k;
65− word ltp_cut;
66−
67− register word temp, wt_k;
68−
69− /* Search of the optimum scaling of d[0..39].
70− */
71− dmax = 0;
72− for (k = 0; k <= 39; k++) {
73− temp = d[k];
74− temp = GSM_ABS( temp );
75− if (temp > dmax) {
76− dmax = temp;
77− best_k = k;
78− }
79− }
80− temp = 0;
81− if (dmax == 0) scal = 0;
82− else {
83− assert(dmax > 0);
84− temp = gsm_norm( (longword)dmax << 16 );
85− }
86− if (temp > 6) scal = 0;
87− else scal = 6 - temp;
88− assert(scal >= 0);
89−
90− /* Search for the maximum cross-correlation and coding of the LTP lag
91− */
92− L_max = 0;
93− Nc = 40; /* index for the maximum cross-correlation */
94− wt_k = SASR(d[best_k], scal);
95−
96− for (lambda = 40; lambda <= 120; lambda++) {
97− L_result = (longword)wt_k * dp[best_k - lambda];
98− if (L_result > L_max) {
99− Nc = lambda;
100− L_max = L_result;
101− }
102− }
103− *Nc_out = Nc;
104− L_max <<= 1;
105−
106− /* Rescaling of L_max
107− */
108− assert(scal <= 100 && scal >= -100);
109− L_max = L_max >> (6 - scal); /* sub(6, scal) */
110−
111− assert( Nc <= 120 && Nc >= 40);
112−
113− /* Compute the power of the reconstructed short term residual
114− * signal dp[..]
115− */
116− L_power = 0;
117− for (k = 0; k <= 39; k++) {
118−
119− register longword L_temp;
120−
121− L_temp = SASR( dp[k - Nc], 3 );
122− L_power += L_temp * L_temp;
123− }
124− L_power <<= 1; /* from L_MULT */
125−
126− /* Normalization of L_max and L_power
127− */
128−
129− if (L_max <= 0) {
130− *bc_out = 0;
131− return;
132− }
133− if (L_max >= L_power) {
134− *bc_out = 3;
135− return;
136− }
137−
138− temp = gsm_norm( L_power );
139−
140− R = SASR( L_max << temp, 16 );
141− S = SASR( L_power << temp, 16 );
142−
143− /* Coding of the LTP gain
144− */
145−
146− /* Table 4.3a must be used to obtain the level DLB[i] for the
147− * quantization of the LTP gain b to get the coded version bc.
148− */
149− for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
150− *bc_out = bc;
151−}
152−
153−#endif /* LTP_CUT */
154−
155−static void Calculation_of_the_LTP_parameters (
156− register word * d, /* [0..39] IN */
157− register word * dp, /* [-120..-1] IN */
158− word * bc_out, /* OUT */
159− word * Nc_out /* OUT */
160−)
161−{
162− register int k, lambda;
163− word Nc, bc;
164− word wt[40];
165−
166− longword L_max, L_power;
167− word R, S, dmax, scal;
168− register word temp;
169−
170− /* Search of the optimum scaling of d[0..39].
171− */
172− dmax = 0;
173−
174− for (k = 0; k <= 39; k++) {
175− temp = d[k];
176− temp = GSM_ABS( temp );
177− if (temp > dmax) dmax = temp;
178− }
179−
180− temp = 0;
181− if (dmax == 0) scal = 0;
182− else {
183− assert(dmax > 0);
184− temp = gsm_norm( (longword)dmax << 16 );
185− }
186−
187− if (temp > 6) scal = 0;
188− else scal = 6 - temp;
189−
190− assert(scal >= 0);
191−
192− /* Initialization of a working array wt
193− */
194−
195− for (k = 0; k <= 39; k++) wt[k] = SASR( d[k], scal );
196−
197− /* Search for the maximum cross-correlation and coding of the LTP lag
198− */
199− L_max = 0;
200− Nc = 40; /* index for the maximum cross-correlation */
201−
202− for (lambda = 40; lambda <= 120; lambda++) {
203−
204−# undef STEP
205−# define STEP(k) (longword)wt[k] * dp[k - lambda]
206−
207− register longword L_result;
208−
209− L_result = STEP(0) ; L_result += STEP(1) ;
210− L_result += STEP(2) ; L_result += STEP(3) ;
211− L_result += STEP(4) ; L_result += STEP(5) ;
212− L_result += STEP(6) ; L_result += STEP(7) ;
213− L_result += STEP(8) ; L_result += STEP(9) ;
214− L_result += STEP(10) ; L_result += STEP(11) ;
215− L_result += STEP(12) ; L_result += STEP(13) ;
216− L_result += STEP(14) ; L_result += STEP(15) ;
217− L_result += STEP(16) ; L_result += STEP(17) ;
218− L_result += STEP(18) ; L_result += STEP(19) ;
219− L_result += STEP(20) ; L_result += STEP(21) ;
220− L_result += STEP(22) ; L_result += STEP(23) ;
221− L_result += STEP(24) ; L_result += STEP(25) ;
222− L_result += STEP(26) ; L_result += STEP(27) ;
223− L_result += STEP(28) ; L_result += STEP(29) ;
224− L_result += STEP(30) ; L_result += STEP(31) ;
225− L_result += STEP(32) ; L_result += STEP(33) ;
226− L_result += STEP(34) ; L_result += STEP(35) ;
227− L_result += STEP(36) ; L_result += STEP(37) ;
228− L_result += STEP(38) ; L_result += STEP(39) ;
229−
230− if (L_result > L_max) {
231−
232− Nc = lambda;
233− L_max = L_result;
234− }
235− }
236−
237− *Nc_out = Nc;
238−
239− L_max <<= 1;
240−
241− /* Rescaling of L_max
242− */
243− assert(scal <= 100 && scal >= -100);
244− L_max = L_max >> (6 - scal); /* sub(6, scal) */
245−
246− assert( Nc <= 120 && Nc >= 40);
247−
248− /* Compute the power of the reconstructed short term residual
249− * signal dp[..]
250− */
251− L_power = 0;
252− for (k = 0; k <= 39; k++) {
253−
254− register longword L_temp;
255−
256− L_temp = SASR( dp[k - Nc], 3 );
257− L_power += L_temp * L_temp;
258− }
259− L_power <<= 1; /* from L_MULT */
260−
261− /* Normalization of L_max and L_power
262− */
263−
264− if (L_max <= 0) {
265− *bc_out = 0;
266− return;
267− }
268− if (L_max >= L_power) {
269− *bc_out = 3;
270− return;
271− }
272−
273− temp = gsm_norm( L_power );
274−
275− R = SASR( L_max << temp, 16 );
276− S = SASR( L_power << temp, 16 );
277−
278− /* Coding of the LTP gain
279− */
280−
281− /* Table 4.3a must be used to obtain the level DLB[i] for the
282− * quantization of the LTP gain b to get the coded version bc.
283− */
284− for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
285− *bc_out = bc;
286−}
287−
288−#else /* USE_FLOAT_MUL */
289−
290−#ifdef LTP_CUT
291−
292−static void Cut_Calculation_of_the_LTP_parameters (
293− struct gsm_state * st, /* IN */
294− register word * d, /* [0..39] IN */
295− register word * dp, /* [-120..-1] IN */
296− word * bc_out, /* OUT */
297− word * Nc_out /* OUT */
298−)
299−{
300− register int k, lambda;
301− word Nc, bc;
302− word ltp_cut;
303−
304− float wt_float[40];
305− float dp_float_base[120], * dp_float = dp_float_base + 120;
306−
307− longword L_max, L_power;
308− word R, S, dmax, scal;
309− register word temp;
310−
311− /* Search of the optimum scaling of d[0..39].
312− */
313− dmax = 0;
314−
315− for (k = 0; k <= 39; k++) {
316− temp = d[k];
317− temp = GSM_ABS( temp );
318− if (temp > dmax) dmax = temp;
319− }
320−
321− temp = 0;
322− if (dmax == 0) scal = 0;
323− else {
324− assert(dmax > 0);
325− temp = gsm_norm( (longword)dmax << 16 );
326− }
327−
328− if (temp > 6) scal = 0;
329− else scal = 6 - temp;
330−
331− assert(scal >= 0);
332− ltp_cut = (longword)SASR(dmax, scal) * st->ltp_cut / 100;
333−
334−
335− /* Initialization of a working array wt
336− */
337−
338− for (k = 0; k < 40; k++) {
339− register word w = SASR( d[k], scal );
340− if (w < 0 ? w > -ltp_cut : w < ltp_cut) {
341− wt_float[k] = 0.0;
342− }
343− else {
344− wt_float[k] = w;
345− }
346− }
347− for (k = -120; k < 0; k++) dp_float[k] = dp[k];
348−
349− /* Search for the maximum cross-correlation and coding of the LTP lag
350− */
351− L_max = 0;
352− Nc = 40; /* index for the maximum cross-correlation */
353−
354− for (lambda = 40; lambda <= 120; lambda += 9) {
355−
356− /* Calculate L_result for l = lambda .. lambda + 9.
357− */
358− register float *lp = dp_float - lambda;
359−
360− register float W;
361− register float a = lp[-8], b = lp[-7], c = lp[-6],
362− d = lp[-5], e = lp[-4], f = lp[-3],
363− g = lp[-2], h = lp[-1];
364− register float E;
365− register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
366− S5 = 0, S6 = 0, S7 = 0, S8 = 0;
367−
368−# undef STEP
369−# define STEP(K, a, b, c, d, e, f, g, h) \
370− if ((W = wt_float[K]) != 0.0) { \
371− E = W * a; S8 += E; \
372− E = W * b; S7 += E; \
373− E = W * c; S6 += E; \
374− E = W * d; S5 += E; \
375− E = W * e; S4 += E; \
376− E = W * f; S3 += E; \
377− E = W * g; S2 += E; \
378− E = W * h; S1 += E; \
379− a = lp[K]; \
380− E = W * a; S0 += E; } else (a = lp[K])
381−
382−# define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
383−# define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
384−# define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
385−# define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
386−# define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
387−# define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
388−# define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
389−# define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
390−
391− STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
392− STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
393−
394− STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
395− STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
396−
397− STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
398− STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
399−
400− STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
401− STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
402−
403− STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
404− STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
405−
406− if (S0 > L_max) { L_max = S0; Nc = lambda; }
407− if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
408− if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
409− if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
410− if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
411− if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
412− if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
413− if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
414− if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
415−
416− }
417− *Nc_out = Nc;
418−
419− L_max <<= 1;
420−
421− /* Rescaling of L_max
422− */
423− assert(scal <= 100 && scal >= -100);
424− L_max = L_max >> (6 - scal); /* sub(6, scal) */
425−
426− assert( Nc <= 120 && Nc >= 40);
427−
428− /* Compute the power of the reconstructed short term residual
429− * signal dp[..]
430− */
431− L_power = 0;
432− for (k = 0; k <= 39; k++) {
433−
434− register longword L_temp;
435−
436− L_temp = SASR( dp[k - Nc], 3 );
437− L_power += L_temp * L_temp;
438− }
439− L_power <<= 1; /* from L_MULT */
440−
441− /* Normalization of L_max and L_power
442− */
443−
444− if (L_max <= 0) {
445− *bc_out = 0;
446− return;
447− }
448− if (L_max >= L_power) {
449− *bc_out = 3;
450− return;
451− }
452−
453− temp = gsm_norm( L_power );
454−
455− R = SASR( L_max << temp, 16 );
456− S = SASR( L_power << temp, 16 );
457−
458− /* Coding of the LTP gain
459− */
460−
461− /* Table 4.3a must be used to obtain the level DLB[i] for the
462− * quantization of the LTP gain b to get the coded version bc.
463− */
464− for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
465− *bc_out = bc;
466−}
467−
468−#endif /* LTP_CUT */
469−
470−static void Calculation_of_the_LTP_parameters (
471− register word * d, /* [0..39] IN */
472− register word * dp, /* [-120..-1] IN */
473− word * bc_out, /* OUT */
474− word * Nc_out /* OUT */
475−)
476−{
477− register int k, lambda;
478− word Nc, bc;
479−
480− float wt_float[40];
481− float dp_float_base[120], * dp_float = dp_float_base + 120;
482−
483− longword L_max, L_power;
484− word R, S, dmax, scal;
485− register word temp;
486−
487− /* Search of the optimum scaling of d[0..39].
488− */
489− dmax = 0;
490−
491− for (k = 0; k <= 39; k++) {
492− temp = d[k];
493− temp = GSM_ABS( temp );
494− if (temp > dmax) dmax = temp;
495− }
496−
497− temp = 0;
498− if (dmax == 0) scal = 0;
499− else {
500− assert(dmax > 0);
501− temp = gsm_norm( (longword)dmax << 16 );
502− }
503−
504− if (temp > 6) scal = 0;
505− else scal = 6 - temp;
506−
507− assert(scal >= 0);
508−
509− /* Initialization of a working array wt
510− */
511−
512− for (k = 0; k < 40; k++) wt_float[k] = SASR( d[k], scal );
513− for (k = -120; k < 0; k++) dp_float[k] = dp[k];
514−
515− /* Search for the maximum cross-correlation and coding of the LTP lag
516− */
517− L_max = 0;
518− Nc = 40; /* index for the maximum cross-correlation */
519−
520− for (lambda = 40; lambda <= 120; lambda += 9) {
521−
522− /* Calculate L_result for l = lambda .. lambda + 9.
523− */
524− register float *lp = dp_float - lambda;
525−
526− register float W;
527− register float a = lp[-8], b = lp[-7], c = lp[-6],
528− d = lp[-5], e = lp[-4], f = lp[-3],
529− g = lp[-2], h = lp[-1];
530− register float E;
531− register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
532− S5 = 0, S6 = 0, S7 = 0, S8 = 0;
533−
534−# undef STEP
535−# define STEP(K, a, b, c, d, e, f, g, h) \
536− W = wt_float[K]; \
537− E = W * a; S8 += E; \
538− E = W * b; S7 += E; \
539− E = W * c; S6 += E; \
540− E = W * d; S5 += E; \
541− E = W * e; S4 += E; \
542− E = W * f; S3 += E; \
543− E = W * g; S2 += E; \
544− E = W * h; S1 += E; \
545− a = lp[K]; \
546− E = W * a; S0 += E
547−
548−# define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
549−# define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
550−# define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
551−# define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
552−# define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
553−# define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
554−# define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
555−# define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
556−
557− STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
558− STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
559−
560− STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
561− STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
562−
563− STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
564− STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
565−
566− STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
567− STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
568−
569− STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
570− STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
571−
572− if (S0 > L_max) { L_max = S0; Nc = lambda; }
573− if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
574− if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
575− if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
576− if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
577− if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
578− if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
579− if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
580− if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
581− }
582− *Nc_out = Nc;
583−
584− L_max <<= 1;
585−
586− /* Rescaling of L_max
587− */
588− assert(scal <= 100 && scal >= -100);
589− L_max = L_max >> (6 - scal); /* sub(6, scal) */
590−
591− assert( Nc <= 120 && Nc >= 40);
592−
593− /* Compute the power of the reconstructed short term residual
594− * signal dp[..]
595− */
596− L_power = 0;
597− for (k = 0; k <= 39; k++) {
598−
599− register longword L_temp;
600−
601− L_temp = SASR( dp[k - Nc], 3 );
602− L_power += L_temp * L_temp;
603− }
604− L_power <<= 1; /* from L_MULT */
605−
606− /* Normalization of L_max and L_power
607− */
608−
609− if (L_max <= 0) {
610− *bc_out = 0;
611− return;
612− }
613− if (L_max >= L_power) {
614− *bc_out = 3;
615− return;
616− }
617−
618− temp = gsm_norm( L_power );
619−
620− R = SASR( L_max << temp, 16 );
621− S = SASR( L_power << temp, 16 );
622−
623− /* Coding of the LTP gain
624− */
625−
626− /* Table 4.3a must be used to obtain the level DLB[i] for the
627− * quantization of the LTP gain b to get the coded version bc.
628− */
629− for (bc = 0; bc <= 2; bc++) if (R <= gsm_mult(S, gsm_DLB[bc])) break;
630− *bc_out = bc;
631−}
632−
633−#ifdef FAST
634−#ifdef LTP_CUT
635−
636−static void Cut_Fast_Calculation_of_the_LTP_parameters (
637− struct gsm_state * st, /* IN */
638− register word * d, /* [0..39] IN */
639− register word * dp, /* [-120..-1] IN */
640− word * bc_out, /* OUT */
641− word * Nc_out /* OUT */
642−)
643−{
644− register int k, lambda;
645− register float wt_float;
646− word Nc, bc;
647− word wt_max, best_k, ltp_cut;
648−
649− float dp_float_base[120], * dp_float = dp_float_base + 120;
650−
651− register float L_result, L_max, L_power;
652−
653− wt_max = 0;
654−
655− for (k = 0; k < 40; ++k) {
656− if ( d[k] > wt_max) wt_max = d[best_k = k];
657− else if (-d[k] > wt_max) wt_max = -d[best_k = k];
658− }
659−
660− assert(wt_max >= 0);
661− wt_float = (float)wt_max;
662−
663− for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];
664−
665− /* Search for the maximum cross-correlation and coding of the LTP lag
666− */
667− L_max = 0;
668− Nc = 40; /* index for the maximum cross-correlation */
669−
670− for (lambda = 40; lambda <= 120; lambda++) {
671− L_result = wt_float * dp_float[best_k - lambda];
672− if (L_result > L_max) {
673− Nc = lambda;
674− L_max = L_result;
675− }
676− }
677−
678− *Nc_out = Nc;
679− if (L_max <= 0.) {
680− *bc_out = 0;
681− return;
682− }
683−
684− /* Compute the power of the reconstructed short term residual
685− * signal dp[..]
686− */
687− dp_float -= Nc;
688− L_power = 0;
689− for (k = 0; k < 40; ++k) {
690− register float f = dp_float[k];
691− L_power += f * f;
692− }
693−
694− if (L_max >= L_power) {
695− *bc_out = 3;
696− return;
697− }
698−
699− /* Coding of the LTP gain
700− * Table 4.3a must be used to obtain the level DLB[i] for the
701− * quantization of the LTP gain b to get the coded version bc.
702− */
703− lambda = L_max / L_power * 32768.;
704− for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
705− *bc_out = bc;
706−}
707−
708−#endif /* LTP_CUT */
709−
710−static void Fast_Calculation_of_the_LTP_parameters (
711− register word * d, /* [0..39] IN */
712− register word * dp, /* [-120..-1] IN */
713− word * bc_out, /* OUT */
714− word * Nc_out /* OUT */
715−)
716−{
717− register int k, lambda;
718− word Nc, bc;
719−
720− float wt_float[40];
721− float dp_float_base[120], * dp_float = dp_float_base + 120;
722−
723− register float L_max, L_power;
724−
725− for (k = 0; k < 40; ++k) wt_float[k] = (float)d[k];
726− for (k = -120; k < 0; ++k) dp_float[k] = (float)dp[k];
727−
728− /* Search for the maximum cross-correlation and coding of the LTP lag
729− */
730− L_max = 0;
731− Nc = 40; /* index for the maximum cross-correlation */
732−
733− for (lambda = 40; lambda <= 120; lambda += 9) {
734−
735− /* Calculate L_result for l = lambda .. lambda + 9.
736− */
737− register float *lp = dp_float - lambda;
738−
739− register float W;
740− register float a = lp[-8], b = lp[-7], c = lp[-6],
741− d = lp[-5], e = lp[-4], f = lp[-3],
742− g = lp[-2], h = lp[-1];
743− register float E;
744− register float S0 = 0, S1 = 0, S2 = 0, S3 = 0, S4 = 0,
745− S5 = 0, S6 = 0, S7 = 0, S8 = 0;
746−
747−# undef STEP
748−# define STEP(K, a, b, c, d, e, f, g, h) \
749− W = wt_float[K]; \
750− E = W * a; S8 += E; \
751− E = W * b; S7 += E; \
752− E = W * c; S6 += E; \
753− E = W * d; S5 += E; \
754− E = W * e; S4 += E; \
755− E = W * f; S3 += E; \
756− E = W * g; S2 += E; \
757− E = W * h; S1 += E; \
758− a = lp[K]; \
759− E = W * a; S0 += E
760−
761−# define STEP_A(K) STEP(K, a, b, c, d, e, f, g, h)
762−# define STEP_B(K) STEP(K, b, c, d, e, f, g, h, a)
763−# define STEP_C(K) STEP(K, c, d, e, f, g, h, a, b)
764−# define STEP_D(K) STEP(K, d, e, f, g, h, a, b, c)
765−# define STEP_E(K) STEP(K, e, f, g, h, a, b, c, d)
766−# define STEP_F(K) STEP(K, f, g, h, a, b, c, d, e)
767−# define STEP_G(K) STEP(K, g, h, a, b, c, d, e, f)
768−# define STEP_H(K) STEP(K, h, a, b, c, d, e, f, g)
769−
770− STEP_A( 0); STEP_B( 1); STEP_C( 2); STEP_D( 3);
771− STEP_E( 4); STEP_F( 5); STEP_G( 6); STEP_H( 7);
772−
773− STEP_A( 8); STEP_B( 9); STEP_C(10); STEP_D(11);
774− STEP_E(12); STEP_F(13); STEP_G(14); STEP_H(15);
775−
776− STEP_A(16); STEP_B(17); STEP_C(18); STEP_D(19);
777− STEP_E(20); STEP_F(21); STEP_G(22); STEP_H(23);
778−
779− STEP_A(24); STEP_B(25); STEP_C(26); STEP_D(27);
780− STEP_E(28); STEP_F(29); STEP_G(30); STEP_H(31);
781−
782− STEP_A(32); STEP_B(33); STEP_C(34); STEP_D(35);
783− STEP_E(36); STEP_F(37); STEP_G(38); STEP_H(39);
784−
785− if (S0 > L_max) { L_max = S0; Nc = lambda; }
786− if (S1 > L_max) { L_max = S1; Nc = lambda + 1; }
787− if (S2 > L_max) { L_max = S2; Nc = lambda + 2; }
788− if (S3 > L_max) { L_max = S3; Nc = lambda + 3; }
789− if (S4 > L_max) { L_max = S4; Nc = lambda + 4; }
790− if (S5 > L_max) { L_max = S5; Nc = lambda + 5; }
791− if (S6 > L_max) { L_max = S6; Nc = lambda + 6; }
792− if (S7 > L_max) { L_max = S7; Nc = lambda + 7; }
793− if (S8 > L_max) { L_max = S8; Nc = lambda + 8; }
794− }
795− *Nc_out = Nc;
796−
797− if (L_max <= 0.) {
798− *bc_out = 0;
799− return;
800− }
801−
802− /* Compute the power of the reconstructed short term residual
803− * signal dp[..]
804− */
805− dp_float -= Nc;
806− L_power = 0;
807− for (k = 0; k < 40; ++k) {
808− register float f = dp_float[k];
809− L_power += f * f;
810− }
811−
812− if (L_max >= L_power) {
813− *bc_out = 3;
814− return;
815− }
816−
817− /* Coding of the LTP gain
818− * Table 4.3a must be used to obtain the level DLB[i] for the
819− * quantization of the LTP gain b to get the coded version bc.
820− */
821− lambda = L_max / L_power * 32768.;
822− for (bc = 0; bc <= 2; ++bc) if (lambda <= gsm_DLB[bc]) break;
823− *bc_out = bc;
824−}
825−
826−#endif /* FAST */
827−#endif /* USE_FLOAT_MUL */
828−
829−
830−/* 4.2.12 */
831−
832−static void Long_term_analysis_filtering (
833− word bc, /* IN */
834− word Nc, /* IN */
835− register word * dp, /* previous d [-120..-1] IN */
836− register word * d, /* d [0..39] IN */
837− register word * dpp, /* estimate [0..39] OUT */
838− register word * e /* long term res. signal [0..39] OUT */
839−)
840−/*
841− * In this part, we have to decode the bc parameter to compute
842− * the samples of the estimate dpp[0..39]. The decoding of bc needs the
843− * use of table 4.3b. The long term residual signal e[0..39]
844− * is then calculated to be fed to the RPE encoding section.
845− */
846−{
847− register int k;
848− register longword ltmp;
849−
850−# undef STEP
851−# define STEP(BP) \
852− for (k = 0; k <= 39; k++) { \
853− dpp[k] = GSM_MULT_R( BP, dp[k - Nc]); \
854− e[k] = GSM_SUB( d[k], dpp[k] ); \
855− }
856−
857− switch (bc) {
858− case 0: STEP( 3277 ); break;
859− case 1: STEP( 11469 ); break;
860− case 2: STEP( 21299 ); break;
861− case 3: STEP( 32767 ); break;
862− }
863−}
864−
865−void Gsm_Long_Term_Predictor ( /* 4x for 160 samples */
866−
867− struct gsm_state * S,
868−
869− word * d, /* [0..39] residual signal IN */
870− word * dp, /* [-120..-1] d' IN */
871−
872− word * e, /* [0..39] OUT */
873− word * dpp, /* [0..39] OUT */
874− word * Nc, /* correlation lag OUT */
875− word * bc /* gain factor OUT */
876−)
877−{
878− (void)S; /* Denotes intentionally unused */
879−
880− assert( d ); assert( dp ); assert( e );
881− assert( dpp); assert( Nc ); assert( bc );
882−
883−#if defined(FAST) && defined(USE_FLOAT_MUL)
884− if (S->fast)
885−#if defined (LTP_CUT)
886− if (S->ltp_cut)
887− Cut_Fast_Calculation_of_the_LTP_parameters(S,
888− d, dp, bc, Nc);
889− else
890−#endif /* LTP_CUT */
891− Fast_Calculation_of_the_LTP_parameters(d, dp, bc, Nc );
892− else
893−#endif /* FAST & USE_FLOAT_MUL */
894−#ifdef LTP_CUT
895− if (S->ltp_cut)
896− Cut_Calculation_of_the_LTP_parameters(S, d, dp, bc, Nc);
897− else
898−#endif
899− Calculation_of_the_LTP_parameters(d, dp, bc, Nc);
900−
901− Long_term_analysis_filtering( *bc, *Nc, dp, d, dpp, e );
902−}
903−
904−/* 4.3.2 */
905−void Gsm_Long_Term_Synthesis_Filtering (
906− struct gsm_state * S,
907−
908− word Ncr,
909− word bcr,
910− register word * erp, /* [0..39] IN */
911− register word * drp /* [-120..-1] IN, [-120..40] OUT */
912−)
913−/*
914− * This procedure uses the bcr and Ncr parameter to realize the
915− * long term synthesis filtering. The decoding of bcr needs
916− * table 4.3b.
917− */
918−{
919− register longword ltmp; /* for ADD */
920− register int k;
921− word brp, drpp, Nr;
922−
923− /* Check the limits of Nr.
924− */
925− Nr = Ncr < 40 || Ncr > 120 ? S->nrp : Ncr;
926− S->nrp = Nr;
927− assert(Nr >= 40 && Nr <= 120);
928−
929− /* Decoding of the LTP gain bcr
930− */
931− brp = gsm_QLB[ bcr ];
932−
933− /* Computation of the reconstructed short term residual
934− * signal drp[0..39]
935− */
936− assert(brp != MIN_WORD);
937−
938− for (k = 0; k <= 39; k++) {
939− drpp = GSM_MULT_R( brp, drp[ k - Nr ] );
940− drp[k] = GSM_ADD( erp[k], drpp );
941− }
942−
943− /*
944− * Update of the reconstructed short term residual signal
945− * drp[ -1..-120 ]
946− */
947−
948− for (k = 0; k <= 119; k++) drp[ -120 + k ] = drp[ -80 + k ];
949−}
libgsm/lpc.c+0−339
@@ -1,339 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/lpc.c,v 1.2 2007/11/04 16:32:36 robs Exp $ */
8−
9−#include <stdio.h>
10−#include <assert.h>
11−
12−#include "private.h"
13−
14−#include "gsm.h"
15−
16−/*
17− * 4.2.4 .. 4.2.7 LPC ANALYSIS SECTION
18− */
19−
20−/* 4.2.4 */
21−
22−
23−static void Autocorrelation (
24− word * s, /* [0..159] IN/OUT */
25− longword * L_ACF) /* [0..8] OUT */
26−/*
27− * The goal is to compute the array L_ACF[k]. The signal s[i] must
28− * be scaled in order to avoid an overflow situation.
29− */
30−{
31− register int k, i;
32−
33− word temp, smax, scalauto;
34−
35−#ifdef USE_FLOAT_MUL
36− float float_s[160];
37−#endif
38−
39− /* Dynamic scaling of the array s[0..159]
40− */
41−
42− /* Search for the maximum.
43− */
44− smax = 0;
45− for (k = 0; k <= 159; k++) {
46− temp = GSM_ABS( s[k] );
47− if (temp > smax) smax = temp;
48− }
49−
50− /* Computation of the scaling factor.
51− */
52− if (smax == 0) scalauto = 0;
53− else {
54− assert(smax > 0);
55− scalauto = 4 - gsm_norm( (longword)smax << 16 );/* sub(4,..) */
56− }
57−
58− /* Scaling of the array s[0...159]
59− */
60−
61− if (scalauto > 0) {
62−
63−# ifdef USE_FLOAT_MUL
64−# define SCALE(n) \
65− case n: for (k = 0; k <= 159; k++) \
66− float_s[k] = (float) \
67− (s[k] = GSM_MULT_R(s[k], 16384 >> (n-1)));\
68− break;
69−# else
70−# define SCALE(n) \
71− case n: for (k = 0; k <= 159; k++) \
72− s[k] = GSM_MULT_R( s[k], 16384 >> (n-1) );\
73− break;
74−# endif /* USE_FLOAT_MUL */
75−
76− switch (scalauto) {
77− SCALE(1)
78− SCALE(2)
79− SCALE(3)
80− SCALE(4)
81− }
82−# undef SCALE
83− }
84−# ifdef USE_FLOAT_MUL
85− else for (k = 0; k <= 159; k++) float_s[k] = (float) s[k];
86−# endif
87−
88− /* Compute the L_ACF[..].
89− */
90− {
91−# ifdef USE_FLOAT_MUL
92− register float * sp = float_s;
93− register float sl = *sp;
94−
95−# define STEP(k) L_ACF[k] += (longword)(sl * sp[ -(k) ]);
96−# else
97− word * sp = s;
98− word sl = *sp;
99−
100−# define STEP(k) L_ACF[k] += ((longword)sl * sp[ -(k) ]);
101−# endif
102−
103−# define NEXTI sl = *++sp
104−
105−
106− for (k = 9; k--; L_ACF[k] = 0) ;
107−
108− STEP (0);
109− NEXTI;
110− STEP(0); STEP(1);
111− NEXTI;
112− STEP(0); STEP(1); STEP(2);
113− NEXTI;
114− STEP(0); STEP(1); STEP(2); STEP(3);
115− NEXTI;
116− STEP(0); STEP(1); STEP(2); STEP(3); STEP(4);
117− NEXTI;
118− STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5);
119− NEXTI;
120− STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); STEP(6);
121− NEXTI;
122− STEP(0); STEP(1); STEP(2); STEP(3); STEP(4); STEP(5); STEP(6); STEP(7);
123−
124− for (i = 8; i <= 159; i++) {
125−
126− NEXTI;
127−
128− STEP(0);
129− STEP(1); STEP(2); STEP(3); STEP(4);
130− STEP(5); STEP(6); STEP(7); STEP(8);
131− }
132−
133− for (k = 9; k--; L_ACF[k] <<= 1) ;
134−
135− }
136− /* Rescaling of the array s[0..159]
137− */
138− if (scalauto > 0) {
139− assert(scalauto <= 4);
140− for (k = 160; k--; *s++ <<= scalauto) ;
141− }
142−}
143−
144−#if defined(USE_FLOAT_MUL) && defined(FAST)
145−
146−static void Fast_Autocorrelation (
147− word * s, /* [0..159] IN/OUT */
148− longword * L_ACF) /* [0..8] OUT */
149−{
150− register int k, i;
151− float f_L_ACF[9];
152− float scale;
153−
154− float s_f[160];
155− register float *sf = s_f;
156−
157− for (i = 0; i < 160; ++i) sf[i] = s[i];
158− for (k = 0; k <= 8; k++) {
159− register float L_temp2 = 0;
160− register float *sfl = sf - k;
161− for (i = k; i < 160; ++i) L_temp2 += sf[i] * sfl[i];
162− f_L_ACF[k] = L_temp2;
163− }
164− scale = MAX_LONGWORD / f_L_ACF[0];
165−
166− for (k = 0; k <= 8; k++) {
167− L_ACF[k] = f_L_ACF[k] * scale;
168− }
169−}
170−#endif /* defined (USE_FLOAT_MUL) && defined (FAST) */
171−
172−/* 4.2.5 */
173−
174−static void Reflection_coefficients (
175− longword * L_ACF, /* 0...8 IN */
176− register word * r /* 0...7 OUT */
177−)
178−{
179− register int i, m, n;
180− register word temp;
181− register longword ltmp;
182− word ACF[9]; /* 0..8 */
183− word P[ 9]; /* 0..8 */
184− word K[ 9]; /* 2..8 */
185−
186− /* Schur recursion with 16 bits arithmetic.
187− */
188−
189− if (L_ACF[0] == 0) {
190− for (i = 8; i--; *r++ = 0) ;
191− return;
192− }
193−
194− assert( L_ACF[0] != 0 );
195− temp = gsm_norm( L_ACF[0] );
196−
197− assert(temp >= 0 && temp < 32);
198−
199− /* ? overflow ? */
200− for (i = 0; i <= 8; i++) ACF[i] = SASR( L_ACF[i] << temp, 16 );
201−
202− /* Initialize array P[..] and K[..] for the recursion.
203− */
204−
205− for (i = 1; i <= 7; i++) K[ i ] = ACF[ i ];
206− for (i = 0; i <= 8; i++) P[ i ] = ACF[ i ];
207−
208− /* Compute reflection coefficients
209− */
210− for (n = 1; n <= 8; n++, r++) {
211−
212− temp = P[1];
213− temp = GSM_ABS(temp);
214− if (P[0] < temp) {
215− for (i = n; i <= 8; i++) *r++ = 0;
216− return;
217− }
218−
219− *r = gsm_div( temp, P[0] );
220−
221− assert(*r >= 0);
222− if (P[1] > 0) *r = -*r; /* r[n] = sub(0, r[n]) */
223− assert (*r != MIN_WORD);
224− if (n == 8) return;
225−
226− /* Schur recursion
227− */
228− temp = GSM_MULT_R( P[1], *r );
229− P[0] = GSM_ADD( P[0], temp );
230−
231− for (m = 1; m <= 8 - n; m++) {
232− temp = GSM_MULT_R( K[ m ], *r );
233− P[m] = GSM_ADD( P[ m+1 ], temp );
234−
235− temp = GSM_MULT_R( P[ m+1 ], *r );
236− K[m] = GSM_ADD( K[ m ], temp );
237− }
238− }
239−}
240−
241−/* 4.2.6 */
242−
243−static void Transformation_to_Log_Area_Ratios (
244− register word * r /* 0..7 IN/OUT */
245−)
246−/*
247− * The following scaling for r[..] and LAR[..] has been used:
248− *
249− * r[..] = integer( real_r[..]*32768. ); -1 <= real_r < 1.
250− * LAR[..] = integer( real_LAR[..] * 16384 );
251− * with -1.625 <= real_LAR <= 1.625
252− */
253−{
254− register word temp;
255− register int i;
256−
257−
258− /* Computation of the LAR[0..7] from the r[0..7]
259− */
260− for (i = 1; i <= 8; i++, r++) {
261−
262− temp = *r;
263− temp = GSM_ABS(temp);
264− assert(temp >= 0);
265−
266− if (temp < 22118) {
267− temp >>= 1;
268− } else if (temp < 31130) {
269− assert( temp >= 11059 );
270− temp -= 11059;
271− } else {
272− assert( temp >= 26112 );
273− temp -= 26112;
274− temp <<= 2;
275− }
276−
277− *r = *r < 0 ? -temp : temp;
278− assert( *r != MIN_WORD );
279− }
280−}
281−
282−/* 4.2.7 */
283−
284−static void Quantization_and_coding (
285− register word * LAR /* [0..7] IN/OUT */
286−)
287−{
288− register word temp;
289− longword ltmp;
290−
291−
292− /* This procedure needs four tables; the following equations
293− * give the optimum scaling for the constants:
294− *
295− * A[0..7] = integer( real_A[0..7] * 1024 )
296− * B[0..7] = integer( real_B[0..7] * 512 )
297− * MAC[0..7] = maximum of the LARc[0..7]
298− * MIC[0..7] = minimum of the LARc[0..7]
299− */
300−
301−# undef STEP
302−# define STEP( A, B, MAC, MIC ) \
303− temp = GSM_MULT( A, *LAR ); \
304− temp = GSM_ADD( temp, B ); \
305− temp = GSM_ADD( temp, 256 ); \
306− temp = SASR( temp, 9 ); \
307− *LAR = temp>MAC ? MAC - MIC : (temp<MIC ? 0 : temp - MIC); \
308− LAR++;
309−
310− STEP( 20480, 0, 31, -32 );
311− STEP( 20480, 0, 31, -32 );
312− STEP( 20480, 2048, 15, -16 );
313− STEP( 20480, -2560, 15, -16 );
314−
315− STEP( 13964, 94, 7, -8 );
316− STEP( 15360, -1792, 7, -8 );
317− STEP( 8534, -341, 3, -4 );
318− STEP( 9036, -1144, 3, -4 );
319−
320−# undef STEP
321−}
322−
323−void Gsm_LPC_Analysis (
324− struct gsm_state *S,
325− word * s, /* 0..159 signals IN/OUT */
326− word * LARc) /* 0..7 LARc's OUT */
327−{
328− longword L_ACF[9];
329− (void)S; /* Denotes intentionally unused */
330−
331−#if defined(USE_FLOAT_MUL) && defined(FAST)
332− if (S->fast) Fast_Autocorrelation (s, L_ACF );
333− else
334−#endif
335− Autocorrelation (s, L_ACF );
336− Reflection_coefficients (L_ACF, LARc );
337− Transformation_to_Log_Area_Ratios (LARc);
338− Quantization_and_coding (LARc);
339−}
libgsm/preprocess.c+0−112
@@ -1,112 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/preprocess.c,v 1.1 2007/09/06 16:50:55 cbagwell Exp $ */
8−
9−#include <stdio.h>
10−#include <assert.h>
11−
12−#include "private.h"
13−
14−#include "gsm.h"
15−
16−/* 4.2.0 .. 4.2.3 PREPROCESSING SECTION
17− *
18− * After A-law to linear conversion (or directly from the
19− * Ato D converter) the following scaling is assumed for
20− * input to the RPE-LTP algorithm:
21− *
22− * in: 0.1.....................12
23− * S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.*
24− *
25− * Where S is the sign bit, v a valid bit, and * a "don't care" bit.
26− * The original signal is called sop[..]
27− *
28− * out: 0.1................... 12
29− * S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0
30− */
31−
32−
33−void Gsm_Preprocess (
34− struct gsm_state * S,
35− word * s,
36− word * so ) /* [0..159] IN/OUT */
37−{
38−
39− word z1 = S->z1;
40− longword L_z2 = S->L_z2;
41− word mp = S->mp;
42−
43− word s1;
44− longword L_s2;
45−
46− longword L_temp;
47−
48− word msp, lsp;
49− word SO;
50−
51− longword ltmp; /* for ADD */
52− ulongword utmp; /* for L_ADD */
53−
54− register int k = 160;
55−
56− while (k--) {
57−
58− /* 4.2.1 Downscaling of the input signal
59− */
60− SO = SASR( *s, 3 ) << 2;
61− s++;
62−
63− assert (SO >= -0x4000); /* downscaled by */
64− assert (SO <= 0x3FFC); /* previous routine. */
65−
66−
67− /* 4.2.2 Offset compensation
68− *
69− * This part implements a high-pass filter and requires extended
70− * arithmetic precision for the recursive part of this filter.
71− * The input of this procedure is the array so[0...159] and the
72− * output the array sof[ 0...159 ].
73− */
74− /* Compute the non-recursive part
75− */
76−
77− s1 = SO - z1; /* s1 = gsm_sub( *so, z1 ); */
78− z1 = SO;
79−
80− assert(s1 != MIN_WORD);
81−
82− /* Compute the recursive part
83− */
84− L_s2 = s1;
85− L_s2 <<= 15;
86−
87− /* Execution of a 31 bv 16 bits multiplication
88− */
89−
90− msp = SASR( L_z2, 15 );
91− lsp = L_z2-((longword)msp<<15); /* gsm_L_sub(L_z2,(msp<<15)); */
92−
93− L_s2 += GSM_MULT_R( lsp, 32735 );
94− L_temp = (longword)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/
95− L_z2 = GSM_L_ADD( L_temp, L_s2 );
96−
97− /* Compute sof[k] with rounding
98− */
99− L_temp = GSM_L_ADD( L_z2, 16384 );
100−
101− /* 4.2.3 Preemphasis
102− */
103−
104− msp = GSM_MULT_R( mp, -28180 );
105− mp = SASR( L_temp, 15 );
106− *so++ = GSM_ADD( mp, msp );
107− }
108−
109− S->z1 = z1;
110− S->L_z2 = L_z2;
111− S->mp = mp;
112−}
libgsm/private.h+0−265
@@ -1,265 +0,0 @@
1−#include "aliases.h"
2−/*
3− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
4− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
5− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
6− */
7−
8−/*$Header: /cvsroot/sox/sox/libgsm/private.h,v 1.3 2008/03/21 13:34:21 robs Exp $*/
9−
10−#ifndef PRIVATE_H
11−#define PRIVATE_H
12−
13−typedef short word; /* 16 bit signed int */
14−typedef long longword; /* 32 bit signed int */
15−
16−typedef unsigned short uword; /* unsigned word */
17−typedef unsigned long ulongword; /* unsigned longword */
18−
19−struct gsm_state {
20−
21− word dp0[ 280 ];
22−
23− word z1; /* preprocessing.c, Offset_com. */
24− longword L_z2; /* Offset_com. */
25− int mp; /* Preemphasis */
26−
27− word u[8]; /* short_term_aly_filter.c */
28− word LARpp[2][8]; /* */
29− word j; /* */
30−
31− word ltp_cut; /* long_term.c, LTP crosscorr. */
32− word nrp; /* 40 */ /* long_term.c, synthesis */
33− word v[9]; /* short_term.c, synthesis */
34− word msr; /* decoder.c, Postprocessing */
35−
36− char verbose; /* only used if !NDEBUG */
37− char fast; /* only used if FAST */
38−
39− char wav_fmt; /* only used if WAV49 defined */
40− unsigned char frame_index; /* odd/even chaining */
41− unsigned char frame_chain; /* half-byte to carry forward */
42−};
43−
44−
45−#define MIN_WORD (-32767 - 1)
46−#define MAX_WORD 32767
47−
48−#define MIN_LONGWORD (-2147483647 - 1)
49−#define MAX_LONGWORD 2147483647
50−
51−#ifdef SASR /* flag: >> is a signed arithmetic shift right */
52−#undef SASR
53−#define SASR(x, by) ((x) >> (by))
54−#else
55−#define SASR(x, by) ((x) >= 0 ? (x) >> (by) : (~(-((x) + 1) >> (by))))
56−#endif /* SASR */
57−
58−/*
59− * Prototypes from add.c
60− */
61−extern word gsm_mult (word a, word b);
62−extern longword gsm_L_mult (word a, word b);
63−extern word gsm_mult_r (word a, word b);
64−
65−extern word gsm_div (word num, word denum);
66−
67−extern word gsm_add ( word a, word b );
68−extern longword gsm_L_add ( longword a, longword b );
69−
70−extern word gsm_sub (word a, word b);
71−extern longword gsm_L_sub (longword a, longword b);
72−
73−extern word gsm_abs (word a);
74−
75−extern word gsm_norm ( longword a );
76−
77−extern longword gsm_L_asl (longword a, int n);
78−extern word gsm_asl (word a, int n);
79−
80−extern longword gsm_L_asr (longword a, int n);
81−extern word gsm_asr (word a, int n);
82−
83−/*
84− * Inlined functions from add.h
85− */
86−
87−/*
88− * #define GSM_MULT_R(a, b) (* word a, word b, !(a == b == MIN_WORD) *) \
89− * (0x0FFFF & SASR(((longword)(a) * (longword)(b) + 16384), 15))
90− */
91−#define GSM_MULT_R(a, b) /* word a, word b, !(a == b == MIN_WORD) */ \
92− (SASR( ((longword)(a) * (longword)(b) + 16384), 15 ))
93−
94−# define GSM_MULT(a,b) /* word a, word b, !(a == b == MIN_WORD) */ \
95− (SASR( ((longword)(a) * (longword)(b)), 15 ))
96−
97−# define GSM_L_MULT(a, b) /* word a, word b */ \
98− (((longword)(a) * (longword)(b)) << 1)
99−
100−# define GSM_L_ADD(a, b) \
101− ( (a) < 0 ? ( (b) >= 0 ? (a) + (b) \
102− : (utmp = (ulongword)-((a) + 1) + (ulongword)-((b) + 1)) \
103− >= MAX_LONGWORD ? MIN_LONGWORD : -(longword)utmp-2 ) \
104− : ((b) <= 0 ? (a) + (b) \
105− : (utmp = (ulongword)(a) + (ulongword)(b)) >= MAX_LONGWORD \
106− ? MAX_LONGWORD : (longword)utmp))
107−
108−/*
109− * # define GSM_ADD(a, b) \
110− * ((ltmp = (longword)(a) + (longword)(b)) >= MAX_WORD \
111− * ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
112− */
113−/* Nonportable, but faster: */
114−
115−#define GSM_ADD(a, b) \
116− ((ulongword)((ltmp = (longword)(a) + (longword)(b)) - MIN_WORD) > \
117− MAX_WORD - MIN_WORD ? (ltmp > 0 ? MAX_WORD : MIN_WORD) : ltmp)
118−
119−# define GSM_SUB(a, b) \
120− ((ltmp = (longword)(a) - (longword)(b)) >= MAX_WORD \
121− ? MAX_WORD : ltmp <= MIN_WORD ? MIN_WORD : ltmp)
122−
123−# define GSM_ABS(a) ((a) < 0 ? ((a) == MIN_WORD ? MAX_WORD : -(a)) : (a))
124−
125−/* Use these if necessary:
126−
127−# define GSM_MULT_R(a, b) gsm_mult_r(a, b)
128−# define GSM_MULT(a, b) gsm_mult(a, b)
129−# define GSM_L_MULT(a, b) gsm_L_mult(a, b)
130−
131−# define GSM_L_ADD(a, b) gsm_L_add(a, b)
132−# define GSM_ADD(a, b) gsm_add(a, b)
133−# define GSM_SUB(a, b) gsm_sub(a, b)
134−
135−# define GSM_ABS(a) gsm_abs(a)
136−
137−*/
138−
139−/*
140− * More prototypes from implementations..
141− */
142−extern void Gsm_Coder (
143− struct gsm_state * S,
144− word * s, /* [0..159] samples IN */
145− word * LARc, /* [0..7] LAR coefficients OUT */
146− word * Nc, /* [0..3] LTP lag OUT */
147− word * bc, /* [0..3] coded LTP gain OUT */
148− word * Mc, /* [0..3] RPE grid selection OUT */
149− word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
150− word * xMc /* [13*4] normalized RPE samples OUT */);
151−
152−extern void Gsm_Long_Term_Predictor ( /* 4x for 160 samples */
153− struct gsm_state * S,
154− word * d, /* [0..39] residual signal IN */
155− word * dp, /* [-120..-1] d' IN */
156− word * e, /* [0..40] OUT */
157− word * dpp, /* [0..40] OUT */
158− word * Nc, /* correlation lag OUT */
159− word * bc /* gain factor OUT */);
160−
161−extern void Gsm_LPC_Analysis (
162− struct gsm_state * S,
163− word * s, /* 0..159 signals IN/OUT */
164− word * LARc); /* 0..7 LARc's OUT */
165−
166−extern void Gsm_Preprocess (
167− struct gsm_state * S,
168− word * s, word * so);
169−
170−extern void Gsm_Encoding (
171− struct gsm_state * S,
172− word * e,
173− word * ep,
174− word * xmaxc,
175− word * Mc,
176− word * xMc);
177−
178−extern void Gsm_Short_Term_Analysis_Filter (
179− struct gsm_state * S,
180− word * LARc, /* coded log area ratio [0..7] IN */
181− word * d /* st res. signal [0..159] IN/OUT */);
182−
183−extern void Gsm_Decoder (
184− struct gsm_state * S,
185− word * LARcr, /* [0..7] IN */
186− word * Ncr, /* [0..3] IN */
187− word * bcr, /* [0..3] IN */
188− word * Mcr, /* [0..3] IN */
189− word * xmaxcr, /* [0..3] IN */
190− word * xMcr, /* [0..13*4] IN */
191− word * s); /* [0..159] OUT */
192−
193−extern void Gsm_Decoding (
194− struct gsm_state * S,
195− word xmaxcr,
196− word Mcr,
197− word * xMcr, /* [0..12] IN */
198− word * erp); /* [0..39] OUT */
199−
200−extern void Gsm_Long_Term_Synthesis_Filtering (
201− struct gsm_state* S,
202− word Ncr,
203− word bcr,
204− word * erp, /* [0..39] IN */
205− word * drp); /* [-120..-1] IN, [0..40] OUT */
206−
207−void Gsm_RPE_Decoding (
208− struct gsm_state *S,
209− word xmaxcr,
210− word Mcr,
211− word * xMcr, /* [0..12], 3 bits IN */
212− word * erp); /* [0..39] OUT */
213−
214−void Gsm_RPE_Encoding (
215− struct gsm_state * S,
216− word * e, /* -5..-1][0..39][40..44 IN/OUT */
217− word * xmaxc, /* OUT */
218− word * Mc, /* OUT */
219− word * xMc); /* [0..12] OUT */
220−
221−extern void Gsm_Short_Term_Synthesis_Filter (
222− struct gsm_state * S,
223− word * LARcr, /* log area ratios [0..7] IN */
224− word * drp, /* received d [0...39] IN */
225− word * s); /* signal s [0..159] OUT */
226−
227−extern void Gsm_Update_of_reconstructed_short_time_residual_signal (
228− word * dpp, /* [0...39] IN */
229− word * ep, /* [0...39] IN */
230− word * dp); /* [-120...-1] IN/OUT */
231−
232−/*
233− * Tables from table.c
234− */
235−#ifndef GSM_TABLE_C
236−
237−extern word gsm_A[8], gsm_B[8], gsm_MIC[8], gsm_MAC[8];
238−extern word gsm_INVA[8];
239−extern word gsm_DLB[4], gsm_QLB[4];
240−extern word gsm_H[11];
241−extern word gsm_NRFAC[8];
242−extern word gsm_FAC[8];
243−
244−#endif /* GSM_TABLE_C */
245−
246−/*
247− * Debugging
248− */
249−#ifdef NDEBUG
250−
251−# define gsm_debug_words(a, b, c, d) /* nil */
252−# define gsm_debug_longwords(a, b, c, d) /* nil */
253−# define gsm_debug_word(a, b) /* nil */
254−# define gsm_debug_longword(a, b) /* nil */
255−
256−#else /* !NDEBUG => DEBUG */
257−
258− extern void gsm_debug_words (char * name, int, int, word *);
259− extern void gsm_debug_longwords (char * name, int, int, longword *);
260− extern void gsm_debug_longword (char * name, longword);
261− extern void gsm_debug_word (char * name, word);
262−
263−#endif /* !NDEBUG */
264−
265−#endif /* PRIVATE_H */
libgsm/rpe.c+0−489
@@ -1,489 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/rpe.c,v 1.2 2007/11/04 16:32:36 robs Exp $ */
8−
9−#include <stdio.h>
10−#include <assert.h>
11−
12−#include "private.h"
13−
14−#include "gsm.h"
15−
16−/* 4.2.13 .. 4.2.17 RPE ENCODING SECTION
17− */
18−
19−/* 4.2.13 */
20−
21−static void Weighting_filter (
22− register word * e, /* signal [-5..0.39.44] IN */
23− word * x /* signal [0..39] OUT */
24−)
25−/*
26− * The coefficients of the weighting filter are stored in a table
27− * (see table 4.4). The following scaling is used:
28− *
29− * H[0..10] = integer( real_H[ 0..10] * 8192 );
30− */
31−{
32− /* word wt[ 50 ]; */
33−
34− register longword L_result;
35− register int k /* , i */ ;
36−
37− /* Initialization of a temporary working array wt[0...49]
38− */
39−
40− /* for (k = 0; k <= 4; k++) wt[k] = 0;
41− * for (k = 5; k <= 44; k++) wt[k] = *e++;
42− * for (k = 45; k <= 49; k++) wt[k] = 0;
43− *
44− * (e[-5..-1] and e[40..44] are allocated by the caller,
45− * are initially zero and are not written anywhere.)
46− */
47− e -= 5;
48−
49− /* Compute the signal x[0..39]
50− */
51− for (k = 0; k <= 39; k++) {
52−
53− L_result = 8192 >> 1;
54−
55− /* for (i = 0; i <= 10; i++) {
56− * L_temp = GSM_L_MULT( wt[k+i], gsm_H[i] );
57− * L_result = GSM_L_ADD( L_result, L_temp );
58− * }
59− */
60−
61−#undef STEP
62−#define STEP( i, H ) (e[ k + i ] * (longword)H)
63−
64− /* Every one of these multiplications is done twice --
65− * but I don't see an elegant way to optimize this.
66− * Do you?
67− */
68−
69−#ifdef STUPID_COMPILER
70− L_result += STEP( 0, -134 ) ;
71− L_result += STEP( 1, -374 ) ;
72− /* + STEP( 2, 0 ) */
73− L_result += STEP( 3, 2054 ) ;
74− L_result += STEP( 4, 5741 ) ;
75− L_result += STEP( 5, 8192 ) ;
76− L_result += STEP( 6, 5741 ) ;
77− L_result += STEP( 7, 2054 ) ;
78− /* + STEP( 8, 0 ) */
79− L_result += STEP( 9, -374 ) ;
80− L_result += STEP( 10, -134 ) ;
81−#else
82− L_result +=
83− STEP( 0, -134 )
84− + STEP( 1, -374 )
85− /* + STEP( 2, 0 ) */
86− + STEP( 3, 2054 )
87− + STEP( 4, 5741 )
88− + STEP( 5, 8192 )
89− + STEP( 6, 5741 )
90− + STEP( 7, 2054 )
91− /* + STEP( 8, 0 ) */
92− + STEP( 9, -374 )
93− + STEP(10, -134 )
94− ;
95−#endif
96−
97− /* L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x2) *)
98− * L_result = GSM_L_ADD( L_result, L_result ); (* scaling(x4) *)
99− *
100− * x[k] = SASR( L_result, 16 );
101− */
102−
103− /* 2 adds vs. >>16 => 14, minus one shift to compensate for
104− * those we lost when replacing L_MULT by '*'.
105− */
106−
107− L_result = SASR( L_result, 13 );
108− x[k] = ( L_result < MIN_WORD ? MIN_WORD
109− : (L_result > MAX_WORD ? MAX_WORD : L_result ));
110− }
111−}
112−
113−/* 4.2.14 */
114−
115−static void RPE_grid_selection (
116− word * x, /* [0..39] IN */
117− word * xM, /* [0..12] OUT */
118− word * Mc_out /* OUT */
119−)
120−/*
121− * The signal x[0..39] is used to select the RPE grid which is
122− * represented by Mc.
123− */
124−{
125− /* register word temp1; */
126− register int /* m, */ i;
127− register longword L_result, L_temp;
128− longword EM; /* xxx should be L_EM? */
129− word Mc;
130−
131− longword L_common_0_3;
132−
133− EM = 0;
134− Mc = 0;
135−
136− /* for (m = 0; m <= 3; m++) {
137− * L_result = 0;
138− *
139− *
140− * for (i = 0; i <= 12; i++) {
141− *
142− * temp1 = SASR( x[m + 3*i], 2 );
143− *
144− * assert(temp1 != MIN_WORD);
145− *
146− * L_temp = GSM_L_MULT( temp1, temp1 );
147− * L_result = GSM_L_ADD( L_temp, L_result );
148− * }
149− *
150− * if (L_result > EM) {
151− * Mc = m;
152− * EM = L_result;
153− * }
154− * }
155− */
156−
157−#undef STEP
158−#define STEP( m, i ) L_temp = SASR( x[m + 3 * i], 2 ); \
159− L_result += L_temp * L_temp;
160−
161− /* common part of 0 and 3 */
162−
163− L_result = 0;
164− STEP( 0, 1 ); STEP( 0, 2 ); STEP( 0, 3 ); STEP( 0, 4 );
165− STEP( 0, 5 ); STEP( 0, 6 ); STEP( 0, 7 ); STEP( 0, 8 );
166− STEP( 0, 9 ); STEP( 0, 10); STEP( 0, 11); STEP( 0, 12);
167− L_common_0_3 = L_result;
168−
169− /* i = 0 */
170−
171− STEP( 0, 0 );
172− L_result <<= 1; /* implicit in L_MULT */
173− EM = L_result;
174−
175− /* i = 1 */
176−
177− L_result = 0;
178− STEP( 1, 0 );
179− STEP( 1, 1 ); STEP( 1, 2 ); STEP( 1, 3 ); STEP( 1, 4 );
180− STEP( 1, 5 ); STEP( 1, 6 ); STEP( 1, 7 ); STEP( 1, 8 );
181− STEP( 1, 9 ); STEP( 1, 10); STEP( 1, 11); STEP( 1, 12);
182− L_result <<= 1;
183− if (L_result > EM) {
184− Mc = 1;
185− EM = L_result;
186− }
187−
188− /* i = 2 */
189−
190− L_result = 0;
191− STEP( 2, 0 );
192− STEP( 2, 1 ); STEP( 2, 2 ); STEP( 2, 3 ); STEP( 2, 4 );
193− STEP( 2, 5 ); STEP( 2, 6 ); STEP( 2, 7 ); STEP( 2, 8 );
194− STEP( 2, 9 ); STEP( 2, 10); STEP( 2, 11); STEP( 2, 12);
195− L_result <<= 1;
196− if (L_result > EM) {
197− Mc = 2;
198− EM = L_result;
199− }
200−
201− /* i = 3 */
202−
203− L_result = L_common_0_3;
204− STEP( 3, 12 );
205− L_result <<= 1;
206− if (L_result > EM) {
207− Mc = 3;
208− EM = L_result;
209− }
210−
211− /**/
212−
213− /* Down-sampling by a factor 3 to get the selected xM[0..12]
214− * RPE sequence.
215− */
216− for (i = 0; i <= 12; i ++) xM[i] = x[Mc + 3*i];
217− *Mc_out = Mc;
218−}
219−
220−/* 4.12.15 */
221−
222−static void APCM_quantization_xmaxc_to_exp_mant (
223− word xmaxc, /* IN */
224− word * exp_out, /* OUT */
225− word * mant_out ) /* OUT */
226−{
227− word exp, mant;
228−
229− /* Compute exponent and mantissa of the decoded version of xmaxc
230− */
231−
232− exp = 0;
233− if (xmaxc > 15) exp = SASR(xmaxc, 3) - 1;
234− mant = xmaxc - (exp << 3);
235−
236− if (mant == 0) {
237− exp = -4;
238− mant = 7;
239− }
240− else {
241− while (mant <= 7) {
242− mant = mant << 1 | 1;
243− exp--;
244− }
245− mant -= 8;
246− }
247−
248− assert( exp >= -4 && exp <= 6 );
249− assert( mant >= 0 && mant <= 7 );
250−
251− *exp_out = exp;
252− *mant_out = mant;
253−}
254−
255−static void APCM_quantization (
256− word * xM, /* [0..12] IN */
257−
258− word * xMc, /* [0..12] OUT */
259− word * mant_out, /* OUT */
260− word * exp_out, /* OUT */
261− word * xmaxc_out /* OUT */
262−)
263−{
264− int i, itest;
265−
266− word xmax, xmaxc, temp, temp1, temp2;
267− word exp, mant;
268−
269−
270− /* Find the maximum absolute value xmax of xM[0..12].
271− */
272−
273− xmax = 0;
274− for (i = 0; i <= 12; i++) {
275− temp = xM[i];
276− temp = GSM_ABS(temp);
277− if (temp > xmax) xmax = temp;
278− }
279−
280− /* Qantizing and coding of xmax to get xmaxc.
281− */
282−
283− exp = 0;
284− temp = SASR( xmax, 9 );
285− itest = 0;
286−
287− for (i = 0; i <= 5; i++) {
288−
289− itest |= (temp <= 0);
290− temp = SASR( temp, 1 );
291−
292− assert(exp <= 5);
293− if (itest == 0) exp++; /* exp = add (exp, 1) */
294− }
295−
296− assert(exp <= 6 && exp >= 0);
297− temp = exp + 5;
298−
299− assert(temp <= 11 && temp >= 0);
300− xmaxc = gsm_add( SASR(xmax, temp), exp << 3 );
301−
302− /* Quantizing and coding of the xM[0..12] RPE sequence
303− * to get the xMc[0..12]
304− */
305−
306− APCM_quantization_xmaxc_to_exp_mant( xmaxc, &exp, &mant );
307−
308− /* This computation uses the fact that the decoded version of xmaxc
309− * can be calculated by using the exponent and the mantissa part of
310− * xmaxc (logarithmic table).
311− * So, this method avoids any division and uses only a scaling
312− * of the RPE samples by a function of the exponent. A direct
313− * multiplication by the inverse of the mantissa (NRFAC[0..7]
314− * found in table 4.5) gives the 3 bit coded version xMc[0..12]
315− * of the RPE samples.
316− */
317−
318−
319− /* Direct computation of xMc[0..12] using table 4.5
320− */
321−
322− assert( exp <= 4096 && exp >= -4096);
323− assert( mant >= 0 && mant <= 7 );
324−
325− temp1 = 6 - exp; /* normalization by the exponent */
326− temp2 = gsm_NRFAC[ mant ]; /* inverse mantissa */
327−
328− for (i = 0; i <= 12; i++) {
329−
330− assert(temp1 >= 0 && temp1 < 16);
331−
332− temp = xM[i] << temp1;
333− temp = GSM_MULT( temp, temp2 );
334− temp = SASR(temp, 12);
335− xMc[i] = temp + 4; /* see note below */
336− }
337−
338− /* NOTE: This equation is used to make all the xMc[i] positive.
339− */
340−
341− *mant_out = mant;
342− *exp_out = exp;
343− *xmaxc_out = xmaxc;
344−}
345−
346−/* 4.2.16 */
347−
348−static void APCM_inverse_quantization (
349− register word * xMc, /* [0..12] IN */
350− word mant,
351− word exp,
352− register word * xMp) /* [0..12] OUT */
353−/*
354− * This part is for decoding the RPE sequence of coded xMc[0..12]
355− * samples to obtain the xMp[0..12] array. Table 4.6 is used to get
356− * the mantissa of xmaxc (FAC[0..7]).
357− */
358−{
359− int i;
360− word temp, temp1, temp2, temp3;
361− longword ltmp;
362−
363− assert( mant >= 0 && mant <= 7 );
364−
365− temp1 = gsm_FAC[ mant ]; /* see 4.2-15 for mant */
366− temp2 = gsm_sub( 6, exp ); /* see 4.2-15 for exp */
367− temp3 = gsm_asl( 1, gsm_sub( temp2, 1 ));
368−
369− for (i = 13; i--;) {
370−
371− assert( *xMc <= 7 && *xMc >= 0 ); /* 3 bit unsigned */
372−
373− /* temp = gsm_sub( *xMc++ << 1, 7 ); */
374− temp = (*xMc++ << 1) - 7; /* restore sign */
375− assert( temp <= 7 && temp >= -7 ); /* 4 bit signed */
376−
377− temp <<= 12; /* 16 bit signed */
378− temp = GSM_MULT_R( temp1, temp );
379− temp = GSM_ADD( temp, temp3 );
380− *xMp++ = gsm_asr( temp, temp2 );
381− }
382−}
383−
384−/* 4.2.17 */
385−
386−static void RPE_grid_positioning (
387− word Mc, /* grid position IN */
388− register word * xMp, /* [0..12] IN */
389− register word * ep /* [0..39] OUT */
390−)
391−/*
392− * This procedure computes the reconstructed long term residual signal
393− * ep[0..39] for the LTP analysis filter. The inputs are the Mc
394− * which is the grid position selection and the xMp[0..12] decoded
395− * RPE samples which are upsampled by a factor of 3 by inserting zero
396− * values.
397− */
398−{
399− int i = 13;
400−
401− assert(0 <= Mc && Mc <= 3);
402−
403− switch (Mc) {
404− case 3: *ep++ = 0;
405− case 2: do {
406− *ep++ = 0;
407− case 1: *ep++ = 0;
408− case 0: *ep++ = *xMp++;
409− } while (--i);
410− }
411− while (++Mc < 4) *ep++ = 0;
412−
413− /*
414−
415− int i, k;
416− for (k = 0; k <= 39; k++) ep[k] = 0;
417− for (i = 0; i <= 12; i++) {
418− ep[ Mc + (3*i) ] = xMp[i];
419− }
420− */
421−}
422−
423−/* 4.2.18 */
424−
425−/* This procedure adds the reconstructed long term residual signal
426− * ep[0..39] to the estimated signal dpp[0..39] from the long term
427− * analysis filter to compute the reconstructed short term residual
428− * signal dp[-40..-1]; also the reconstructed short term residual
429− * array dp[-120..-41] is updated.
430− */
431−
432−#if 0 /* Has been inlined in code.c */
433−void Gsm_Update_of_reconstructed_short_time_residual_signal P3((dpp, ep, dp),
434− word * dpp, /* [0...39] IN */
435− word * ep, /* [0...39] IN */
436− word * dp) /* [-120...-1] IN/OUT */
437−{
438− int k;
439−
440− for (k = 0; k <= 79; k++)
441− dp[ -120 + k ] = dp[ -80 + k ];
442−
443− for (k = 0; k <= 39; k++)
444− dp[ -40 + k ] = gsm_add( ep[k], dpp[k] );
445−}
446−#endif /* Has been inlined in code.c */
447−
448−void Gsm_RPE_Encoding (
449−
450− struct gsm_state * S,
451−
452− word * e, /* -5..-1][0..39][40..44 IN/OUT */
453− word * xmaxc, /* OUT */
454− word * Mc, /* OUT */
455− word * xMc) /* [0..12] OUT */
456−{
457− word x[40];
458− word xM[13], xMp[13];
459− word mant, exp;
460−
461− (void)S; /* Denotes intentionally unused */
462− Weighting_filter(e, x);
463− RPE_grid_selection(x, xM, Mc);
464−
465− APCM_quantization( xM, xMc, &mant, &exp, xmaxc);
466− APCM_inverse_quantization( xMc, mant, exp, xMp);
467−
468− RPE_grid_positioning( *Mc, xMp, e );
469−
470−}
471−
472−void Gsm_RPE_Decoding (
473− struct gsm_state * S,
474−
475− word xmaxcr,
476− word Mcr,
477− word * xMcr, /* [0..12], 3 bits IN */
478− word * erp /* [0..39] OUT */
479−)
480−{
481− word exp, mant;
482− word xMp[ 13 ];
483−
484− (void)S; /* Denotes intentionally unused */
485− APCM_quantization_xmaxc_to_exp_mant( xmaxcr, &exp, &mant );
486− APCM_inverse_quantization( xMcr, mant, exp, xMp );
487− RPE_grid_positioning( Mcr, xMp, erp );
488−
489−}
libgsm/short_term.c+0−428
@@ -1,428 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/short_term.c,v 1.1 2007/09/06 16:50:56 cbagwell Exp $ */
8−
9−#include <stdio.h>
10−#include <assert.h>
11−
12−#include "private.h"
13−
14−#include "gsm.h"
15−
16−/*
17− * SHORT TERM ANALYSIS FILTERING SECTION
18− */
19−
20−/* 4.2.8 */
21−
22−static void Decoding_of_the_coded_Log_Area_Ratios (
23− word * LARc, /* coded log area ratio [0..7] IN */
24− word * LARpp) /* out: decoded .. */
25−{
26− register word temp1 /* , temp2 */;
27− register long ltmp; /* for GSM_ADD */
28−
29− /* This procedure requires for efficient implementation
30− * two tables.
31− *
32− * INVA[1..8] = integer( (32768 * 8) / real_A[1..8])
33− * MIC[1..8] = minimum value of the LARc[1..8]
34− */
35−
36− /* Compute the LARpp[1..8]
37− */
38−
39− /* for (i = 1; i <= 8; i++, B++, MIC++, INVA++, LARc++, LARpp++) {
40− *
41− * temp1 = GSM_ADD( *LARc, *MIC ) << 10;
42− * temp2 = *B << 1;
43− * temp1 = GSM_SUB( temp1, temp2 );
44− *
45− * assert(*INVA != MIN_WORD);
46− *
47− * temp1 = GSM_MULT_R( *INVA, temp1 );
48− * *LARpp = GSM_ADD( temp1, temp1 );
49− * }
50− */
51−
52−#undef STEP
53−#define STEP( B, MIC, INVA ) \
54− temp1 = GSM_ADD( *LARc++, MIC ) << 10; \
55− temp1 = GSM_SUB( temp1, B << 1 ); \
56− temp1 = GSM_MULT_R( INVA, temp1 ); \
57− *LARpp++ = GSM_ADD( temp1, temp1 );
58−
59− STEP( 0, -32, 13107 );
60− STEP( 0, -32, 13107 );
61− STEP( 2048, -16, 13107 );
62− STEP( -2560, -16, 13107 );
63−
64− STEP( 94, -8, 19223 );
65− STEP( -1792, -8, 17476 );
66− STEP( -341, -4, 31454 );
67− STEP( -1144, -4, 29708 );
68−
69− /* NOTE: the addition of *MIC is used to restore
70− * the sign of *LARc.
71− */
72−}
73−
74−/* 4.2.9 */
75−/* Computation of the quantized reflection coefficients
76− */
77−
78−/* 4.2.9.1 Interpolation of the LARpp[1..8] to get the LARp[1..8]
79− */
80−
81−/*
82− * Within each frame of 160 analyzed speech samples the short term
83− * analysis and synthesis filters operate with four different sets of
84− * coefficients, derived from the previous set of decoded LARs(LARpp(j-1))
85− * and the actual set of decoded LARs (LARpp(j))
86− *
87− * (Initial value: LARpp(j-1)[1..8] = 0.)
88− */
89−
90−static void Coefficients_0_12 (
91− register word * LARpp_j_1,
92− register word * LARpp_j,
93− register word * LARp)
94−{
95− register int i;
96− register longword ltmp;
97−
98− for (i = 1; i <= 8; i++, LARp++, LARpp_j_1++, LARpp_j++) {
99− *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
100− *LARp = GSM_ADD( *LARp, SASR( *LARpp_j_1, 1));
101− }
102−}
103−
104−static void Coefficients_13_26 (
105− register word * LARpp_j_1,
106− register word * LARpp_j,
107− register word * LARp)
108−{
109− register int i;
110− register longword ltmp;
111− for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
112− *LARp = GSM_ADD( SASR( *LARpp_j_1, 1), SASR( *LARpp_j, 1 ));
113− }
114−}
115−
116−static void Coefficients_27_39 (
117− register word * LARpp_j_1,
118− register word * LARpp_j,
119− register word * LARp)
120−{
121− register int i;
122− register longword ltmp;
123−
124− for (i = 1; i <= 8; i++, LARpp_j_1++, LARpp_j++, LARp++) {
125− *LARp = GSM_ADD( SASR( *LARpp_j_1, 2 ), SASR( *LARpp_j, 2 ));
126− *LARp = GSM_ADD( *LARp, SASR( *LARpp_j, 1 ));
127− }
128−}
129−
130−
131−static void Coefficients_40_159 (
132− register word * LARpp_j,
133− register word * LARp)
134−{
135− register int i;
136−
137− for (i = 1; i <= 8; i++, LARp++, LARpp_j++)
138− *LARp = *LARpp_j;
139−}
140−
141−/* 4.2.9.2 */
142−
143−static void LARp_to_rp (
144− register word * LARp) /* [0..7] IN/OUT */
145−/*
146− * The input of this procedure is the interpolated LARp[0..7] array.
147− * The reflection coefficients, rp[i], are used in the analysis
148− * filter and in the synthesis filter.
149− */
150−{
151− register int i;
152− register word temp;
153− register longword ltmp;
154−
155− for (i = 1; i <= 8; i++, LARp++) {
156−
157− /* temp = GSM_ABS( *LARp );
158− *
159− * if (temp < 11059) temp <<= 1;
160− * else if (temp < 20070) temp += 11059;
161− * else temp = GSM_ADD( temp >> 2, 26112 );
162− *
163− * *LARp = *LARp < 0 ? -temp : temp;
164− */
165−
166− if (*LARp < 0) {
167− temp = *LARp == MIN_WORD ? MAX_WORD : -(*LARp);
168− *LARp = - ((temp < 11059) ? temp << 1
169− : ((temp < 20070) ? temp + 11059
170− : GSM_ADD( temp >> 2, 26112 )));
171− } else {
172− temp = *LARp;
173− *LARp = (temp < 11059) ? temp << 1
174− : ((temp < 20070) ? temp + 11059
175− : GSM_ADD( temp >> 2, 26112 ));
176− }
177− }
178−}
179−
180−
181−/* 4.2.10 */
182−static void Short_term_analysis_filtering (
183− struct gsm_state * S,
184− register word * rp, /* [0..7] IN */
185− register int k_n, /* k_end - k_start */
186− register word * s /* [0..n-1] IN/OUT */
187−)
188−/*
189− * This procedure computes the short term residual signal d[..] to be fed
190− * to the RPE-LTP loop from the s[..] signal and from the local rp[..]
191− * array (quantized reflection coefficients). As the call of this
192− * procedure can be done in many ways (see the interpolation of the LAR
193− * coefficient), it is assumed that the computation begins with index
194− * k_start (for arrays d[..] and s[..]) and stops with index k_end
195− * (k_start and k_end are defined in 4.2.9.1). This procedure also
196− * needs to keep the array u[0..7] in memory for each call.
197− */
198−{
199− register word * u = S->u;
200− register int i;
201− register word di, zzz, ui, sav, rpi;
202− register longword ltmp;
203−
204− for (; k_n--; s++) {
205−
206− di = sav = *s;
207−
208− for (i = 0; i < 8; i++) { /* YYY */
209−
210− ui = u[i];
211− rpi = rp[i];
212− u[i] = sav;
213−
214− zzz = GSM_MULT_R(rpi, di);
215− sav = GSM_ADD( ui, zzz);
216−
217− zzz = GSM_MULT_R(rpi, ui);
218− di = GSM_ADD( di, zzz );
219− }
220−
221− *s = di;
222− }
223−}
224−
225−#if defined(USE_FLOAT_MUL) && defined(FAST)
226−
227−static void Fast_Short_term_analysis_filtering (
228− struct gsm_state * S,
229− register word * rp, /* [0..7] IN */
230− register int k_n, /* k_end - k_start */
231− register word * s /* [0..n-1] IN/OUT */
232−)
233−{
234− register word * u = S->u;
235− register int i;
236−
237− float uf[8],
238− rpf[8];
239−
240− register float scalef = 3.0517578125e-5;
241− register float sav, di, temp;
242−
243− for (i = 0; i < 8; ++i) {
244− uf[i] = u[i];
245− rpf[i] = rp[i] * scalef;
246− }
247− for (; k_n--; s++) {
248− sav = di = *s;
249− for (i = 0; i < 8; ++i) {
250− register float rpfi = rpf[i];
251− register float ufi = uf[i];
252−
253− uf[i] = sav;
254− temp = rpfi * di + ufi;
255− di += rpfi * ufi;
256− sav = temp;
257− }
258− *s = di;
259− }
260− for (i = 0; i < 8; ++i) u[i] = uf[i];
261−}
262−#endif /* ! (defined (USE_FLOAT_MUL) && defined (FAST)) */
263−
264−static void Short_term_synthesis_filtering (
265− struct gsm_state * S,
266− register word * rrp, /* [0..7] IN */
267− register int k, /* k_end - k_start */
268− register word * wt, /* [0..k-1] IN */
269− register word * sr /* [0..k-1] OUT */
270−)
271−{
272− register word * v = S->v;
273− register int i;
274− register word sri, tmp1, tmp2;
275− register longword ltmp; /* for GSM_ADD & GSM_SUB */
276−
277− while (k--) {
278− sri = *wt++;
279− for (i = 8; i--;) {
280−
281− /* sri = GSM_SUB( sri, gsm_mult_r( rrp[i], v[i] ) );
282− */
283− tmp1 = rrp[i];
284− tmp2 = v[i];
285− tmp2 = ( tmp1 == MIN_WORD && tmp2 == MIN_WORD
286− ? MAX_WORD
287− : 0x0FFFF & (( (longword)tmp1 * (longword)tmp2
288− + 16384) >> 15)) ;
289−
290− sri = GSM_SUB( sri, tmp2 );
291−
292− /* v[i+1] = GSM_ADD( v[i], gsm_mult_r( rrp[i], sri ) );
293− */
294− tmp1 = ( tmp1 == MIN_WORD && sri == MIN_WORD
295− ? MAX_WORD
296− : 0x0FFFF & (( (longword)tmp1 * (longword)sri
297− + 16384) >> 15)) ;
298−
299− v[i+1] = GSM_ADD( v[i], tmp1);
300− }
301− *sr++ = v[0] = sri;
302− }
303−}
304−
305−
306−#if defined(FAST) && defined(USE_FLOAT_MUL)
307−
308−static void Fast_Short_term_synthesis_filtering (
309− struct gsm_state * S,
310− register word * rrp, /* [0..7] IN */
311− register int k, /* k_end - k_start */
312− register word * wt, /* [0..k-1] IN */
313− register word * sr /* [0..k-1] OUT */
314−)
315−{
316− register word * v = S->v;
317− register int i;
318−
319− float va[9], rrpa[8];
320− register float scalef = 3.0517578125e-5, temp;
321−
322− for (i = 0; i < 8; ++i) {
323− va[i] = v[i];
324− rrpa[i] = (float)rrp[i] * scalef;
325− }
326− while (k--) {
327− register float sri = *wt++;
328− for (i = 8; i--;) {
329− sri -= rrpa[i] * va[i];
330− if (sri < -32768.) sri = -32768.;
331− else if (sri > 32767.) sri = 32767.;
332−
333− temp = va[i] + rrpa[i] * sri;
334− if (temp < -32768.) temp = -32768.;
335− else if (temp > 32767.) temp = 32767.;
336− va[i+1] = temp;
337− }
338− *sr++ = va[0] = sri;
339− }
340− for (i = 0; i < 9; ++i) v[i] = va[i];
341−}
342−
343−#endif /* defined(FAST) && defined(USE_FLOAT_MUL) */
344−
345−void Gsm_Short_Term_Analysis_Filter (
346−
347− struct gsm_state * S,
348−
349− word * LARc, /* coded log area ratio [0..7] IN */
350− word * s /* signal [0..159] IN/OUT */
351−)
352−{
353− word * LARpp_j = S->LARpp[ S->j ];
354− word * LARpp_j_1 = S->LARpp[ S->j ^= 1 ];
355−
356− word LARp[8];
357−
358−#undef FILTER
359−#if defined(FAST) && defined(USE_FLOAT_MUL)
360−# define FILTER (* (S->fast \
361− ? Fast_Short_term_analysis_filtering \
362− : Short_term_analysis_filtering ))
363−
364−#else
365−# define FILTER Short_term_analysis_filtering
366−#endif
367−
368− Decoding_of_the_coded_Log_Area_Ratios( LARc, LARpp_j );
369−
370− Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
371− LARp_to_rp( LARp );
372− FILTER( S, LARp, 13, s);
373−
374− Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
375− LARp_to_rp( LARp );
376− FILTER( S, LARp, 14, s + 13);
377−
378− Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
379− LARp_to_rp( LARp );
380− FILTER( S, LARp, 13, s + 27);
381−
382− Coefficients_40_159( LARpp_j, LARp);
383− LARp_to_rp( LARp );
384− FILTER( S, LARp, 120, s + 40);
385−}
386−
387−void Gsm_Short_Term_Synthesis_Filter (
388− struct gsm_state * S,
389−
390− word * LARcr, /* received log area ratios [0..7] IN */
391− word * wt, /* received d [0..159] IN */
392−
393− word * s /* signal s [0..159] OUT */
394−)
395−{
396− word * LARpp_j = S->LARpp[ S->j ];
397− word * LARpp_j_1 = S->LARpp[ S->j ^=1 ];
398−
399− word LARp[8];
400−
401−#undef FILTER
402−#if defined(FAST) && defined(USE_FLOAT_MUL)
403−
404−# define FILTER (* (S->fast \
405− ? Fast_Short_term_synthesis_filtering \
406− : Short_term_synthesis_filtering ))
407−#else
408−# define FILTER Short_term_synthesis_filtering
409−#endif
410−
411− Decoding_of_the_coded_Log_Area_Ratios( LARcr, LARpp_j );
412−
413− Coefficients_0_12( LARpp_j_1, LARpp_j, LARp );
414− LARp_to_rp( LARp );
415− FILTER( S, LARp, 13, wt, s );
416−
417− Coefficients_13_26( LARpp_j_1, LARpp_j, LARp);
418− LARp_to_rp( LARp );
419− FILTER( S, LARp, 14, wt + 13, s + 13 );
420−
421− Coefficients_27_39( LARpp_j_1, LARpp_j, LARp);
422− LARp_to_rp( LARp );
423− FILTER( S, LARp, 13, wt + 27, s + 27 );
424−
425− Coefficients_40_159( LARpp_j, LARp );
426− LARp_to_rp( LARp );
427− FILTER(S, LARp, 120, wt + 40, s + 40);
428−}
libgsm/table.c+0−63
@@ -1,63 +0,0 @@
1−/*
2− * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
3− * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
4− * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
5− */
6−
7−/* $Header: /cvsroot/sox/sox/libgsm/table.c,v 1.1 2007/09/06 16:50:56 cbagwell Exp $ */
8−
9−/* Most of these tables are inlined at their point of use.
10− */
11−
12−/* 4.4 TABLES USED IN THE FIXED POINT IMPLEMENTATION OF THE RPE-LTP
13− * CODER AND DECODER
14− *
15− * (Most of them inlined, so watch out.)
16− */
17−
18−#define GSM_TABLE_C
19−#include "private.h"
20−#include "gsm.h"
21−
22−/* Table 4.1 Quantization of the Log.-Area Ratios
23− */
24−/* i 1 2 3 4 5 6 7 8 */
25−word gsm_A[8] = {20480, 20480, 20480, 20480, 13964, 15360, 8534, 9036};
26−word gsm_B[8] = { 0, 0, 2048, -2560, 94, -1792, -341, -1144};
27−word gsm_MIC[8] = { -32, -32, -16, -16, -8, -8, -4, -4 };
28−word gsm_MAC[8] = { 31, 31, 15, 15, 7, 7, 3, 3 };
29−
30−
31−/* Table 4.2 Tabulation of 1/A[1..8]
32− */
33−word gsm_INVA[8]={ 13107, 13107, 13107, 13107, 19223, 17476, 31454, 29708 };
34−
35−
36−/* Table 4.3a Decision level of the LTP gain quantizer
37− */
38−/* bc 0 1 2 3 */
39−word gsm_DLB[4] = { 6554, 16384, 26214, 32767 };
40−
41−
42−/* Table 4.3b Quantization levels of the LTP gain quantizer
43− */
44−/* bc 0 1 2 3 */
45−word gsm_QLB[4] = { 3277, 11469, 21299, 32767 };
46−
47−
48−/* Table 4.4 Coefficients of the weighting filter
49− */
50−/* i 0 1 2 3 4 5 6 7 8 9 10 */
51−word gsm_H[11] = {-134, -374, 0, 2054, 5741, 8192, 5741, 2054, 0, -374, -134 };
52−
53−
54−/* Table 4.5 Normalized inverse mantissa used to compute xM/xmax
55− */
56−/* i 0 1 2 3 4 5 6 7 */
57−word gsm_NRFAC[8] = { 29128, 26215, 23832, 21846, 20165, 18725, 17476, 16384 };
58−
59−
60−/* Table 4.6 Normalized direct mantissa used to compute xM/xmax
61− */
62−/* i 0 1 2 3 4 5 6 7 */
63−word gsm_FAC[8] = { 18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767 };
src/Makefile.am+0−1
@@ -120,7 +120,6 @@ libsox_la_SOURCES += raw-fmt.c s1-fmt.c s2-fmt.c s3-fmt.c \ · 119 unmodified lines
120120 sounder.c soundtool.c sphere.c tx16w.c voc.c vox-fmt.c ima-fmt.c adpcm.c adpcm.h \
121121 ima_rw.c ima_rw.h wav.c wve.c xa.c nulfile.c f4-fmt.c f8-fmt.c gsrt.c
122122
123−libsox_la_LIBADD += @GSM_LIBS@ @LIBGSM_LIBADD@
124123 libsox_la_LIBADD += @LPC10_LIBS@ @LIBLPC10_LIBADD@
125124
126125 pkglib_LTLIBRARIES =
src/gsm.c+0−6
@@ -25,18 +25,12 @@ · 24 unmodified lines
2525
2626 #include "sox_i.h"
2727
28−#ifdef EXTERNAL_GSM
29−
3028 #ifdef HAVE_GSM_GSM_H
3129 #include <gsm/gsm.h>
3230 #else
3331 #include <gsm.h>
3432 #endif
3533
36−#else
37−#include "../libgsm/gsm.h"
38−#endif
39−
4034 #include <errno.h>
4135
4236 #define MAXCHANS 16
src/wav.c+26−4
@@ -18,16 +18,13 @@ · 17 unmodified lines
1818
1919 #include "ima_rw.h"
2020 #include "adpcm.h"
21−#ifdef EXTERNAL_GSM
2221
22+#ifdef HAVE_GSM
2323 #ifdef HAVE_GSM_GSM_H
2424 #include <gsm/gsm.h>
2525 #else
2626 #include <gsm.h>
2727 #endif
28−
29−#else
30−#include "../libgsm/gsm.h"
3128 #endif
3229
3330 /* Magic length sometimes used to indicate unknown or too large size.
@@ -111,11 +108,13 @@ typedef struct { · 77 unmodified lines
111108 unsigned short blockSamplesRemaining;/* Samples remaining per channel */
112109 int state[16]; /* step-size info for *ADPCM writes */
113110
111+#ifdef HAVE_GSM
114112 /* following used by GSM 6.10 wav */
115113 gsm gsmhandle;
116114 gsm_signal *gsmsample;
117115 int gsmindex;
118116 size_t gsmbytecount; /* counts bytes written to data block */
117+#endif
119118 } priv_t;
120119
121120 struct wave_format {
@@ -344,6 +343,7 @@ static int xxxAdpcmWriteBlock(sox_format_t * ft) · 222 unmodified lines
344343 return (SOX_SUCCESS);
345344 }
346345
346+#ifdef HAVE_GSM
347347 /****************************************************************************/
348348 /* WAV GSM6.10 support functions */
349349 /****************************************************************************/
@@ -518,6 +518,8 @@ static void wavgsmstopwrite(sox_format_t * ft) · 168 unmodified lines
518518 wavgsmdestroy(ft);
519519 }
520520
521+#endif /* HAVE_GSM */
522+
521523 /****************************************************************************/
522524 /* General Sox WAV file code */
523525 /****************************************************************************/
@@ -575,8 +577,10 @@ static const struct wave_format wave_formats[] = { · 51 unmodified lines
575577 { WAVE_FORMAT_AUDIOFILE_AF10, "Audio File AF10" },
576578 { WAVE_FORMAT_DOLBY_AC2, "Dolby AC-2" },
577579 { WAVE_FORMAT_GSM610, "GSM 6.10",
580+#ifdef HAVE_GSM
578581 SOX_ENCODING_GSM,
579582 wav_gsm_fmt,
583+#endif
580584 },
581585 { WAVE_FORMAT_ADPCME, "Antex ADPCME" },
582586 { WAVE_FORMAT_CONTROL_RES_VQLPC, "Control Resources VQLPC" },
@@ -955,10 +959,12 @@ static int startread(sox_format_t *ft) · 372 unmodified lines
955959 lsx_ima_init_table();
956960 break;
957961
962+#ifdef HAVE_GSM
958963 case WAVE_FORMAT_GSM610:
959964 wav->numSamples = qwDataLength / wav->blockAlign * wav->samplesPerBlock;
960965 wavgsminit(ft);
961966 break;
967+#endif
962968 }
963969
964970 if (!wav->numSamples)
@@ -1041,9 +1047,11 @@ static size_t read_samples(sox_format_t *ft, sox_sample_t *buf, size_t len) · 76 unmodified lines
10411047
10421048 return done;
10431049
1050+#ifdef HAVE_GSM
10441051 case SOX_ENCODING_GSM:
10451052 done = wavgsmread(ft, buf, len);
10461053 break;
1054+#endif
10471055
10481056 default: /* assume PCM or float encoding */
10491057 done = lsx_rawread(ft, buf, len);
@@ -1083,9 +1091,11 @@ static int stopread(sox_format_t * ft) · 33 unmodified lines
10831091
10841092 switch (ft->encoding.encoding)
10851093 {
1094+#ifdef HAVE_GSM
10861095 case SOX_ENCODING_GSM:
10871096 wavgsmdestroy(ft);
10881097 break;
1098+#endif
10891099 case SOX_ENCODING_IMA_ADPCM:
10901100 case SOX_ENCODING_MS_ADPCM:
10911101 break;
@@ -1141,8 +1151,10 @@ static int startwrite(sox_format_t * ft) · 49 unmodified lines
11411151 wav->samplePtr = wav->samples;
11421152 break;
11431153
1154+#ifdef HAVE_GSM
11441155 case WAVE_FORMAT_GSM610:
11451156 return wavgsminit(ft);
1157+#endif
11461158
11471159 default:
11481160 break;
@@ -1298,6 +1310,7 @@ static int wavwritehdr(sox_format_t * ft, int second_header) · 149 unmodified lines
12981310 wExtSize = 4+4*7; /* Ext fmt data length */
12991311 wSamplesPerBlock = lsx_ms_adpcm_samples_in((size_t) 0, (size_t) wChannels, (size_t) wBlockAlign, (size_t) 0);
13001312 break;
1313+#ifdef HAVE_GSM
13011314 case SOX_ENCODING_GSM:
13021315 if (wChannels!=1)
13031316 {
@@ -1313,6 +1326,7 @@ static int wavwritehdr(sox_format_t * ft, int second_header) · 9 unmodified lines
13131326 wExtSize=2; /* length of format extension */
13141327 wSamplesPerBlock = 320;
13151328 break;
1329+#endif
13161330 default:
13171331 break;
13181332 }
@@ -1460,6 +1474,7 @@ static int wavwritehdr(sox_format_t * ft, int second_header) · 141 unmodified lines
14601474 } else {
14611475 lsx_debug("Finished writing Wave file, %"PRIu64" data bytes %"PRIu64" samples",
14621476 dwDataLength, wav->numSamples);
1477+#ifdef HAVE_GSM
14631478 if (wFormatTag == WAVE_FORMAT_GSM610){
14641479 lsx_debug("GSM6.10 format: %"PRIu64" blocks %"PRIu64" padded samples %"PRIu64" padded data bytes",
14651480 blocksWritten, dwSamplesWritten, dwDataLength);
@@ -1468,6 +1483,7 @@ static int wavwritehdr(sox_format_t * ft, int second_header) · 2 unmodified lines
14681483 dwDataLength, wav->gsmbytecount);
14691484
14701485 }
1486+#endif
14711487 }
14721488 return SOX_SUCCESS;
14731489 }
@@ -1500,11 +1516,13 @@ static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t l · 26 unmodified lines
15001516 return total_len - len;
15011517 break;
15021518
1519+#ifdef HAVE_GSM
15031520 case WAVE_FORMAT_GSM610:
15041521 len = wavgsmwrite(ft, buf, len);
15051522 wav->numSamples += (len/ft->signal.channels);
15061523 return len;
15071524 break;
1525+#endif
15081526
15091527 default:
15101528 len = lsx_rawwrite(ft, buf, len);
@@ -1527,9 +1545,11 @@ static int stopwrite(sox_format_t * ft) · 16 unmodified lines
15271545 case WAVE_FORMAT_ADPCM:
15281546 xxxAdpcmWriteBlock(ft);
15291547 break;
1548+#ifdef HAVE_GSM
15301549 case WAVE_FORMAT_GSM610:
15311550 wavgsmstopwrite(ft);
15321551 break;
1552+#endif
15331553 }
15341554
15351555 /* Add a pad byte if the number of data bytes is odd.
@@ -1613,7 +1633,9 @@ LSX_FORMAT_HANDLER(wav) · 77 unmodified lines
16131633 SOX_ENCODING_UNSIGNED, 8, 0,
16141634 SOX_ENCODING_ULAW, 8, 0,
16151635 SOX_ENCODING_ALAW, 8, 0,
1636+#ifdef HAVE_GSM
16161637 SOX_ENCODING_GSM, 0,
1638+#endif
16171639 SOX_ENCODING_MS_ADPCM, 4, 0,
16181640 SOX_ENCODING_IMA_ADPCM, 4, 0,
16191641 SOX_ENCODING_FLOAT, 32, 64, 0,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t