提交 d92ee88a authored 作者: Michael Jerris's avatar Michael Jerris

dos2unix gsm

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@966 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 e3d0adb8
/* /*
* config.h * config.h
* *
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
*/ */
#ifndef CONFIG_H #ifndef CONFIG_H
#define CONFIG_H #define CONFIG_H
/*efine SIGHANDLER_T int * signal handlers are void */ /*efine SIGHANDLER_T int * signal handlers are void */
/*efine HAS_SYSV_SIGNAL 1 * sigs not blocked/reset? */ /*efine HAS_SYSV_SIGNAL 1 * sigs not blocked/reset? */
#define HAS_STDLIB_H 1 /* /usr/include/stdlib.h */ #define HAS_STDLIB_H 1 /* /usr/include/stdlib.h */
/*efine HAS_LIMITS_H 1 * /usr/include/limits.h */ /*efine HAS_LIMITS_H 1 * /usr/include/limits.h */
#define HAS_FCNTL_H 1 /* /usr/include/fcntl.h */ #define HAS_FCNTL_H 1 /* /usr/include/fcntl.h */
/*efine HAS_ERRNO_DECL 1 * errno.h declares errno */ /*efine HAS_ERRNO_DECL 1 * errno.h declares errno */
#define HAS_FSTAT 1 /* fstat syscall */ #define HAS_FSTAT 1 /* fstat syscall */
#define HAS_FCHMOD 1 /* fchmod syscall */ #define HAS_FCHMOD 1 /* fchmod syscall */
#define HAS_CHMOD 1 /* chmod syscall */ #define HAS_CHMOD 1 /* chmod syscall */
#define HAS_FCHOWN 1 /* fchown syscall */ #define HAS_FCHOWN 1 /* fchown syscall */
#define HAS_CHOWN 1 /* chown syscall */ #define HAS_CHOWN 1 /* chown syscall */
/*efine HAS__FSETMODE 1 * _fsetmode -- set file mode */ /*efine HAS__FSETMODE 1 * _fsetmode -- set file mode */
#define HAS_STRING_H 1 /* /usr/include/string.h */ #define HAS_STRING_H 1 /* /usr/include/string.h */
/*efine HAS_STRINGS_H 1 * /usr/include/strings.h */ /*efine HAS_STRINGS_H 1 * /usr/include/strings.h */
#define HAS_UNISTD_H 1 /* /usr/include/unistd.h */ #define HAS_UNISTD_H 1 /* /usr/include/unistd.h */
#define HAS_UTIME 1 /* POSIX utime(path, times) */ #define HAS_UTIME 1 /* POSIX utime(path, times) */
/*efine HAS_UTIMES 1 * use utimes() syscall instead */ /*efine HAS_UTIMES 1 * use utimes() syscall instead */
#define HAS_UTIME_H 1 /* UTIME header file */ #define HAS_UTIME_H 1 /* UTIME header file */
/*efine HAS_UTIMBUF 1 * struct utimbuf */ /*efine HAS_UTIMBUF 1 * struct utimbuf */
/*efine HAS_UTIMEUSEC 1 * microseconds in utimbuf? */ /*efine HAS_UTIMEUSEC 1 * microseconds in utimbuf? */
#endif /* CONFIG_H */ #endif /* CONFIG_H */
/* /*
* gsm.h * gsm.h
* *
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
*/ */
#ifndef GSM_H #ifndef GSM_H
#define GSM_H #define GSM_H
#ifdef __cplusplus #ifdef __cplusplus
# define NeedFunctionPrototypes 1 # define NeedFunctionPrototypes 1
#endif #endif
#if __STDC__ #if __STDC__
# define NeedFunctionPrototypes 1 # define NeedFunctionPrototypes 1
#endif #endif
#ifdef _NO_PROTO #ifdef _NO_PROTO
# undef NeedFunctionPrototypes # undef NeedFunctionPrototypes
#endif #endif
#ifdef NeedFunctionPrototypes #ifdef NeedFunctionPrototypes
# include <stdio.h> /* for FILE * */ # include <stdio.h> /* for FILE * */
#endif #endif
#undef GSM_P #undef GSM_P
#if NeedFunctionPrototypes #if NeedFunctionPrototypes
# define GSM_P( protos ) protos # define GSM_P( protos ) protos
#else #else
# define GSM_P( protos ) ( /* protos */ ) # define GSM_P( protos ) ( /* protos */ )
#endif #endif
/* /*
* Interface * Interface
*/ */
typedef struct gsm_state * gsm; typedef struct gsm_state * gsm;
typedef short gsm_signal; /* signed 16 bit */ typedef short gsm_signal; /* signed 16 bit */
typedef unsigned char gsm_byte; typedef unsigned char gsm_byte;
typedef gsm_byte gsm_frame[33]; /* 33 * 8 bits */ typedef gsm_byte gsm_frame[33]; /* 33 * 8 bits */
#define GSM_MAGIC 0xD /* 13 kbit/s RPE-LTP */ #define GSM_MAGIC 0xD /* 13 kbit/s RPE-LTP */
#define GSM_PATCHLEVEL 10 #define GSM_PATCHLEVEL 10
#define GSM_MINOR 0 #define GSM_MINOR 0
#define GSM_MAJOR 1 #define GSM_MAJOR 1
#define GSM_OPT_VERBOSE 1 #define GSM_OPT_VERBOSE 1
#define GSM_OPT_FAST 2 #define GSM_OPT_FAST 2
#define GSM_OPT_LTP_CUT 3 #define GSM_OPT_LTP_CUT 3
#define GSM_OPT_WAV49 4 #define GSM_OPT_WAV49 4
#define GSM_OPT_FRAME_INDEX 5 #define GSM_OPT_FRAME_INDEX 5
#define GSM_OPT_FRAME_CHAIN 6 #define GSM_OPT_FRAME_CHAIN 6
extern gsm gsm_create GSM_P((void)); extern gsm gsm_create GSM_P((void));
extern void gsm_destroy GSM_P((gsm)); extern void gsm_destroy GSM_P((gsm));
extern int gsm_print GSM_P((FILE *, gsm, gsm_byte *)); extern int gsm_print GSM_P((FILE *, gsm, gsm_byte *));
extern int gsm_option GSM_P((gsm, int, int *)); extern int gsm_option GSM_P((gsm, int, int *));
extern void gsm_encode GSM_P((gsm, gsm_signal *, gsm_byte *)); extern void gsm_encode GSM_P((gsm, gsm_signal *, gsm_byte *));
extern int gsm_decode GSM_P((gsm, gsm_byte *, gsm_signal *)); extern int gsm_decode GSM_P((gsm, gsm_byte *, gsm_signal *));
extern int gsm_explode GSM_P((gsm, gsm_byte *, gsm_signal *)); extern int gsm_explode GSM_P((gsm, gsm_byte *, gsm_signal *));
extern void gsm_implode GSM_P((gsm, gsm_signal *, gsm_byte *)); extern void gsm_implode GSM_P((gsm, gsm_signal *, gsm_byte *));
#undef GSM_P #undef GSM_P
#endif /* GSM_H */ #endif /* GSM_H */
/* /*
* proto.h * proto.h
* *
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
*/ */
#ifndef PROTO_H #ifndef PROTO_H
#define PROTO_H #define PROTO_H
#if __cplusplus #if __cplusplus
# define NeedFunctionPrototypes 1 # define NeedFunctionPrototypes 1
#endif #endif
#if __STDC__ #if __STDC__
# define NeedFunctionPrototypes 1 # define NeedFunctionPrototypes 1
#endif #endif
#ifdef _NO_PROTO #ifdef _NO_PROTO
# undef NeedFunctionPrototypes # undef NeedFunctionPrototypes
#endif #endif
#undef P /* gnu stdio.h actually defines this... */ #undef P /* gnu stdio.h actually defines this... */
#undef P0 #undef P0
#undef P1 #undef P1
#undef P2 #undef P2
#undef P3 #undef P3
#undef P4 #undef P4
#undef P5 #undef P5
#undef P6 #undef P6
#undef P7 #undef P7
#undef P8 #undef P8
#if NeedFunctionPrototypes #if NeedFunctionPrototypes
# define P( protos ) protos # define P( protos ) protos
# define P0() (void) # define P0() (void)
# define P1(x, a) (a) # define P1(x, a) (a)
# define P2(x, a, b) (a, b) # define P2(x, a, b) (a, b)
# define P3(x, a, b, c) (a, b, c) # define P3(x, a, b, c) (a, b, c)
# define P4(x, a, b, c, d) (a, b, c, d) # define P4(x, a, b, c, d) (a, b, c, d)
# define P5(x, a, b, c, d, e) (a, b, c, d, e) # define P5(x, a, b, c, d, e) (a, b, c, d, e)
# define P6(x, a, b, c, d, e, f) (a, b, c, d, e, f) # define P6(x, a, b, c, d, e, f) (a, b, c, d, e, f)
# define P7(x, a, b, c, d, e, f, g) (a, b, c, d, e, f, g) # define P7(x, a, b, c, d, e, f, g) (a, b, c, d, e, f, g)
# define P8(x, a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h) # define P8(x, a, b, c, d, e, f, g, h) (a, b, c, d, e, f, g, h)
#else /* !NeedFunctionPrototypes */ #else /* !NeedFunctionPrototypes */
# define P( protos ) ( /* protos */ ) # define P( protos ) ( /* protos */ )
# define P0() () # define P0() ()
# define P1(x, a) x a; # define P1(x, a) x a;
# define P2(x, a, b) x a; b; # define P2(x, a, b) x a; b;
# define P3(x, a, b, c) x a; b; c; # define P3(x, a, b, c) x a; b; c;
# define P4(x, a, b, c, d) x a; b; c; d; # define P4(x, a, b, c, d) x a; b; c; d;
# define P5(x, a, b, c, d, e) x a; b; c; d; e; # define P5(x, a, b, c, d, e) x a; b; c; d; e;
# define P6(x, a, b, c, d, e, f) x a; b; c; d; e; f; # define P6(x, a, b, c, d, e, f) x a; b; c; d; e; f;
# define P7(x, a, b, c, d, e, f, g) x a; b; c; d; e; f; g; # define P7(x, a, b, c, d, e, f, g) x a; b; c; d; e; f; g;
# define P8(x, a, b, c, d, e, f, g, h) x a; b; c; d; e; f; g; h; # define P8(x, a, b, c, d, e, f, g, h) x a; b; c; d; e; f; g; h;
#endif /* !NeedFunctionPrototypes */ #endif /* !NeedFunctionPrototypes */
#endif /* PROTO_H */ #endif /* PROTO_H */
/* /*
* unproto.h * unproto.h
* *
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
*/ */
#ifdef PROTO_H /* sic */ #ifdef PROTO_H /* sic */
#undef PROTO_H #undef PROTO_H
#undef P #undef P
#undef P0 #undef P0
#undef P1 #undef P1
#undef P2 #undef P2
#undef P3 #undef P3
#undef P4 #undef P4
#undef P5 #undef P5
#undef P6 #undef P6
#undef P7 #undef P7
#undef P8 #undef P8
#endif /* PROTO_H */ #endif /* PROTO_H */
差异被折叠。
/* /*
* code.c * code.c
* *
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
*/ */
#include "config.h" #include "config.h"
#ifdef HAS_STRING_H #ifdef HAS_STRING_H
#include <string.h> #include <string.h>
#else #else
#include "proto.h" #include "proto.h"
extern char * memcpy P((char *, char *, int)); extern char * memcpy P((char *, char *, int));
#endif #endif
#include "private.h" #include "private.h"
#include "gsm.h" #include "gsm.h"
#include "proto.h" #include "proto.h"
/* /*
* 4.2 FIXED POINT IMPLEMENTATION OF THE RPE-LTP CODER * 4.2 FIXED POINT IMPLEMENTATION OF THE RPE-LTP CODER
*/ */
void Gsm_Coder P8((S,s,LARc,Nc,bc,Mc,xmaxc,xMc), void Gsm_Coder P8((S,s,LARc,Nc,bc,Mc,xmaxc,xMc),
struct gsm_state * S, struct gsm_state * S,
word * s, /* [0..159] samples IN */ word * s, /* [0..159] samples IN */
/* /*
* The RPE-LTD coder works on a frame by frame basis. The length of * The RPE-LTD coder works on a frame by frame basis. The length of
* the frame is equal to 160 samples. Some computations are done * the frame is equal to 160 samples. Some computations are done
* once per frame to produce at the output of the coder the * once per frame to produce at the output of the coder the
* LARc[1..8] parameters which are the coded LAR coefficients and * LARc[1..8] parameters which are the coded LAR coefficients and
* also to realize the inverse filtering operation for the entire * also to realize the inverse filtering operation for the entire
* frame (160 samples of signal d[0..159]). These parts produce at * frame (160 samples of signal d[0..159]). These parts produce at
* the output of the coder: * the output of the coder:
*/ */
word * LARc, /* [0..7] LAR coefficients OUT */ word * LARc, /* [0..7] LAR coefficients OUT */
/* /*
* Procedure 4.2.11 to 4.2.18 are to be executed four times per * Procedure 4.2.11 to 4.2.18 are to be executed four times per
* frame. That means once for each sub-segment RPE-LTP analysis of * frame. That means once for each sub-segment RPE-LTP analysis of
* 40 samples. These parts produce at the output of the coder: * 40 samples. These parts produce at the output of the coder:
*/ */
word * Nc, /* [0..3] LTP lag OUT */ word * Nc, /* [0..3] LTP lag OUT */
word * bc, /* [0..3] coded LTP gain OUT */ word * bc, /* [0..3] coded LTP gain OUT */
word * Mc, /* [0..3] RPE grid selection OUT */ word * Mc, /* [0..3] RPE grid selection OUT */
word * xmaxc,/* [0..3] Coded maximum amplitude OUT */ word * xmaxc,/* [0..3] Coded maximum amplitude OUT */
word * xMc /* [13*4] normalized RPE samples OUT */ word * xMc /* [13*4] normalized RPE samples OUT */
) )
{ {
int k; int k;
word * dp = S->dp0 + 120; /* [ -120...-1 ] */ word * dp = S->dp0 + 120; /* [ -120...-1 ] */
word * dpp = dp; /* [ 0...39 ] */ word * dpp = dp; /* [ 0...39 ] */
static word e[50]; static word e[50];
word so[160]; word so[160];
Gsm_Preprocess (S, s, so); Gsm_Preprocess (S, s, so);
Gsm_LPC_Analysis (S, so, LARc); Gsm_LPC_Analysis (S, so, LARc);
Gsm_Short_Term_Analysis_Filter (S, LARc, so); Gsm_Short_Term_Analysis_Filter (S, LARc, so);
for (k = 0; k <= 3; k++, xMc += 13) { for (k = 0; k <= 3; k++, xMc += 13) {
Gsm_Long_Term_Predictor ( S, Gsm_Long_Term_Predictor ( S,
so+k*40, /* d [0..39] IN */ so+k*40, /* d [0..39] IN */
dp, /* dp [-120..-1] IN */ dp, /* dp [-120..-1] IN */
e + 5, /* e [0..39] OUT */ e + 5, /* e [0..39] OUT */
dpp, /* dpp [0..39] OUT */ dpp, /* dpp [0..39] OUT */
Nc++, Nc++,
bc++); bc++);
Gsm_RPE_Encoding ( S, Gsm_RPE_Encoding ( S,
e + 5, /* e ][0..39][ IN/OUT */ e + 5, /* e ][0..39][ IN/OUT */
xmaxc++, Mc++, xMc ); xmaxc++, Mc++, xMc );
/* /*
* Gsm_Update_of_reconstructed_short_time_residual_signal * Gsm_Update_of_reconstructed_short_time_residual_signal
* ( dpp, e + 5, dp ); * ( dpp, e + 5, dp );
*/ */
{ register int i; { register int i;
register longword ltmp; register longword ltmp;
for (i = 0; i <= 39; i++) for (i = 0; i <= 39; i++)
dp[ i ] = (word) GSM_ADD( e[5 + i], dpp[i] ); dp[ i ] = (word) GSM_ADD( e[5 + i], dpp[i] );
} }
dp += 40; dp += 40;
dpp += 40; dpp += 40;
} }
(void)memcpy( (char *)S->dp0, (char *)(S->dp0 + 160), (void)memcpy( (char *)S->dp0, (char *)(S->dp0 + 160),
120 * sizeof(*S->dp0) ); 120 * sizeof(*S->dp0) );
} }
/* /*
* decode.c * decode.c
* *
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
*/ */
#include <stdio.h> #include <stdio.h>
#include "private.h" #include "private.h"
#include "gsm.h" #include "gsm.h"
#include "proto.h" #include "proto.h"
/* /*
* 4.3 FIXED POINT IMPLEMENTATION OF THE RPE-LTP DECODER * 4.3 FIXED POINT IMPLEMENTATION OF THE RPE-LTP DECODER
*/ */
static void Postprocessing P2((S,s), static void Postprocessing P2((S,s),
struct gsm_state * S, struct gsm_state * S,
register word * s) register word * s)
{ {
register int k; register int k;
register word msr = S->msr; register word msr = S->msr;
register longword ltmp; /* for GSM_ADD */ register longword ltmp; /* for GSM_ADD */
register word tmp; register word tmp;
for (k = 160; k--; s++) { for (k = 160; k--; s++) {
tmp = (word) GSM_MULT_R( msr, 28180 ); tmp = (word) GSM_MULT_R( msr, 28180 );
msr = (word) GSM_ADD(*s, tmp); /* Deemphasis */ msr = (word) GSM_ADD(*s, tmp); /* Deemphasis */
*s = (word) GSM_ADD(msr, msr) & 0xFFF8; /* Truncation & Upscaling */ *s = (word) GSM_ADD(msr, msr) & 0xFFF8; /* Truncation & Upscaling */
} }
S->msr = msr; S->msr = msr;
} }
void Gsm_Decoder P8((S,LARcr, Ncr,bcr,Mcr,xmaxcr,xMcr,s), void Gsm_Decoder P8((S,LARcr, Ncr,bcr,Mcr,xmaxcr,xMcr,s),
struct gsm_state * S, struct gsm_state * S,
word * LARcr, /* [0..7] IN */ word * LARcr, /* [0..7] IN */
word * Ncr, /* [0..3] IN */ word * Ncr, /* [0..3] IN */
word * bcr, /* [0..3] IN */ word * bcr, /* [0..3] IN */
word * Mcr, /* [0..3] IN */ word * Mcr, /* [0..3] IN */
word * xmaxcr, /* [0..3] IN */ word * xmaxcr, /* [0..3] IN */
word * xMcr, /* [0..13*4] IN */ word * xMcr, /* [0..13*4] IN */
word * s) /* [0..159] OUT */ word * s) /* [0..159] OUT */
{ {
int j, k; int j, k;
word erp[40], wt[160]; word erp[40], wt[160];
word * drp = S->dp0 + 120; word * drp = S->dp0 + 120;
for (j=0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) { for (j=0; j <= 3; j++, xmaxcr++, bcr++, Ncr++, Mcr++, xMcr += 13) {
Gsm_RPE_Decoding( S, *xmaxcr, *Mcr, xMcr, erp ); Gsm_RPE_Decoding( S, *xmaxcr, *Mcr, xMcr, erp );
Gsm_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp ); Gsm_Long_Term_Synthesis_Filtering( S, *Ncr, *bcr, erp, drp );
for (k = 0; k <= 39; k++) wt[ j * 40 + k ] = drp[ k ]; for (k = 0; k <= 39; k++) wt[ j * 40 + k ] = drp[ k ];
} }
Gsm_Short_Term_Synthesis_Filter( S, LARcr, wt, s ); Gsm_Short_Term_Synthesis_Filter( S, LARcr, wt, s );
Postprocessing(S, s); Postprocessing(S, s);
} }
/* /*
* gsm_create.c * gsm_create.c
* *
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
*/ */
#include "config.h" #include "config.h"
#ifdef HAS_STRING_H #ifdef HAS_STRING_H
#include <string.h> #include <string.h>
#else #else
# include "proto.h" # include "proto.h"
extern char * memset P((char *, int, int)); extern char * memset P((char *, int, int));
#endif #endif
#ifdef HAS_STDLIB_H #ifdef HAS_STDLIB_H
# include <stdlib.h> # include <stdlib.h>
#else #else
# ifdef HAS_MALLOC_H # ifdef HAS_MALLOC_H
# include <malloc.h> # include <malloc.h>
# else # else
extern char * malloc(); extern char * malloc();
# endif # endif
#endif #endif
#include <stdio.h> #include <stdio.h>
#include "gsm.h" #include "gsm.h"
#include "private.h" #include "private.h"
#include "proto.h" #include "proto.h"
gsm gsm_create P0() gsm gsm_create P0()
{ {
gsm r; gsm r;
r = (gsm)malloc(sizeof(struct gsm_state)); r = (gsm)malloc(sizeof(struct gsm_state));
if (!r) return r; if (!r) return r;
memset((char *)r, 0, sizeof(*r)); memset((char *)r, 0, sizeof(*r));
r->nrp = 40; r->nrp = 40;
return r; return r;
} }
/* /*
* gsm_destroy.c * gsm_destroy.c
* *
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
*/ */
#include "gsm.h" #include "gsm.h"
#include "config.h" #include "config.h"
#include "proto.h" #include "proto.h"
#ifdef HAS_STDLIB_H #ifdef HAS_STDLIB_H
# include <stdlib.h> # include <stdlib.h>
#else #else
# ifdef HAS_MALLOC_H # ifdef HAS_MALLOC_H
# include <malloc.h> # include <malloc.h>
# else # else
extern void free(); extern void free();
# endif # endif
#endif #endif
void gsm_destroy P1((S), gsm S) void gsm_destroy P1((S), gsm S)
{ {
if (S) free((char *)S); if (S) free((char *)S);
} }
/* /*
* gsm_option.c * gsm_option.c
* *
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
*/ */
#include "private.h" #include "private.h"
#include "gsm.h" #include "gsm.h"
#include "proto.h" #include "proto.h"
int gsm_option P3((r, opt, val), gsm r, int opt, int * val) int gsm_option P3((r, opt, val), gsm r, int opt, int * val)
{ {
int result = -1; int result = -1;
switch (opt) { switch (opt) {
case GSM_OPT_LTP_CUT: case GSM_OPT_LTP_CUT:
#ifdef LTP_CUT #ifdef LTP_CUT
result = r->ltp_cut; result = r->ltp_cut;
if (val) r->ltp_cut = *val; if (val) r->ltp_cut = *val;
#endif #endif
break; break;
case GSM_OPT_VERBOSE: case GSM_OPT_VERBOSE:
#ifndef NDEBUG #ifndef NDEBUG
result = r->verbose; result = r->verbose;
if (val) r->verbose = *val; if (val) r->verbose = *val;
#endif #endif
break; break;
case GSM_OPT_FAST: case GSM_OPT_FAST:
#if defined(FAST) && defined(USE_FLOAT_MUL) #if defined(FAST) && defined(USE_FLOAT_MUL)
result = r->fast; result = r->fast;
if (val) r->fast = !!*val; if (val) r->fast = !!*val;
#endif #endif
break; break;
case GSM_OPT_FRAME_CHAIN: case GSM_OPT_FRAME_CHAIN:
#ifdef WAV49 #ifdef WAV49
result = r->frame_chain; result = r->frame_chain;
if (val) r->frame_chain = *val; if (val) r->frame_chain = *val;
#endif #endif
break; break;
case GSM_OPT_FRAME_INDEX: case GSM_OPT_FRAME_INDEX:
#ifdef WAV49 #ifdef WAV49
result = r->frame_index; result = r->frame_index;
if (val) r->frame_index = *val; if (val) r->frame_index = *val;
#endif #endif
break; break;
case GSM_OPT_WAV49: case GSM_OPT_WAV49:
#ifdef WAV49 #ifdef WAV49
result = r->wav_fmt; result = r->wav_fmt;
if (val) r->wav_fmt = !!*val; if (val) r->wav_fmt = !!*val;
#endif #endif
break; break;
default: default:
break; break;
} }
return result; return result;
} }
/* /*
* preprocess.c * preprocess.c
* *
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
*/ */
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include "private.h" #include "private.h"
#include "gsm.h" #include "gsm.h"
#include "proto.h" #include "proto.h"
/* 4.2.0 .. 4.2.3 PREPROCESSING SECTION /* 4.2.0 .. 4.2.3 PREPROCESSING SECTION
* *
* After A-law to linear conversion (or directly from the * After A-law to linear conversion (or directly from the
* Ato D converter) the following scaling is assumed for * Ato D converter) the following scaling is assumed for
* input to the RPE-LTP algorithm: * input to the RPE-LTP algorithm:
* *
* in: 0.1.....................12 * in: 0.1.....................12
* S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.* * S.v.v.v.v.v.v.v.v.v.v.v.v.*.*.*
* *
* Where S is the sign bit, v a valid bit, and * a "don't care" bit. * Where S is the sign bit, v a valid bit, and * a "don't care" bit.
* The original signal is called sop[..] * The original signal is called sop[..]
* *
* out: 0.1................... 12 * out: 0.1................... 12
* S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0 * S.S.v.v.v.v.v.v.v.v.v.v.v.v.0.0
*/ */
void Gsm_Preprocess P3((S, s, so), void Gsm_Preprocess P3((S, s, so),
struct gsm_state * S, struct gsm_state * S,
word * s, word * s,
word * so ) /* [0..159] IN/OUT */ word * so ) /* [0..159] IN/OUT */
{ {
word z1 = S->z1; word z1 = S->z1;
longword L_z2 = S->L_z2; longword L_z2 = S->L_z2;
word mp = S->mp; word mp = S->mp;
word s1; word s1;
longword L_s2; longword L_s2;
longword L_temp; longword L_temp;
word msp, lsp; word msp, lsp;
word SO; word SO;
longword ltmp; /* for ADD */ longword ltmp; /* for ADD */
ulongword utmp; /* for L_ADD */ ulongword utmp; /* for L_ADD */
register int k = 160; register int k = 160;
while (k--) { while (k--) {
/* 4.2.1 Downscaling of the input signal /* 4.2.1 Downscaling of the input signal
*/ */
SO = SASR( *s, 3 ) << 2; SO = SASR( *s, 3 ) << 2;
s++; s++;
assert (SO >= -0x4000); /* downscaled by */ assert (SO >= -0x4000); /* downscaled by */
assert (SO <= 0x3FFC); /* previous routine. */ assert (SO <= 0x3FFC); /* previous routine. */
/* 4.2.2 Offset compensation /* 4.2.2 Offset compensation
* *
* This part implements a high-pass filter and requires extended * This part implements a high-pass filter and requires extended
* arithmetic precision for the recursive part of this filter. * arithmetic precision for the recursive part of this filter.
* The input of this procedure is the array so[0...159] and the * The input of this procedure is the array so[0...159] and the
* output the array sof[ 0...159 ]. * output the array sof[ 0...159 ].
*/ */
/* Compute the non-recursive part /* Compute the non-recursive part
*/ */
s1 = SO - z1; /* s1 = gsm_sub( *so, z1 ); */ s1 = SO - z1; /* s1 = gsm_sub( *so, z1 ); */
z1 = SO; z1 = SO;
assert(s1 != MIN_WORD); assert(s1 != MIN_WORD);
/* Compute the recursive part /* Compute the recursive part
*/ */
L_s2 = s1; L_s2 = s1;
L_s2 <<= 15; L_s2 <<= 15;
/* Execution of a 31 bv 16 bits multiplication /* Execution of a 31 bv 16 bits multiplication
*/ */
msp = (word) SASR( L_z2, 15 ); msp = (word) SASR( L_z2, 15 );
lsp = (word) (L_z2-((longword)msp<<15)); /* gsm_L_sub(L_z2,(msp<<15)); */ lsp = (word) (L_z2-((longword)msp<<15)); /* gsm_L_sub(L_z2,(msp<<15)); */
L_s2 += GSM_MULT_R( lsp, 32735 ); L_s2 += GSM_MULT_R( lsp, 32735 );
L_temp = (longword)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/ L_temp = (longword)msp * 32735; /* GSM_L_MULT(msp,32735) >> 1;*/
L_z2 = GSM_L_ADD( L_temp, L_s2 ); L_z2 = GSM_L_ADD( L_temp, L_s2 );
/* Compute sof[k] with rounding /* Compute sof[k] with rounding
*/ */
L_temp = GSM_L_ADD( L_z2, 16384 ); L_temp = GSM_L_ADD( L_z2, 16384 );
/* 4.2.3 Preemphasis /* 4.2.3 Preemphasis
*/ */
msp = (word) GSM_MULT_R( mp, -28180 ); msp = (word) GSM_MULT_R( mp, -28180 );
mp = (word) SASR( L_temp, 15 ); mp = (word) SASR( L_temp, 15 );
*so++ = (word) GSM_ADD( mp, msp ); *so++ = (word) GSM_ADD( mp, msp );
} }
S->z1 = z1; S->z1 = z1;
S->L_z2 = L_z2; S->L_z2 = L_z2;
S->mp = mp; S->mp = mp;
} }
差异被折叠。
/* /*
* table.c * table.c
* *
* Copyright 1992 by Jutta Degener and Carsten Bormann, Technische * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
* Universitaet Berlin. See the accompanying file "COPYRIGHT" for * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
* details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE. * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
*/ */
/* Most of these tables are inlined at their point of use. /* Most of these tables are inlined at their point of use.
*/ */
/* 4.4 TABLES USED IN THE FIXED POINT IMPLEMENTATION OF THE RPE-LTP /* 4.4 TABLES USED IN THE FIXED POINT IMPLEMENTATION OF THE RPE-LTP
* CODER AND DECODER * CODER AND DECODER
* *
* (Most of them inlined, so watch out.) * (Most of them inlined, so watch out.)
*/ */
#define GSM_TABLE_C #define GSM_TABLE_C
#include "private.h" #include "private.h"
#include "gsm.h" #include "gsm.h"
/* Table 4.1 Quantization of the Log.-Area Ratios /* Table 4.1 Quantization of the Log.-Area Ratios
*/ */
/* i 1 2 3 4 5 6 7 8 */ /* i 1 2 3 4 5 6 7 8 */
word gsm_A[8] = {20480, 20480, 20480, 20480, 13964, 15360, 8534, 9036}; word gsm_A[8] = {20480, 20480, 20480, 20480, 13964, 15360, 8534, 9036};
word gsm_B[8] = { 0, 0, 2048, -2560, 94, -1792, -341, -1144}; word gsm_B[8] = { 0, 0, 2048, -2560, 94, -1792, -341, -1144};
word gsm_MIC[8] = { -32, -32, -16, -16, -8, -8, -4, -4 }; word gsm_MIC[8] = { -32, -32, -16, -16, -8, -8, -4, -4 };
word gsm_MAC[8] = { 31, 31, 15, 15, 7, 7, 3, 3 }; word gsm_MAC[8] = { 31, 31, 15, 15, 7, 7, 3, 3 };
/* Table 4.2 Tabulation of 1/A[1..8] /* Table 4.2 Tabulation of 1/A[1..8]
*/ */
word gsm_INVA[8]={ 13107, 13107, 13107, 13107, 19223, 17476, 31454, 29708 }; word gsm_INVA[8]={ 13107, 13107, 13107, 13107, 19223, 17476, 31454, 29708 };
/* Table 4.3a Decision level of the LTP gain quantizer /* Table 4.3a Decision level of the LTP gain quantizer
*/ */
/* bc 0 1 2 3 */ /* bc 0 1 2 3 */
word gsm_DLB[4] = { 6554, 16384, 26214, 32767 }; word gsm_DLB[4] = { 6554, 16384, 26214, 32767 };
/* Table 4.3b Quantization levels of the LTP gain quantizer /* Table 4.3b Quantization levels of the LTP gain quantizer
*/ */
/* bc 0 1 2 3 */ /* bc 0 1 2 3 */
word gsm_QLB[4] = { 3277, 11469, 21299, 32767 }; word gsm_QLB[4] = { 3277, 11469, 21299, 32767 };
/* Table 4.4 Coefficients of the weighting filter /* Table 4.4 Coefficients of the weighting filter
*/ */
/* i 0 1 2 3 4 5 6 7 8 9 10 */ /* i 0 1 2 3 4 5 6 7 8 9 10 */
word gsm_H[11] = {-134, -374, 0, 2054, 5741, 8192, 5741, 2054, 0, -374, -134 }; word gsm_H[11] = {-134, -374, 0, 2054, 5741, 8192, 5741, 2054, 0, -374, -134 };
/* Table 4.5 Normalized inverse mantissa used to compute xM/xmax /* Table 4.5 Normalized inverse mantissa used to compute xM/xmax
*/ */
/* i 0 1 2 3 4 5 6 7 */ /* i 0 1 2 3 4 5 6 7 */
word gsm_NRFAC[8] = { 29128, 26215, 23832, 21846, 20165, 18725, 17476, 16384 }; word gsm_NRFAC[8] = { 29128, 26215, 23832, 21846, 20165, 18725, 17476, 16384 };
/* Table 4.6 Normalized direct mantissa used to compute xM/xmax /* Table 4.6 Normalized direct mantissa used to compute xM/xmax
*/ */
/* i 0 1 2 3 4 5 6 7 */ /* i 0 1 2 3 4 5 6 7 */
word gsm_FAC[8] = { 18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767 }; word gsm_FAC[8] = { 18431, 20479, 22527, 24575, 26623, 28671, 30719, 32767 };
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论