changeset 279:52b9f37998db

Removed global state variable; should be thread safe now.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 14 Mar 2002 16:38:59 +0000
parents dfe4a46f88f7
children 06fbb106a554
files decoders/mpglib/decode_i386.c decoders/mpglib/interface.c decoders/mpglib/layer1.c decoders/mpglib/layer2.c decoders/mpglib/layer3.c decoders/mpglib/mpg123_sdlsound.h
diffstat 6 files changed, 45 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/decoders/mpglib/decode_i386.c	Thu Mar 14 16:38:32 2002 +0000
+++ b/decoders/mpglib/decode_i386.c	Thu Mar 14 16:38:59 2002 +0000
@@ -17,22 +17,21 @@
 #include "mpg123_sdlsound.h"
 #include "mpglib_sdlsound.h"
 
-extern struct mpstr *gmp;
-
  /* old WRITE_SAMPLE */
 #define WRITE_SAMPLE(samples,sum,clip) \
   if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
   else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
   else { *(samples) = sum; }
 
-int synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
+int synth_1to1_mono(real *bandPtr,unsigned char *samples,
+                    int *pnt, struct mpstr *mp)
 {
   short samples_tmp[64];
   short *tmp1 = samples_tmp;
   int i,ret;
   int pnt1 = 0;
 
-  ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
+  ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1,mp);
   samples += *pnt;
 
   for(i=0;i<32;i++) {
@@ -46,7 +45,8 @@
 }
 
 
-int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
+int synth_1to1(real *bandPtr,int channel,unsigned char *out,
+               int *pnt, struct mpstr *mp)
 {
   static const int step = 2;
   int bo;
@@ -56,16 +56,16 @@
   int clip = 0; 
   int bo1;
 
-  bo = gmp->synth_bo;
+  bo = mp->synth_bo;
 
   if(!channel) {
     bo--;
     bo &= 0xf;
-    buf = gmp->synth_buffs[0];
+    buf = mp->synth_buffs[0];
   }
   else {
     samples++;
-    buf = gmp->synth_buffs[1];
+    buf = mp->synth_buffs[1];
   }
 
   if(bo & 0x1) {
@@ -79,7 +79,7 @@
     dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
   }
 
-  gmp->synth_bo = bo;
+  mp->synth_bo = bo;
   
   {
     register int j;
--- a/decoders/mpglib/interface.c	Thu Mar 14 16:38:32 2002 +0000
+++ b/decoders/mpglib/interface.c	Thu Mar 14 16:38:59 2002 +0000
@@ -11,7 +11,7 @@
 #include "mpglib_sdlsound.h"
 
 /* Global mp .. it's a hack */
-struct mpstr *gmp;
+/*struct mpstr *gmp;*/
 
 
 BOOL InitMP3(struct mpstr *mp) 
@@ -158,8 +158,6 @@
 {
 	int len;
 
-	gmp = mp;
-
 	if(osize < 4608) {
 		Sound_SetError("MPGLIB: Not enough output space for decoding!");
 		return MP3_ERR;
@@ -217,13 +215,13 @@
            getbits(16);
         switch(mp->fr.lay) {
           case 1:
-	    do_layer1(&mp->fr,(unsigned char *) out,done);
+	    do_layer1(&mp->fr,(unsigned char *) out,done,mp);
             break;
           case 2:
-	    do_layer2(&mp->fr,(unsigned char *) out,done);
+	    do_layer2(&mp->fr,(unsigned char *) out,done,mp);
             break;
           case 3:
-	    do_layer3(&mp->fr,(unsigned char *) out,done);
+	    do_layer3(&mp->fr,(unsigned char *) out,done,mp);
             break;
         }
 
@@ -233,17 +231,17 @@
 	return MP3_OK;
 }
 
-int set_pointer(long backstep)
+int set_pointer(long backstep, struct mpstr *mp)
 {
   unsigned char *bsbufold;
-  if(gmp->fsizeold < 0 && backstep > 0) {
+  if(mp->fsizeold < 0 && backstep > 0) {
     Sound_SetError("MPGLIB: Can't step back!"); /* FIXME: need formatting: %ld!\n",backstep); */
     return MP3_ERR;
   }
-  bsbufold = gmp->bsspace[gmp->bsnum] + 512;
+  bsbufold = mp->bsspace[mp->bsnum] + 512;
   wordpointer -= backstep;
   if (backstep)
-    memcpy(wordpointer,bsbufold+gmp->fsizeold-backstep,backstep);
+    memcpy(wordpointer,bsbufold+mp->fsizeold-backstep,backstep);
   bitindex = 0;
   return MP3_OK;
 }
--- a/decoders/mpglib/layer1.c	Thu Mar 14 16:38:32 2002 +0000
+++ b/decoders/mpglib/layer1.c	Thu Mar 14 16:38:59 2002 +0000
@@ -111,7 +111,7 @@
   }
 }
 
-int do_layer1(struct frame *fr,unsigned char *pcm_sample,int *pcm_point)
+int do_layer1(struct frame *fr,unsigned char *pcm_sample,int *pcm_point,struct mpstr *mp)
 {
   int clip=0;
   int i,stereo = fr->stereo;
@@ -132,12 +132,12 @@
     I_step_two(fraction,balloc,scale_index,fr);
 
       if(single >= 0) {
-        clip += synth_1to1_mono( (real*)fraction[single],pcm_sample,pcm_point);
+        clip += synth_1to1_mono( (real*)fraction[single],pcm_sample,pcm_point,mp);
       }
       else {
         int p1 = *pcm_point;
-        clip += synth_1to1( (real*)fraction[0],0,pcm_sample,&p1);
-        clip += synth_1to1( (real*)fraction[1],1,pcm_sample,pcm_point);
+        clip += synth_1to1( (real*)fraction[0],0,pcm_sample,&p1,mp);
+        clip += synth_1to1( (real*)fraction[1],1,pcm_sample,pcm_point,mp);
       }
   }
 
--- a/decoders/mpglib/layer2.c	Thu Mar 14 16:38:32 2002 +0000
+++ b/decoders/mpglib/layer2.c	Thu Mar 14 16:38:59 2002 +0000
@@ -247,7 +247,7 @@
   fr->II_sblimit = sblim;
 }
 
-int do_layer2(struct frame *fr,unsigned char *pcm_sample,int *pcm_point)
+int do_layer2(struct frame *fr,unsigned char *pcm_sample,int *pcm_point,struct mpstr *mp)
 {
   int clip=0;
   int i,j;
@@ -271,12 +271,12 @@
     II_step_two(bit_alloc,fraction,scale,fr,i>>2);
     for (j=0;j<3;j++) {
       if(single >= 0) {
-        clip += synth_1to1_mono(fraction[0][j],pcm_sample,pcm_point);
+        clip += synth_1to1_mono(fraction[0][j],pcm_sample,pcm_point,mp);
       }
       else {
         int p1 = *pcm_point;
-        clip += synth_1to1(fraction[0][j],0,pcm_sample,&p1);
-        clip += synth_1to1(fraction[1][j],1,pcm_sample,pcm_point);
+        clip += synth_1to1(fraction[0][j],0,pcm_sample,&p1,mp);
+        clip += synth_1to1(fraction[1][j],1,pcm_sample,pcm_point,mp);
       }
 
     }
--- a/decoders/mpglib/layer3.c	Thu Mar 14 16:38:32 2002 +0000
+++ b/decoders/mpglib/layer3.c	Thu Mar 14 16:38:59 2002 +0000
@@ -16,11 +16,8 @@
 #include "mpglib_sdlsound.h"
 #include "huffman.h"
 
-extern struct mpstr *gmp;
-
 #define MPEG1
 
-
 static real ispow[8207];
 static real aa_ca[8],aa_cs[8];
 static real COS1[12][6];
@@ -1819,11 +1816,11 @@
  * III_hybrid
  */
 static void III_hybrid(real fsIn[SBLIMIT][SSLIMIT],real tsOut[SSLIMIT][SBLIMIT],
-   int ch,struct gr_info_s *gr_info)
+   int ch,struct gr_info_s *gr_info,struct mpstr *mp)
 {
    real *tspnt = (real *) tsOut;
-   real (*block)[2][SBLIMIT*SSLIMIT] = gmp->hybrid_block;
-   int *blc = gmp->hybrid_blc;
+   real (*block)[2][SBLIMIT*SSLIMIT] = mp->hybrid_block;
+   int *blc = mp->hybrid_blc;
    real *rawout1,*rawout2;
    int bt;
    int sb = 0;
@@ -1870,7 +1867,7 @@
 /*
  * main layer3 handler
  */
-int do_layer3(struct frame *fr,unsigned char *pcm_sample,int *pcm_point)
+int do_layer3(struct frame *fr,unsigned char *pcm_sample,int *pcm_point,struct mpstr *mp)
 {
   int gr, ch, ss,clip=0;
   int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */
@@ -1912,7 +1909,7 @@
 #endif
   }
 
-  if(set_pointer(sideinfo.main_data_begin) == MP3_ERR)
+  if(set_pointer(sideinfo.main_data_begin,mp) == MP3_ERR)
     return -1;
 
   for (gr=0;gr<granules;gr++) 
@@ -1929,7 +1926,7 @@
 #ifdef MPEG1
         part2bits = III_get_scale_factors_1(scalefacs[0],gr_info);
 #else
-    Sound_SetError("MPGLIB: Not supported!");
+        Sound_SetError("MPGLIB: Not supported!");
 #endif
       }
       if(III_dequantize_sample(hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits))
@@ -1944,7 +1941,7 @@
 #ifdef MPEG1
         part2bits = III_get_scale_factors_1(scalefacs[1],gr_info);
 #else
-    Sound_SetError("MPGLIB: Not supported!");
+        Sound_SetError("MPGLIB: Not supported!");
 #endif
       }
 
@@ -1995,17 +1992,17 @@
     for(ch=0;ch<stereo1;ch++) {
       struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]);
       III_antialias(hybridIn[ch],gr_info);
-      III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info);
+      III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info,mp);
     }
 
     for(ss=0;ss<SSLIMIT;ss++) {
       if(single >= 0) {
-        clip += synth_1to1_mono(hybridOut[0][ss],pcm_sample,pcm_point);
+        clip += synth_1to1_mono(hybridOut[0][ss],pcm_sample,pcm_point,mp);
       }
       else {
         int p1 = *pcm_point;
-        clip += synth_1to1(hybridOut[0][ss],0,pcm_sample,&p1);
-        clip += synth_1to1(hybridOut[1][ss],1,pcm_sample,pcm_point);
+        clip += synth_1to1(hybridOut[0][ss],0,pcm_sample,&p1,mp);
+        clip += synth_1to1(hybridOut[1][ss],1,pcm_sample,pcm_point,mp);
       }
     }
   }
--- a/decoders/mpglib/mpg123_sdlsound.h	Thu Mar 14 16:38:32 2002 +0000
+++ b/decoders/mpglib/mpg123_sdlsound.h	Thu Mar 14 16:38:59 2002 +0000
@@ -96,18 +96,20 @@
 	int checkrange;
 };
 
+struct mpstr;  /* forward declaration. */
+
 extern unsigned int   get1bit(void);
 extern unsigned int   getbits(int);
 extern unsigned int   getbits_fast(int);
-extern int set_pointer(long);
+extern int set_pointer(long,struct mpstr *);
 
 extern unsigned char *wordpointer;
 extern int bitindex;
 
 extern void make_decode_tables(long scaleval);
-extern int do_layer3(struct frame *fr,unsigned char *,int *);
-extern int do_layer2(struct frame *fr,unsigned char *,int *);
-extern int do_layer1(struct frame *fr,unsigned char *,int *);
+extern int do_layer3(struct frame *fr,unsigned char *,int *,struct mpstr *);
+extern int do_layer2(struct frame *fr,unsigned char *,int *,struct mpstr *);
+extern int do_layer1(struct frame *fr,unsigned char *,int *,struct mpstr *);
 extern int decode_header(struct frame *fr,unsigned long newhead);
 
 
@@ -142,9 +144,10 @@
   } ch[2];
 };
 
-extern int synth_1to1 (real *,int,unsigned char *,int *);
+
+extern int synth_1to1 (real *,int,unsigned char *,int *,struct mpstr *);
 extern int synth_1to1_8bit (real *,int,unsigned char *,int *);
-extern int synth_1to1_mono (real *,unsigned char *,int *);
+extern int synth_1to1_mono (real *,unsigned char *,int *,struct mpstr *);
 extern int synth_1to1_mono2stereo (real *,unsigned char *,int *);
 extern int synth_1to1_8bit_mono (real *,unsigned char *,int *);
 extern int synth_1to1_8bit_mono2stereo (real *,unsigned char *,int *);