make mpglib more not threadsafe

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6704 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-12-12 20:50:58 +00:00
parent 5bd41e52c0
commit 3eb3671fb2
3 changed files with 21 additions and 16 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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 *);