From 3eb3671fb20768ded13a9cd805b84e22b3a6dc53 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 12 Dec 2007 20:50:58 +0000 Subject: [PATCH] make mpglib more not threadsafe git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6704 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/formats/mod_shout/decode_ntom.c | 26 ++++++++++++------------- src/mod/formats/mod_shout/interface.c | 5 ++++- src/mod/formats/mod_shout/mpglib.h | 6 ++++-- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/mod/formats/mod_shout/decode_ntom.c b/src/mod/formats/mod_shout/decode_ntom.c index 59c11d0b85..2e927ba2d2 100644 --- a/src/mod/formats/mod_shout/decode_ntom.c +++ b/src/mod/formats/mod_shout/decode_ntom.c @@ -20,12 +20,12 @@ else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \ else { *(samples) = sum; } -#define NTOM_MUL (32768) -static unsigned long ntom_val[2] = { NTOM_MUL >> 1, NTOM_MUL >> 1 }; -static unsigned long ntom_step = NTOM_MUL; + +//static unsigned long ntom_val[2] = { NTOM_MUL >> 1, NTOM_MUL >> 1 }; +//static unsigned long ntom_step = NTOM_MUL; -int synth_ntom_set_step(long m, long n) +int synth_ntom_set_step(struct mpstr *mp, long m, long n) { if (param.verbose > 1) debug_printf("Init rate converter: %ld->%ld\n", m, n); @@ -36,14 +36,14 @@ int synth_ntom_set_step(long m, long n) } n *= NTOM_MUL; - ntom_step = n / m; + mp->ntom_step = n / m; - if (ntom_step > 8 * NTOM_MUL) { + if (mp->ntom_step > 8 * NTOM_MUL) { debug_printf("%d max. 1:8 conversion allowed!\n", __LINE__); return (1); } - ntom_val[0] = ntom_val[1] = NTOM_MUL >> 1; + mp->ntom_val[0] = mp->ntom_val[1] = NTOM_MUL >> 1; return (0); @@ -89,12 +89,12 @@ int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out bo--; bo &= 0xf; buf = mp->synth_buffs[0]; - ntom = ntom_val[1] = ntom_val[0]; + ntom = mp->ntom_val[1] = mp->ntom_val[0]; } else { samples++; out += 2; /* to compute the right *pnt value */ buf = mp->synth_buffs[1]; - ntom = ntom_val[1]; + ntom = mp->ntom_val[1]; } if (bo & 0x1) { @@ -116,7 +116,7 @@ int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out for (j = 16; j; j--, window += 0x10) { real sum; - ntom += ntom_step; + ntom += mp->ntom_step; if (ntom < NTOM_MUL) { window += 16; b0 += 16; @@ -147,7 +147,7 @@ int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out } } - ntom += ntom_step; + ntom += mp->ntom_step; if (ntom >= NTOM_MUL) { real sum; sum = window[0x0] * b0[0x0]; @@ -172,7 +172,7 @@ int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out for (j = 15; j; j--, b0 -= 0x20, window -= 0x10) { real sum; - ntom += ntom_step; + ntom += mp->ntom_step; if (ntom < NTOM_MUL) { window -= 16; b0 += 16; @@ -204,7 +204,7 @@ int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out } } - ntom_val[channel] = ntom; + mp->ntom_val[channel] = ntom; *pnt = ((unsigned char *) samples - out); return clip; diff --git a/src/mod/formats/mod_shout/interface.c b/src/mod/formats/mod_shout/interface.c index f188189377..b5af8fe85e 100644 --- a/src/mod/formats/mod_shout/interface.c +++ b/src/mod/formats/mod_shout/interface.c @@ -27,6 +27,9 @@ BOOL InitMP3(struct mpstr *mp, long outscale, int samplerate) mp->bsnum = 0; mp->synth_bo = 1; mp->outsamplerate = samplerate; + mp->ntom_val[0] = NTOM_MUL >> 1; + mp->ntom_val[1] = NTOM_MUL >> 1; + mp->ntom_step = NTOM_MUL; make_decode_tables_scale(mp, outscale); @@ -241,7 +244,7 @@ int decodeMP3(struct mpstr *mp, char *in, int isize, char *out, int osize, int * m = n; } - if (synth_ntom_set_step(n, m)) + if (synth_ntom_set_step(mp, n, m)) return MP3_ERR; diff --git a/src/mod/formats/mod_shout/mpglib.h b/src/mod/formats/mod_shout/mpglib.h index 3ad9283eb6..93176eca86 100644 --- a/src/mod/formats/mod_shout/mpglib.h +++ b/src/mod/formats/mod_shout/mpglib.h @@ -3,6 +3,7 @@ #else #define debug_printf(fmt,...) #endif +#define NTOM_MUL (32768) struct buf { unsigned char *pnt; @@ -39,7 +40,8 @@ struct mpstr { int longLimit[9][23]; /*sample limits re setting volume */ int shortLimit[9][14]; real decwin[512 + 32]; /* scale table */ - + unsigned long ntom_val[2]; + unsigned long ntom_step; }; #define BOOL int @@ -54,7 +56,7 @@ BOOL InitMP3(struct mpstr *mp, long outscale, int samplerate); int decodeMP3(struct mpstr *mp, char *inmemory, int inmemsize, char *outmemory, int outmemsize, int *done); void ExitMP3(struct mpstr *mp); -extern int synth_ntom_set_step(long, long); +extern int synth_ntom_set_step(struct mpstr *mp, long, long); extern int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out, int *pnt); extern int synth_ntom_mono(struct mpstr *mp, real * bandPtr, unsigned char *samples, int *pnt); extern int synth_ntom_8bit(real *, int, unsigned char *, int *);