Browse Source

Remove incorrect copyright headers

David Rose 24 years ago
parent
commit
0ad075823f

+ 124 - 141
panda/src/mpg123/audio.c

@@ -1,20 +1,3 @@
-/* Filename: audio.c
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 
 #include "mpg123.h"
 #include "mpg123.h"
 #ifdef WIN32
 #ifdef WIN32
@@ -53,7 +36,7 @@ void audio_info_struct_init(struct audio_info_struct *ai)
 
 
 struct audio_name audio_val2name[NUM_ENCODINGS+1] = {
 struct audio_name audio_val2name[NUM_ENCODINGS+1] = {
  { AUDIO_FORMAT_SIGNED_16  , "signed 16 bit" , "s16 " } ,
  { AUDIO_FORMAT_SIGNED_16  , "signed 16 bit" , "s16 " } ,
- { AUDIO_FORMAT_UNSIGNED_16, "unsigned 16 bit" , "u16 " } ,
+ { AUDIO_FORMAT_UNSIGNED_16, "unsigned 16 bit" , "u16 " } ,  
  { AUDIO_FORMAT_UNSIGNED_8 , "unsigned 8 bit" , "u8  " } ,
  { AUDIO_FORMAT_UNSIGNED_8 , "unsigned 8 bit" , "u8  " } ,
  { AUDIO_FORMAT_SIGNED_8   , "signed 8 bit" , "s8  " } ,
  { AUDIO_FORMAT_SIGNED_8   , "signed 8 bit" , "s8  " } ,
  { AUDIO_FORMAT_ULAW_8     , "mu-law (8 bit)" , "ulaw " } ,
  { AUDIO_FORMAT_ULAW_8     , "mu-law (8 bit)" , "ulaw " } ,
@@ -62,20 +45,20 @@ struct audio_name audio_val2name[NUM_ENCODINGS+1] = {
 };
 };
 
 
 #if 0
 #if 0
-static char *channel_name[NUM_CHANNELS] =
+static char *channel_name[NUM_CHANNELS] = 
  { "mono" , "stereo" };
  { "mono" , "stereo" };
 #endif
 #endif
 
 
 static int channels[NUM_CHANNELS] = { 1 , 2 };
 static int channels[NUM_CHANNELS] = { 1 , 2 };
-static int rates[NUM_RATES] = {
-         8000, 11025, 12000,
-        16000, 22050, 24000,
-        32000, 44100, 48000,
-        8000    /* 8000 = dummy for user forced */
+static int rates[NUM_RATES] = { 
+     8000, 11025, 12000, 
+    16000, 22050, 24000,
+    32000, 44100, 48000,
+    8000    /* 8000 = dummy for user forced */
 
 
 };
 };
 static int encodings[NUM_ENCODINGS] = {
 static int encodings[NUM_ENCODINGS] = {
- AUDIO_FORMAT_SIGNED_16,
+ AUDIO_FORMAT_SIGNED_16, 
  AUDIO_FORMAT_UNSIGNED_16,
  AUDIO_FORMAT_UNSIGNED_16,
  AUDIO_FORMAT_UNSIGNED_8,
  AUDIO_FORMAT_UNSIGNED_8,
  AUDIO_FORMAT_SIGNED_8,
  AUDIO_FORMAT_SIGNED_8,
@@ -87,81 +70,81 @@ static char capabilities[NUM_CHANNELS][NUM_ENCODINGS][NUM_RATES];
 
 
 void audio_capabilities(struct audio_info_struct *ai)
 void audio_capabilities(struct audio_info_struct *ai)
 {
 {
-        int fmts;
-        int i,j,k,k1=NUM_RATES-1;
-        struct audio_info_struct ai1 = *ai;
+    int fmts;
+    int i,j,k,k1=NUM_RATES-1;
+    struct audio_info_struct ai1 = *ai;
 
 
         if (param.outmode != DECODE_AUDIO) {
         if (param.outmode != DECODE_AUDIO) {
-                memset(capabilities,1,sizeof(capabilities));
-                return;
+        memset(capabilities,1,sizeof(capabilities));
+        return;
+    }
+
+    memset(capabilities,0,sizeof(capabilities));
+    if(param.force_rate) {
+        rates[NUM_RATES-1] = param.force_rate;
+        k1 = NUM_RATES;
+    }
+
+    if(audio_open(&ai1) < 0) {
+        perror("audio");
+        exit(1);
+    }
+
+    for(i=0;i<NUM_CHANNELS;i++) {
+        for(j=0;j<NUM_RATES;j++) {
+            ai1.channels = channels[i];
+            ai1.rate = rates[j];
+            fmts = audio_get_formats(&ai1);
+            if(fmts < 0)
+                continue;
+            for(k=0;k<NUM_ENCODINGS;k++) {
+                if((fmts & encodings[k]) == encodings[k])
+                    capabilities[i][k][j] = 1;
+            }
         }
         }
+    }
 
 
-        memset(capabilities,0,sizeof(capabilities));
-        if(param.force_rate) {
-                rates[NUM_RATES-1] = param.force_rate;
-                k1 = NUM_RATES;
-        }
+    audio_close(&ai1);
 
 
-        if(audio_open(&ai1) < 0) {
-                perror("audio");
-                exit(1);
+    if(param.verbose > 1) {
+        fprintf(stderr,"\nAudio capabilities:\n        |");
+        for(j=0;j<NUM_ENCODINGS;j++) {
+            fprintf(stderr," %5s |",audio_val2name[j].sname);
         }
         }
-
-        for(i=0;i<NUM_CHANNELS;i++) {
-                for(j=0;j<NUM_RATES;j++) {
-                        ai1.channels = channels[i];
-                        ai1.rate = rates[j];
-                        fmts = audio_get_formats(&ai1);
-                        if(fmts < 0)
-                                continue;
-                        for(k=0;k<NUM_ENCODINGS;k++) {
-                                if((fmts & encodings[k]) == encodings[k])
-                                        capabilities[i][k][j] = 1;
-                        }
-                }
-        }
-
-        audio_close(&ai1);
-
-        if(param.verbose > 1) {
-                fprintf(stderr,"\nAudio capabilities:\n        |");
-                for(j=0;j<NUM_ENCODINGS;j++) {
-                        fprintf(stderr," %5s |",audio_val2name[j].sname);
-                }
-                fprintf(stderr,"\n --------------------------------------------------------\n");
-                for(k=0;k<k1;k++) {
-                        fprintf(stderr," %5d  |",rates[k]);
-                        for(j=0;j<NUM_ENCODINGS;j++) {
-                                if(capabilities[0][j][k]) {
-                                        if(capabilities[1][j][k])
-                                                fprintf(stderr,"  M/S  |");
-                                        else
-                                                fprintf(stderr,"   M   |");
-                                }
-                                else if(capabilities[1][j][k])
-                                        fprintf(stderr,"   S   |");
-                                else
-                                        fprintf(stderr,"       |");
-                        }
-                        fprintf(stderr,"\n");
+        fprintf(stderr,"\n --------------------------------------------------------\n");
+        for(k=0;k<k1;k++) {
+            fprintf(stderr," %5d  |",rates[k]);
+            for(j=0;j<NUM_ENCODINGS;j++) {
+                if(capabilities[0][j][k]) {
+                    if(capabilities[1][j][k])
+                        fprintf(stderr,"  M/S  |");
+                    else
+                        fprintf(stderr,"   M   |");
                 }
                 }
-                fprintf(stderr,"\n");
+                else if(capabilities[1][j][k])
+                    fprintf(stderr,"   S   |");
+                else
+                    fprintf(stderr,"       |");
+            }
+            fprintf(stderr,"\n");
         }
         }
+        fprintf(stderr,"\n");
+    }
 }
 }
 
 
 static int rate2num(int r)
 static int rate2num(int r)
 {
 {
-        int i;
-        for(i=0;i<NUM_RATES;i++)
-                if(rates[i] == r)
-                        return i;
-        return -1;
+    int i;
+    for(i=0;i<NUM_RATES;i++) 
+        if(rates[i] == r)
+            return i;
+    return -1;
 }
 }
 
 
 
 
 static int audio_fit_cap_helper(struct audio_info_struct *ai,int rn,int f0,int f2,int c)
 static int audio_fit_cap_helper(struct audio_info_struct *ai,int rn,int f0,int f2,int c)
 {
 {
-        int i;
+    int i;
 
 
         if(rn >= 0) {
         if(rn >= 0) {
                 for(i=f0;i<f2;i++) {
                 for(i=f0;i<f2;i++) {
@@ -169,11 +152,11 @@ static int audio_fit_cap_helper(struct audio_info_struct *ai,int rn,int f0,int f
                                 ai->rate = rates[rn];
                                 ai->rate = rates[rn];
                                 ai->format = encodings[i];
                                 ai->format = encodings[i];
                                 ai->channels = channels[c];
                                 ai->channels = channels[c];
-                                return 1;
+                return 1;
                         }
                         }
                 }
                 }
         }
         }
-        return 0;
+    return 0;
 
 
 }
 }
 
 
@@ -183,64 +166,64 @@ static int audio_fit_cap_helper(struct audio_info_struct *ai,int rn,int f0,int f
  */
  */
 void audio_fit_capabilities(struct audio_info_struct *ai,int c,int r)
 void audio_fit_capabilities(struct audio_info_struct *ai,int c,int r)
 {
 {
-        int rn;
-        int f0=0;
+    int rn;
+    int f0=0;
 
 
-        if(param.force_8bit) {
-                f0 = 2;
-        }
+    if(param.force_8bit) {
+        f0 = 2;
+    }
 
 
-        c--; /* stereo=1 ,mono=0 */
+    c--; /* stereo=1 ,mono=0 */
 
 
-        if(param.force_mono >= 0)
-                c = 0;
-        if(param.force_stereo)
-                c = 1;
+    if(param.force_mono >= 0)
+        c = 0;
+    if(param.force_stereo)
+        c = 1;
 
 
-        if(param.force_rate) {
-                rn = rate2num(param.force_rate);
-                if(audio_fit_cap_helper(ai,rn,f0,2,c))
-                        return;
-                if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
-                        return;
-
-                if(c == 1 && !param.force_stereo)
-                        c = 0;
-                else if(c == 0 && !param.force_mono)
-                        c = 1;
-
-                if(audio_fit_cap_helper(ai,rn,f0,2,c))
-                        return;
-                if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
-                        return;
-
-                fprintf(stderr,"No supported rate found!\n");
-                exit(1);
-        }
-
-        rn = rate2num(r>>0);
-        if(audio_fit_cap_helper(ai,rn,f0,2,c))
-                return;
-        rn = rate2num(r>>1);
-        if(audio_fit_cap_helper(ai,rn,f0,2,c))
-                return;
-        rn = rate2num(r>>2);
+    if(param.force_rate) {
+        rn = rate2num(param.force_rate);
         if(audio_fit_cap_helper(ai,rn,f0,2,c))
         if(audio_fit_cap_helper(ai,rn,f0,2,c))
-                return;
-
-        rn = rate2num(r>>0);
+            return;
         if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
         if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
-                return;
-        rn = rate2num(r>>1);
-        if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
-                return;
-        rn = rate2num(r>>2);
+            return;
+
+        if(c == 1 && !param.force_stereo)
+            c = 0;
+        else if(c == 0 && !param.force_mono)
+            c = 1;
+
+        if(audio_fit_cap_helper(ai,rn,f0,2,c))
+            return;
         if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
         if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
-                return;
+            return;
+
+        fprintf(stderr,"No supported rate found!\n");
+        exit(1);
+    }
+
+    rn = rate2num(r>>0);
+    if(audio_fit_cap_helper(ai,rn,f0,2,c))
+        return;
+    rn = rate2num(r>>1);
+    if(audio_fit_cap_helper(ai,rn,f0,2,c))
+        return;
+    rn = rate2num(r>>2);
+    if(audio_fit_cap_helper(ai,rn,f0,2,c))
+        return;
+
+    rn = rate2num(r>>0);
+    if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
+        return;
+    rn = rate2num(r>>1);
+    if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
+        return;
+    rn = rate2num(r>>2);
+    if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
+        return;
 
 
 
 
         if(c == 1 && !param.force_stereo)
         if(c == 1 && !param.force_stereo)
-                c = 0;
+        c = 0;
         else if(c == 0 && !param.force_mono)
         else if(c == 0 && !param.force_mono)
                 c = 1;
                 c = 1;
 
 
@@ -264,19 +247,19 @@ void audio_fit_capabilities(struct audio_info_struct *ai,int c,int r)
         if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
         if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
                 return;
                 return;
 
 
-        fprintf(stderr,"No supported rate found!\n");
-        exit(1);
+    fprintf(stderr,"No supported rate found!\n");
+    exit(1);
 }
 }
 
 
 char *audio_encoding_name(int format)
 char *audio_encoding_name(int format)
 {
 {
-        int i;
+    int i;
 
 
-        for(i=0;i<NUM_ENCODINGS;i++) {
-                if(audio_val2name[i].val == format)
-                        return audio_val2name[i].name;
-        }
-        return "Unknown";
+    for(i=0;i<NUM_ENCODINGS;i++) {
+        if(audio_val2name[i].val == format)
+            return audio_val2name[i].name;
+    }
+    return "Unknown";
 }
 }
 
 
 #if !defined(SOLARIS) && !defined(__NetBSD__) || defined(NAS)
 #if !defined(SOLARIS) && !defined(__NetBSD__) || defined(NAS)

+ 262 - 278
panda/src/mpg123/common.c

@@ -1,20 +1,4 @@
-/* Filename: common.c
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* GPL clean */
 
 
 #include <ctype.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdlib.h>
@@ -74,23 +58,23 @@ static int decode_header(struct frame *fr,unsigned long newhead);
 void audio_flush(int outmode, struct audio_info_struct *ai)
 void audio_flush(int outmode, struct audio_info_struct *ai)
 {
 {
     if (pcm_point) {
     if (pcm_point) {
-        switch (outmode) {
-        case DECODE_FILE:
-            write (OutputDescriptor, pcm_sample, pcm_point);
-            break;
-        case DECODE_AUDIO:
-            audio_play_samples (ai, pcm_sample, pcm_point);
-            break;
-        case DECODE_BUFFER:
-            write (buffer_fd[1], pcm_sample, pcm_point);
-            break;
-        case DECODE_WAV:
-        case DECODE_CDR:
-        case DECODE_AU:
-            wav_write(pcm_sample, pcm_point);
-            break;
-        }
-        pcm_point = 0;
+    switch (outmode) {
+    case DECODE_FILE:
+        write (OutputDescriptor, pcm_sample, pcm_point);
+        break;
+    case DECODE_AUDIO:
+        audio_play_samples (ai, pcm_sample, pcm_point);
+        break;
+    case DECODE_BUFFER:
+        write (buffer_fd[1], pcm_sample, pcm_point);
+        break;
+    case DECODE_WAV:
+    case DECODE_CDR:
+    case DECODE_AU:
+        wav_write(pcm_sample, pcm_point);
+        break;
+    }
+    pcm_point = 0;
     }
     }
 }
 }
 
 
@@ -109,7 +93,7 @@ void (*catchsignal(int signum, void(*handler)()))()
     sigemptyset(&new_sa.sa_mask);
     sigemptyset(&new_sa.sa_mask);
     new_sa.sa_flags = 0;
     new_sa.sa_flags = 0;
     if (sigaction(signum, &new_sa, &old_sa) == -1)
     if (sigaction(signum, &new_sa, &old_sa) == -1)
-        return ((void (*)()) -1);
+    return ((void (*)()) -1);
     return (old_sa.sa_handler);
     return (old_sa.sa_handler);
 }
 }
 #endif
 #endif
@@ -124,17 +108,17 @@ int head_check(unsigned long head)
 {
 {
 /* fprintf(stderr,"HC"); */
 /* fprintf(stderr,"HC"); */
     if( (head & 0xffe00000) != 0xffe00000)
     if( (head & 0xffe00000) != 0xffe00000)
-        return FALSE;
+    return FALSE;
     if(!((head>>17)&3))
     if(!((head>>17)&3))
-        return FALSE;
+    return FALSE;
     if( ((head>>12)&0xf) == 0xf)
     if( ((head>>12)&0xf) == 0xf)
-        return FALSE;
+    return FALSE;
     if( ((head>>10)&0x3) == 0x3 )
     if( ((head>>10)&0x3) == 0x3 )
-        return FALSE;
+    return FALSE;
 #if 0
 #if 0
     /* this would match on MPEG1/Layer1 streams with CRC = off */
     /* this would match on MPEG1/Layer1 streams with CRC = off */
     if ((head & 0xffff0000) == 0xffff0000)
     if ((head & 0xffff0000) == 0xffff0000)
-        return FALSE;
+    return FALSE;
 #endif
 #endif
 
 
     return TRUE;
     return TRUE;
@@ -153,129 +137,129 @@ int read_frame(struct frame *fr)
     fsizeold=fr->framesize;       /* for Layer3 */
     fsizeold=fr->framesize;       /* for Layer3 */
 
 
     if (param.halfspeed) {
     if (param.halfspeed) {
-        static int halfphase = 0;
-        if (halfphase--) {
-            bsi.bitindex = 0;
-            bsi.wordpointer = (unsigned char *) bsbuf;
-            if (fr->lay == 3)
-                memcpy (bsbuf, ssave, ssize);
-            return 1;
-        }
-        else
-            halfphase = param.halfspeed - 1;
+    static int halfphase = 0;
+    if (halfphase--) {
+        bsi.bitindex = 0;
+        bsi.wordpointer = (unsigned char *) bsbuf;
+        if (fr->lay == 3)
+        memcpy (bsbuf, ssave, ssize);
+        return 1;
+    }
+    else
+        halfphase = param.halfspeed - 1;
     }
     }
 
 
  read_again:
  read_again:
     if(!rd->head_read(rd,&newhead))
     if(!rd->head_read(rd,&newhead))
-        return FALSE;
+    return FALSE;
 
 
     if(1 || oldhead != newhead || !oldhead) {
     if(1 || oldhead != newhead || !oldhead) {
 
 
     init_resync:
     init_resync:
 
 
-        fr->header_change = 2;
-        if(oldhead) {
-            if((oldhead & 0xc00) == (newhead & 0xc00)) {
-                if( (oldhead & 0xc0) == 0 && (newhead & 0xc0) == 0)
-                    fr->header_change = 1;
-                else if( (oldhead & 0xc0) > 0 && (newhead & 0xc0) > 0)
-                    fr->header_change = 1;
-            }
+    fr->header_change = 2;
+    if(oldhead) {
+        if((oldhead & 0xc00) == (newhead & 0xc00)) {
+        if( (oldhead & 0xc0) == 0 && (newhead & 0xc0) == 0)
+            fr->header_change = 1; 
+        else if( (oldhead & 0xc0) > 0 && (newhead & 0xc0) > 0)
+            fr->header_change = 1;
         }
         }
+    }
 
 
 
 
 #ifdef SKIP_JUNK
 #ifdef SKIP_JUNK
-        if(!firsthead && !head_check(newhead) ) {
-            int i;
-
-            fprintf(stderr,"Junk at the beginning %08lx\n",newhead);
-
-            /* I even saw RIFF headers at the beginning of MPEG streams ;( */
-            if(newhead == ('R'<<24)+('I'<<16)+('F'<<8)+'F') {
-                if(!rd->head_read(rd,&newhead))
-                    return 0;
-                while(newhead != ('d'<<24)+('a'<<16)+('t'<<8)+'a') {
-                    if(!rd->head_shift(rd,&newhead))
-                        return 0;
-                }
-                if(!rd->head_read(rd,&newhead))
-                    return 0;
-                /* fprintf(stderr,"Skipped RIFF header!\n"); */
-                goto read_again;
-            }
-            {
-                /* step in byte steps through next 64K */
-                for(i=0;i<65536;i++) {
-                    if(!rd->head_shift(rd,&newhead))
-                        return 0;
-                    if(head_check(newhead))
-                        break;
-                }
-                if(i == 65536) {
-                    fprintf(stderr,"Giving up searching valid MPEG header\n");
-                    return 0;
-                }
-            }
-            /*
-             * should we additionaly check, whether a new frame starts at
-             * the next expected position? (some kind of read ahead)
-             * We could implement this easily, at least for files.
-             */
+    if(!firsthead && !head_check(newhead) ) {
+        int i;
+
+        fprintf(stderr,"Junk at the beginning %08lx\n",newhead);
+
+        /* I even saw RIFF headers at the beginning of MPEG streams ;( */
+        if(newhead == ('R'<<24)+('I'<<16)+('F'<<8)+'F') {
+        if(!rd->head_read(rd,&newhead))
+            return 0;
+        while(newhead != ('d'<<24)+('a'<<16)+('t'<<8)+'a') {
+            if(!rd->head_shift(rd,&newhead))
+            return 0;
         }
         }
+        if(!rd->head_read(rd,&newhead))
+            return 0;
+        /* fprintf(stderr,"Skipped RIFF header!\n"); */
+        goto read_again;
+        }
+        {
+        /* step in byte steps through next 64K */
+        for(i=0;i<65536;i++) {
+            if(!rd->head_shift(rd,&newhead))
+            return 0;
+            if(head_check(newhead))
+            break;
+        }
+        if(i == 65536) {
+            fprintf(stderr,"Giving up searching valid MPEG header\n");
+            return 0;
+        }
+        }
+        /* 
+         * should we additionaly check, whether a new frame starts at
+         * the next expected position? (some kind of read ahead)
+         * We could implement this easily, at least for files.
+         */
+    }
 #endif
 #endif
 
 
-        if( (newhead & 0xffe00000) != 0xffe00000) {
-            if (!param.quiet)
-                fprintf(stderr,"Illegal Audio-MPEG-Header 0x%08lx at offset 0x%lx.\n",
-                        newhead,rd->tell(rd)-4);
-            /* and those ugly ID3 tags */
-            if((newhead & 0xffffff00) == ('T'<<24)+('A'<<16)+('G'<<8)) {
-                rd->skip_bytes(rd,124);
-                fprintf(stderr,"Skipped ID3 Tag!\n");
-                goto read_again;
-            }
-            if (param.tryresync) {
-                int try = 0;
-                /* Read more bytes until we find something that looks
-                   reasonably like a valid header.  This is not a
-                   perfect strategy, but it should get us back on the
-                   track within a short time (and hopefully without
-                   too much distortion in the audio output).  */
-                do {
-                    try++;
-                    if(!rd->head_shift(rd,&newhead))
-                        return 0;
-                    if (!oldhead)
-                        goto init_resync;       /* "considered harmful", eh? */
-
-                } while ((newhead & HDRCMPMASK) != (oldhead & HDRCMPMASK)
-                         && (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK));
-                if (!param.quiet)
-                    fprintf (stderr, "Skipped %d bytes in input.\n", try);
-            }
-            else
-                return (0);
+    if( (newhead & 0xffe00000) != 0xffe00000) {
+        if (!param.quiet)
+        fprintf(stderr,"Illegal Audio-MPEG-Header 0x%08lx at offset 0x%lx.\n",
+            newhead,rd->tell(rd)-4);
+        /* and those ugly ID3 tags */
+        if((newhead & 0xffffff00) == ('T'<<24)+('A'<<16)+('G'<<8)) {
+        rd->skip_bytes(rd,124);
+        fprintf(stderr,"Skipped ID3 Tag!\n");
+        goto read_again;
+        }
+        if (param.tryresync) {
+        int try = 0;
+        /* Read more bytes until we find something that looks
+           reasonably like a valid header.  This is not a
+           perfect strategy, but it should get us back on the
+           track within a short time (and hopefully without
+           too much distortion in the audio output).  */
+        do {
+            try++;
+            if(!rd->head_shift(rd,&newhead))
+            return 0;
+            if (!oldhead)
+            goto init_resync;       /* "considered harmful", eh? */
+
+        } while ((newhead & HDRCMPMASK) != (oldhead & HDRCMPMASK)
+             && (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK));
+        if (!param.quiet)
+            fprintf (stderr, "Skipped %d bytes in input.\n", try);
         }
         }
+        else
+        return (0);
+    }
 
 
 /* fprintf(stderr,"+"); */
 /* fprintf(stderr,"+"); */
 
 
-        if (!firsthead) {
-            if(!decode_header(fr,newhead)) {
+    if (!firsthead) {
+        if(!decode_header(fr,newhead)) {
 /* fprintf(stderr,"A"); */
 /* fprintf(stderr,"A"); */
-                goto read_again;
-            }
-            firsthead = newhead;
-
+        goto read_again;
         }
         }
-        else if(!decode_header(fr,newhead)) {
+        firsthead = newhead;
+
+    }
+    else if(!decode_header(fr,newhead)) {
 /* fprintf(stderr,"B: %08lx\n",newhead); */
 /* fprintf(stderr,"B: %08lx\n",newhead); */
-            return 0;
+        return 0;
         }
         }
 
 
 /* fprintf(stderr,"-"); */
 /* fprintf(stderr,"-"); */
     }
     }
     else
     else
-        fr->header_change = 0;
+    fr->header_change = 0;
 
 
 /* fprintf(stderr,"FS: %d\n",fr->framesize); */
 /* fprintf(stderr,"FS: %d\n",fr->framesize); */
 
 
@@ -286,9 +270,9 @@ int read_frame(struct frame *fr)
 
 
     /* read main data into memory */
     /* read main data into memory */
     if(!rd->read_frame_body(rd,bsbuf,fr->framesize))
     if(!rd->read_frame_body(rd,bsbuf,fr->framesize))
-        return 0;
+    return 0;
 
 
-    {
+    { 
       /* Test */
       /* Test */
       static struct vbrHeader head;
       static struct vbrHeader head;
       static int vbr = 0;
       static int vbr = 0;
@@ -304,7 +288,7 @@ int read_frame(struct frame *fr)
     bsi.wordpointer = (unsigned char *) bsbuf;
     bsi.wordpointer = (unsigned char *) bsbuf;
 
 
     if (param.halfspeed && fr->lay == 3)
     if (param.halfspeed && fr->lay == 3)
-        memcpy (ssave, bsbuf, ssize);
+    memcpy (ssave, bsbuf, ssize);
 
 
     return 1;
     return 1;
 }
 }
@@ -317,32 +301,32 @@ int back_frame(struct reader *rds,struct frame *fr,int num)
 {
 {
     long bytes;
     long bytes;
     unsigned long newhead;
     unsigned long newhead;
-
+  
     if(!firsthead)
     if(!firsthead)
-        return 0;
-
+    return 0;
+  
     bytes = (fr->framesize+8)*(num+2);
     bytes = (fr->framesize+8)*(num+2);
-
+  
     if(rds->back_bytes(rds,bytes) < 0)
     if(rds->back_bytes(rds,bytes) < 0)
-        return -1;
+    return -1;
     if(!rds->head_read(rds,&newhead))
     if(!rds->head_read(rds,&newhead))
-        return -1;
-
+    return -1;
+  
     while( (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK) ) {
     while( (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK) ) {
-        if(!rds->head_shift(rds,&newhead))
-            return -1;
+    if(!rds->head_shift(rds,&newhead))
+        return -1;
     }
     }
-
+  
     if(rds->back_bytes(rds,4) <0)
     if(rds->back_bytes(rds,4) <0)
-        return -1;
+    return -1;
 
 
     read_frame(fr);
     read_frame(fr);
     read_frame(fr);
     read_frame(fr);
-
+  
     if(fr->lay == 3) {
     if(fr->lay == 3) {
-        set_pointer(512);
+    set_pointer(512);
     }
     }
-
+  
     return 0;
     return 0;
 }
 }
 
 
@@ -355,32 +339,32 @@ static int decode_header(struct frame *fr,unsigned long newhead)
 {
 {
     if(!head_check(newhead)) {
     if(!head_check(newhead)) {
         fprintf(stderr,"Oopps header is wrong\n");
         fprintf(stderr,"Oopps header is wrong\n");
-        return 0;
+    return 0;
     }
     }
 
 
     if( newhead & (1<<20) ) {
     if( newhead & (1<<20) ) {
-        fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1;
-        fr->mpeg25 = 0;
+    fr->lsf = (newhead & (1<<19)) ? 0x0 : 0x1;
+    fr->mpeg25 = 0;
     }
     }
     else {
     else {
-        fr->lsf = 1;
-        fr->mpeg25 = 1;
+    fr->lsf = 1;
+    fr->mpeg25 = 1;
     }
     }
-
+    
     if (!param.tryresync || !oldhead) {
     if (!param.tryresync || !oldhead) {
-        /* If "tryresync" is true, assume that certain
-           parameters do not change within the stream! */
-        fr->lay = 4-((newhead>>17)&3);
-        if( ((newhead>>10)&0x3) == 0x3) {
-            fprintf(stderr,"Stream error\n");
-            exit(1);
-        }
-        if(fr->mpeg25) {
-            fr->sampling_frequency = 6 + ((newhead>>10)&0x3);
-        }
-        else
-            fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3);
-        fr->error_protection = ((newhead>>16)&0x1)^0x1;
+    /* If "tryresync" is true, assume that certain
+       parameters do not change within the stream! */
+    fr->lay = 4-((newhead>>17)&3);
+    if( ((newhead>>10)&0x3) == 0x3) {
+        fprintf(stderr,"Stream error\n");
+        exit(1);
+    }
+    if(fr->mpeg25) {
+        fr->sampling_frequency = 6 + ((newhead>>10)&0x3);
+    }
+    else
+        fr->sampling_frequency = ((newhead>>10)&0x3) + (fr->lsf*3);
+    fr->error_protection = ((newhead>>16)&0x1)^0x1;
     }
     }
 
 
     fr->bitrate_index = ((newhead>>12)&0xf);
     fr->bitrate_index = ((newhead>>12)&0xf);
@@ -397,8 +381,8 @@ static int decode_header(struct frame *fr,unsigned long newhead)
     oldhead = newhead;
     oldhead = newhead;
 
 
     if(!fr->bitrate_index) {
     if(!fr->bitrate_index) {
-        fprintf(stderr,"Free format not supported: (head %08lx)\n",newhead);
-        return (0);
+    fprintf(stderr,"Free format not supported: (head %08lx)\n",newhead);
+    return (0);
     }
     }
 
 
     switch(fr->lay) {
     switch(fr->lay) {
@@ -414,17 +398,17 @@ static int decode_header(struct frame *fr,unsigned long newhead)
         break;
         break;
     case 3:
     case 3:
         if(fr->lsf)
         if(fr->lsf)
-            ssize = (fr->stereo == 1) ? 9 : 17;
+        ssize = (fr->stereo == 1) ? 9 : 17;
         else
         else
-            ssize = (fr->stereo == 1) ? 17 : 32;
+        ssize = (fr->stereo == 1) ? 17 : 32;
         if(fr->error_protection)
         if(fr->error_protection)
-            ssize += 2;
+        ssize += 2;
         fr->framesize  = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
         fr->framesize  = (long) tabsel_123[fr->lsf][2][fr->bitrate_index] * 144000;
         fr->framesize /= freqs[fr->sampling_frequency]<<(fr->lsf);
         fr->framesize /= freqs[fr->sampling_frequency]<<(fr->lsf);
         fr->framesize = fr->framesize + fr->padding - 4;
         fr->framesize = fr->framesize + fr->padding - 4;
-        break;
+        break; 
     default:
     default:
-        fprintf(stderr,"Sorry, unknown layer type.\n");
+        fprintf(stderr,"Sorry, unknown layer type.\n"); 
         return (0);
         return (0);
     }
     }
     return 1;
     return 1;
@@ -439,10 +423,10 @@ void print_rheader(struct frame *fr)
 
 
     /* version, layer, freq, mode, channels, bitrate, BPF */
     /* version, layer, freq, mode, channels, bitrate, BPF */
     fprintf(stderr,"@I %s %s %ld %s %d %d %d\n",
     fprintf(stderr,"@I %s %s %ld %s %d %d %d\n",
-            mpeg_type[fr->lsf],layers[fr->lay],freqs[fr->sampling_frequency],
-            modes[fr->mode],fr->stereo,
-            tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
-            fr->framesize+4);
+        mpeg_type[fr->lsf],layers[fr->lay],freqs[fr->sampling_frequency],
+        modes[fr->mode],fr->stereo,
+        tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
+        fr->framesize+4);
 }
 }
 #endif
 #endif
 
 
@@ -451,40 +435,40 @@ void print_header(struct frame *fr)
     static char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" };
     static char *modes[4] = { "Stereo", "Joint-Stereo", "Dual-Channel", "Single-Channel" };
     static char *layers[4] = { "Unknown" , "I", "II", "III" };
     static char *layers[4] = { "Unknown" , "I", "II", "III" };
 
 
-    fprintf(stderr,"MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n",
-            fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
-            layers[fr->lay],freqs[fr->sampling_frequency],
-            modes[fr->mode],fr->mode_ext,fr->framesize+4);
+    fprintf(stderr,"MPEG %s, Layer: %s, Freq: %ld, mode: %s, modext: %d, BPF : %d\n", 
+        fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
+        layers[fr->lay],freqs[fr->sampling_frequency],
+        modes[fr->mode],fr->mode_ext,fr->framesize+4);
     fprintf(stderr,"Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n",
     fprintf(stderr,"Channels: %d, copyright: %s, original: %s, CRC: %s, emphasis: %d.\n",
-            fr->stereo,fr->copyright?"Yes":"No",
-            fr->original?"Yes":"No",fr->error_protection?"Yes":"No",
-            fr->emphasis);
+        fr->stereo,fr->copyright?"Yes":"No",
+        fr->original?"Yes":"No",fr->error_protection?"Yes":"No",
+        fr->emphasis);
     fprintf(stderr,"Bitrate: %d Kbits/s, Extension value: %d\n",
     fprintf(stderr,"Bitrate: %d Kbits/s, Extension value: %d\n",
-            tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension);
+        tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],fr->extension);
 }
 }
 
 
 void print_header_compact(struct frame *fr)
 void print_header_compact(struct frame *fr)
 {
 {
     static char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" };
     static char *modes[4] = { "stereo", "joint-stereo", "dual-channel", "mono" };
     static char *layers[4] = { "Unknown" , "I", "II", "III" };
     static char *layers[4] = { "Unknown" , "I", "II", "III" };
-
+ 
     fprintf(stderr,"MPEG %s layer %s, %d kbit/s, %ld Hz %s\n",
     fprintf(stderr,"MPEG %s layer %s, %d kbit/s, %ld Hz %s\n",
-            fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
-            layers[fr->lay],
-            tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
-            freqs[fr->sampling_frequency], modes[fr->mode]);
+        fr->mpeg25 ? "2.5" : (fr->lsf ? "2.0" : "1.0"),
+        layers[fr->lay],
+        tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index],
+        freqs[fr->sampling_frequency], modes[fr->mode]);
 }
 }
 
 
 void print_id3_tag(unsigned char *buf)
 void print_id3_tag(unsigned char *buf)
 {
 {
     struct id3tag {
     struct id3tag {
-        char tag[3];
-        char title[30];
-        char artist[30];
-        char album[30];
-        char year[4];
-        char comment[30];
-        unsigned char genre;
+    char tag[3];
+    char title[30];
+    char artist[30];
+    char album[30];
+    char year[4];
+    char comment[30];
+    unsigned char genre;
     };
     };
     struct id3tag *tag = (struct id3tag *) buf;
     struct id3tag *tag = (struct id3tag *) buf;
     char title[31]={0,};
     char title[31]={0,};
@@ -495,7 +479,7 @@ void print_id3_tag(unsigned char *buf)
     char genre[31]={0,};
     char genre[31]={0,};
 
 
     if(param.quiet)
     if(param.quiet)
-        return;
+    return;
 
 
     strncpy(title,tag->title,30);
     strncpy(title,tag->title,30);
     strncpy(artist,tag->artist,30);
     strncpy(artist,tag->artist,30);
@@ -504,9 +488,9 @@ void print_id3_tag(unsigned char *buf)
     strncpy(comment,tag->comment,30);
     strncpy(comment,tag->comment,30);
 
 
     if ( tag->genre < sizeof(genre_table)/sizeof(*genre_table) ) {
     if ( tag->genre < sizeof(genre_table)/sizeof(*genre_table) ) {
-        strncpy(genre, genre_table[tag->genre], 30);
+    strncpy(genre, genre_table[tag->genre], 30);
     } else {
     } else {
-        strncpy(genre,"Unknown",30);
+    strncpy(genre,"Unknown",30);
     }
     }
 
 
     fprintf(stderr,"Title  : %-30s  Artist: %s\n",title,artist);
     fprintf(stderr,"Title  : %-30s  Artist: %s\n",title,artist);
@@ -526,7 +510,7 @@ char *strndup (const char *src, int num)
     char *dst;
     char *dst;
 
 
     if (!(dst = (char *) malloc(num+1)))
     if (!(dst = (char *) malloc(num+1)))
-        return (NULL);
+    return (NULL);
     dst[num] = '\0';
     dst[num] = '\0';
     return (strncpy(dst, src, num));
     return (strncpy(dst, src, num));
 }
 }
@@ -549,45 +533,45 @@ int split_dir_file (const char *path, char **dname, char **fname)
     char *slashpos;
     char *slashpos;
 
 
     if ((slashpos = strrchr(path, '/'))) {
     if ((slashpos = strrchr(path, '/'))) {
-        *fname = slashpos + 1;
-        *dname = strdup(path); /* , 1 + slashpos - path); */
-        if(!(*dname)) {
-            perror("memory");
-            exit(1);
-        }
-        (*dname)[1 + slashpos - path] = 0;
-        if (lastdir && !strcmp(lastdir, *dname)) {
-            /***   same as previous directory   ***/
-            free (*dname);
-            *dname = lastdir;
-            return 0;
-        }
-        else {
-            /***   different directory   ***/
-            if (lastdir)
-                free (lastdir);
-            lastdir = *dname;
-            return 1;
-        }
+    *fname = slashpos + 1;
+    *dname = strdup(path); /* , 1 + slashpos - path); */
+    if(!(*dname)) {
+        perror("memory");
+        exit(1);
     }
     }
-    else {
-        /***   no directory specified   ***/
-        if (lastdir) {
-            free (lastdir);
-            lastdir = NULL;
-        };
-        *dname = NULL;
-        *fname = (char *)path;
+    (*dname)[1 + slashpos - path] = 0;
+    if (lastdir && !strcmp(lastdir, *dname)) {
+        /***   same as previous directory   ***/
+        free (*dname);
+        *dname = lastdir;
         return 0;
         return 0;
     }
     }
+    else {
+        /***   different directory   ***/
+        if (lastdir)
+        free (lastdir);
+        lastdir = *dname;
+        return 1;
+    }
+    }
+    else {
+    /***   no directory specified   ***/
+    if (lastdir) {
+        free (lastdir);
+        lastdir = NULL;
+    };
+    *dname = NULL;
+    *fname = (char *)path;
+    return 0;
+    }
 }
 }
 
 
 void set_pointer(long backstep)
 void set_pointer(long backstep)
 {
 {
     bsi.wordpointer = bsbuf + ssize - backstep;
     bsi.wordpointer = bsbuf + ssize - backstep;
     if (backstep)
     if (backstep)
-        memcpy(bsi.wordpointer,bsbufold+fsizeold-backstep,backstep);
-    bsi.bitindex = 0;
+    memcpy(bsi.wordpointer,bsbufold+fsizeold-backstep,backstep);
+    bsi.bitindex = 0; 
 }
 }
 
 
 /********************************/
 /********************************/
@@ -598,18 +582,18 @@ double compute_bpf(struct frame *fr)
 
 
     switch(fr->lay) {
     switch(fr->lay) {
     case 1:
     case 1:
-        bpf = tabsel_123[fr->lsf][0][fr->bitrate_index];
-        bpf *= 12000.0 * 4.0;
-        bpf /= freqs[fr->sampling_frequency] <<(fr->lsf);
-        break;
+    bpf = tabsel_123[fr->lsf][0][fr->bitrate_index];
+    bpf *= 12000.0 * 4.0;
+    bpf /= freqs[fr->sampling_frequency] <<(fr->lsf);
+    break;
     case 2:
     case 2:
     case 3:
     case 3:
-        bpf = tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index];
+    bpf = tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index];
         bpf *= 144000;
         bpf *= 144000;
-        bpf /= freqs[fr->sampling_frequency] << (fr->lsf);
-        break;
+    bpf /= freqs[fr->sampling_frequency] << (fr->lsf);
+    break;
     default:
     default:
-        bpf = 1.0;
+    bpf = 1.0;
     }
     }
 
 
     return bpf;
     return bpf;
@@ -626,7 +610,7 @@ double compute_tpf(struct frame *fr)
 }
 }
 
 
 /*
 /*
- * Returns number of frames queued up in output buffer, i.e.
+ * Returns number of frames queued up in output buffer, i.e. 
  * offset between currently played and currently decoded frame.
  * offset between currently played and currently decoded frame.
  */
  */
 
 
@@ -642,15 +626,15 @@ long compute_buffer_offset(struct frame *fr)
 
 
     if(!param.usebuffer || !(bufsize=xfermem_get_usedspace(buffermem))
     if(!param.usebuffer || !(bufsize=xfermem_get_usedspace(buffermem))
        || !buffermem->buf[0] || !buffermem->buf[1])
        || !buffermem->buf[0] || !buffermem->buf[1])
-        return 0;
+    return 0;
 
 
-    bufsize = (long)((double) bufsize / buffermem->buf[0] /
-                     buffermem->buf[1] / compute_tpf(fr));
+    bufsize = (long)((double) bufsize / buffermem->buf[0] / 
+             buffermem->buf[1] / compute_tpf(fr));
 
 
     if((buffermem->buf[2] & AUDIO_FORMAT_MASK) == AUDIO_FORMAT_16)
     if((buffermem->buf[2] & AUDIO_FORMAT_MASK) == AUDIO_FORMAT_16)
-        return bufsize/2;
+    return bufsize/2;
     else
     else
-        return bufsize;
+    return bufsize;
 }
 }
 
 
 void print_stat(struct frame *fr,int no,long buffsize,struct audio_info_struct *ai)
 void print_stat(struct frame *fr,int no,long buffsize,struct audio_info_struct *ai)
@@ -660,24 +644,24 @@ void print_stat(struct frame *fr,int no,long buffsize,struct audio_info_struct *
     int sno,rno;
     int sno,rno;
     char outbuf[256];
     char outbuf[256];
 
 
-    if(!rd || !fr)
-        return;
+    if(!rd || !fr) 
+    return;
 
 
     outbuf[0] = 0;
     outbuf[0] = 0;
 
 
 #ifndef GENERIC
 #ifndef GENERIC
     {
     {
-        struct timeval t;
-        fd_set serr;
-        int n,errfd = fileno(stderr);
+    struct timeval t;
+    fd_set serr;
+    int n,errfd = fileno(stderr);
 
 
-        t.tv_sec=t.tv_usec=0;
+    t.tv_sec=t.tv_usec=0;
 
 
-        FD_ZERO(&serr);
-        FD_SET(errfd,&serr);
-        n = select(errfd+1,NULL,&serr,NULL,&t);
-        if(n <= 0)
-            return;
+    FD_ZERO(&serr);
+    FD_SET(errfd,&serr);
+    n = select(errfd+1,NULL,&serr,NULL,&t);
+    if(n <= 0)
+        return;
     }
     }
 #endif
 #endif
 
 
@@ -685,17 +669,17 @@ void print_stat(struct frame *fr,int no,long buffsize,struct audio_info_struct *
     tpf = compute_tpf(fr);
     tpf = compute_tpf(fr);
 
 
     if(buffsize > 0 && ai && ai->rate > 0 && ai->channels > 0) {
     if(buffsize > 0 && ai && ai->rate > 0 && ai->channels > 0) {
-        dt = (double) buffsize / ai->rate / ai->channels;
-        if( (ai->format & AUDIO_FORMAT_MASK) == AUDIO_FORMAT_16)
-            dt *= 0.5;
+    dt = (double) buffsize / ai->rate / ai->channels;
+    if( (ai->format & AUDIO_FORMAT_MASK) == AUDIO_FORMAT_16)
+        dt *= 0.5;
     }
     }
 
 
     rno = 0;
     rno = 0;
     sno = no;
     sno = no;
     if(rd->filelen >= 0) {
     if(rd->filelen >= 0) {
-        long t = rd->tell(rd);
-        rno = (int)((double)(rd->filelen-t)/bpf);
-        sno = (int)((double)t/bpf);
+    long t = rd->tell(rd);
+    rno = (int)((double)(rd->filelen-t)/bpf);
+    sno = (int)((double)t/bpf);
     }
     }
 
 
     sprintf(outbuf+strlen(outbuf),"\rFrame# %5d [%5d], ",sno,rno);
     sprintf(outbuf+strlen(outbuf),"\rFrame# %5d [%5d], ",sno,rno);
@@ -708,15 +692,15 @@ void print_stat(struct frame *fr,int no,long buffsize,struct audio_info_struct *
     tim2 = tim2 < 0 ? 0.0 : tim2;
     tim2 = tim2 < 0 ? 0.0 : tim2;
 
 
     sprintf(outbuf+strlen(outbuf),"Time: %02u:%02u.%02u [%02u:%02u.%02u], ",
     sprintf(outbuf+strlen(outbuf),"Time: %02u:%02u.%02u [%02u:%02u.%02u], ",
-            (unsigned int)tim1/60,
-            (unsigned int)tim1%60,
-            (unsigned int)(tim1*100)%100,
-            (unsigned int)tim2/60,
-            (unsigned int)tim2%60,
-            (unsigned int)(tim2*100)%100);
+        (unsigned int)tim1/60,
+        (unsigned int)tim1%60,
+        (unsigned int)(tim1*100)%100,
+        (unsigned int)tim2/60,
+        (unsigned int)tim2%60,
+        (unsigned int)(tim2*100)%100);
 
 
     if(param.usebuffer)
     if(param.usebuffer)
-        sprintf(outbuf+strlen(outbuf),"[%8ld] ",(long)buffsize);
+    sprintf(outbuf+strlen(outbuf),"[%8ld] ",(long)buffsize);
     write(fileno(stderr),outbuf,strlen(outbuf));
     write(fileno(stderr),outbuf,strlen(outbuf));
 #if 0
 #if 0
     fflush(out); /* hmm not really nec. */
     fflush(out); /* hmm not really nec. */
@@ -728,12 +712,12 @@ int get_songlen(struct frame *fr,int no)
     double tpf;
     double tpf;
 
 
     if(!fr)
     if(!fr)
-        return 0;
+    return 0;
 
 
     if(no < 0) {
     if(no < 0) {
-        if(!rd || rd->filelen < 0)
-            return 0;
-        no = (double) rd->filelen / compute_bpf(fr);
+    if(!rd || rd->filelen < 0)
+        return 0;
+    no = (double) rd->filelen / compute_bpf(fr);
     }
     }
 
 
     tpf = compute_tpf(fr);
     tpf = compute_tpf(fr);

+ 3 - 17
panda/src/mpg123/common.h

@@ -1,20 +1,6 @@
-/* Filename: common.h
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/*
+ * common.h
+ */
 
 
 extern void print_id3_tag(unsigned char *buf);
 extern void print_id3_tag(unsigned char *buf);
 extern unsigned long firsthead;
 extern unsigned long firsthead;

+ 20 - 30
panda/src/mpg123/dct64.c

@@ -1,24 +1,14 @@
-/* Filename: dct64.c
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
+
+/*
+ * Discrete Cosine Tansform (DCT) for subband synthesis
  *
  *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ * -funroll-loops (for gcc) will remove the loops for better performance
+ * using loops in the source-code enhances readabillity
+ */
 
 
 /*
 /*
  * TODO: write an optimized version for the down-sampling modes
  * TODO: write an optimized version for the down-sampling modes
- *       (in these modes the bands 16-31 (2:1) or 8-31 (4:1) are zero
+ *       (in these modes the bands 16-31 (2:1) or 8-31 (4:1) are zero 
  */
  */
 
 
 #include "mpg123.h"
 #include "mpg123.h"
@@ -37,7 +27,7 @@ void dct64(real *out0,real *out1,real *samples)
   b2 = b1 + 32;
   b2 = b1 + 32;
 
 
   for(i=15;i>=0;i--)
   for(i=15;i>=0;i--)
-    *bs++ = (*b1++ + *--b2);
+    *bs++ = (*b1++ + *--b2); 
   for(i=15;i>=0;i--)
   for(i=15;i>=0;i--)
     *bs++ = (*--b2 - *b1++) * *--costab;
     *bs++ = (*--b2 - *b1++) * *--costab;
 
 
@@ -47,15 +37,15 @@ void dct64(real *out0,real *out1,real *samples)
 
 
   {
   {
     for(i=7;i>=0;i--)
     for(i=7;i>=0;i--)
-      *bs++ = (*b1++ + *--b2);
+      *bs++ = (*b1++ + *--b2); 
     for(i=7;i>=0;i--)
     for(i=7;i>=0;i--)
-      *bs++ = (*--b2 - *b1++) * *--costab;
+      *bs++ = (*--b2 - *b1++) * *--costab; 
     b2 += 32;
     b2 += 32;
     costab += 8;
     costab += 8;
     for(i=7;i>=0;i--)
     for(i=7;i>=0;i--)
-      *bs++ = (*b1++ + *--b2);
+      *bs++ = (*b1++ + *--b2); 
     for(i=7;i>=0;i--)
     for(i=7;i>=0;i--)
-      *bs++ = (*b1++ - *--b2) * *--costab;
+      *bs++ = (*b1++ - *--b2) * *--costab; 
     b2 += 32;
     b2 += 32;
   }
   }
 
 
@@ -66,14 +56,14 @@ void dct64(real *out0,real *out1,real *samples)
   for(j=2;j;j--)
   for(j=2;j;j--)
   {
   {
     for(i=3;i>=0;i--)
     for(i=3;i>=0;i--)
-      *bs++ = (*b1++ + *--b2);
+      *bs++ = (*b1++ + *--b2); 
     for(i=3;i>=0;i--)
     for(i=3;i>=0;i--)
-      *bs++ = (*--b2 - *b1++) * costab[i];
+      *bs++ = (*--b2 - *b1++) * costab[i]; 
     b2 += 16;
     b2 += 16;
     for(i=3;i>=0;i--)
     for(i=3;i>=0;i--)
-      *bs++ = (*b1++ + *--b2);
+      *bs++ = (*b1++ + *--b2); 
     for(i=3;i>=0;i--)
     for(i=3;i>=0;i--)
-      *bs++ = (*b1++ - *--b2) * costab[i];
+      *bs++ = (*b1++ - *--b2) * costab[i]; 
     b2 += 16;
     b2 += 16;
   }
   }
 
 
@@ -83,14 +73,14 @@ void dct64(real *out0,real *out1,real *samples)
 
 
   for(j=4;j;j--)
   for(j=4;j;j--)
   {
   {
+    *bs++ = (*b1++ + *--b2); 
     *bs++ = (*b1++ + *--b2);
     *bs++ = (*b1++ + *--b2);
-    *bs++ = (*b1++ + *--b2);
-    *bs++ = (*--b2 - *b1++) * costab[1];
+    *bs++ = (*--b2 - *b1++) * costab[1]; 
     *bs++ = (*--b2 - *b1++) * costab[0];
     *bs++ = (*--b2 - *b1++) * costab[0];
     b2 += 8;
     b2 += 8;
+    *bs++ = (*b1++ + *--b2); 
     *bs++ = (*b1++ + *--b2);
     *bs++ = (*b1++ + *--b2);
-    *bs++ = (*b1++ + *--b2);
-    *bs++ = (*b1++ - *--b2) * costab[1];
+    *bs++ = (*b1++ - *--b2) * costab[1]; 
     *bs++ = (*b1++ - *--b2) * costab[0];
     *bs++ = (*b1++ - *--b2) * costab[0];
     b2 += 8;
     b2 += 8;
   }
   }

+ 10 - 20
panda/src/mpg123/decode.c

@@ -1,20 +1,10 @@
-/* Filename: decode.c
- * Created by:  
+/* 
+ * Mpeg Layer-1,2,3 audio decoder 
+ * ------------------------------
+ * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
+ * See also 'README'
  *
  *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ */
 
 
 #include <stdlib.h>
 #include <stdlib.h>
 #include <math.h>
 #include <math.h>
@@ -62,7 +52,7 @@ int synth_1to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt)
     tmp1 += 2;
     tmp1 += 2;
   }
   }
   *pnt += 32;
   *pnt += 32;
-
+  
   return ret;
   return ret;
 }
 }
 
 
@@ -131,11 +121,11 @@ int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
   short *samples = (short *) (out+*pnt);
   short *samples = (short *) (out+*pnt);
 
 
   real *b0,(*buf)[0x110];
   real *b0,(*buf)[0x110];
-  int clip = 0;
+  int clip = 0; 
   int bo1;
   int bo1;
 
 
   if(param.enable_equalizer)
   if(param.enable_equalizer)
-        do_equalizer(bandPtr,channel);
+    do_equalizer(bandPtr,channel);
 
 
   if(!channel) {
   if(!channel) {
     bo--;
     bo--;
@@ -162,7 +152,7 @@ int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
   {
   {
     register int j;
     register int j;
     real *window = decwin + 16 - bo1;
     real *window = decwin + 16 - bo1;
-
+ 
     for (j=16;j;j--,window+=0x10,samples+=step)
     for (j=16;j;j--,window+=0x10,samples+=step)
     {
     {
       real sum;
       real sum;

+ 9 - 18
panda/src/mpg123/decode_2to1.c

@@ -1,20 +1,11 @@
-/* Filename: decode_2to1.c
- * Created by:  
+/*
+ * Mpeg Layer-1,2,3 audio decoder
+ * ------------------------------
+ * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
+ * version for slower machines .. decodes only every second sample
+ * sounds like 24000,22050 or 16000 kHz .. (depending on original sample freq.)
  *
  *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ */
 
 
 #include <stdlib.h>
 #include <stdlib.h>
 #include <math.h>
 #include <math.h>
@@ -118,7 +109,7 @@ int synth_2to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
     ((short *)samples)[1] = ((short *)samples)[0];
     ((short *)samples)[1] = ((short *)samples)[0];
     samples+=4;
     samples+=4;
   }
   }
-
+  
   return ret;
   return ret;
 }
 }
 
 
@@ -130,7 +121,7 @@ int synth_2to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
   short *samples = (short *) (out + *pnt);
   short *samples = (short *) (out + *pnt);
 
 
   real *b0,(*buf)[0x110];
   real *b0,(*buf)[0x110];
-  int clip = 0;
+  int clip = 0; 
   int bo1;
   int bo1;
 
 
   if(param.enable_equalizer)
   if(param.enable_equalizer)

+ 11 - 19
panda/src/mpg123/decode_4to1.c

@@ -1,20 +1,12 @@
-/* Filename: decode_4to1.c
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/*
+ * Mpeg Layer-1,2,3 audio decoder
+ * ------------------------------
+ * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
+ * See also 'README'
+ * version for slower machines .. decodes only every fourth sample
+ * dunno why it sounds THIS annoying (maybe we should adapt the window?)
+ * absolutely not optimized for this operation
+ */
 
 
 #include <stdlib.h>
 #include <stdlib.h>
 #include <math.h>
 #include <math.h>
@@ -130,7 +122,7 @@ int synth_4to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
   short *samples = (short *) (out + *pnt);
   short *samples = (short *) (out + *pnt);
 
 
   real *b0,(*buf)[0x110];
   real *b0,(*buf)[0x110];
-  int clip = 0;
+  int clip = 0; 
   int bo1;
   int bo1;
 
 
   if(param.enable_equalizer)
   if(param.enable_equalizer)
@@ -237,7 +229,7 @@ int synth_4to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
 #endif
 #endif
     }
     }
   }
   }
-
+  
   *pnt += 32;
   *pnt += 32;
 
 
   return clip;
   return clip;

+ 25 - 34
panda/src/mpg123/decode_ntom.c

@@ -1,20 +1,11 @@
-/* Filename: decode_ntom.c
- * Created by:  
+/* 
+ * Mpeg Layer-1,2,3 audio decoder 
+ * ------------------------------
+ * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
+ * See also 'README'
  *
  *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ * N->M down/up sampling. Not optimized for speed.
+ */
 
 
 #include <stdlib.h>
 #include <stdlib.h>
 #include <math.h>
 #include <math.h>
@@ -34,23 +25,23 @@ static unsigned long ntom_step = NTOM_MUL;
 
 
 void synth_ntom_set_step(long m,long n)
 void synth_ntom_set_step(long m,long n)
 {
 {
-        if(param.verbose > 1)
-                fprintf(stderr,"Init rate converter: %ld->%ld\n",m,n);
+    if(param.verbose > 1)
+        fprintf(stderr,"Init rate converter: %ld->%ld\n",m,n);
 
 
-        if(n >= 96000 || m >= 96000 || m == 0 || n == 0) {
-                fprintf(stderr,"NtoM converter: illegal rates\n");
-                exit(1);
-        }
+    if(n >= 96000 || m >= 96000 || m == 0 || n == 0) {
+        fprintf(stderr,"NtoM converter: illegal rates\n");
+        exit(1);
+    }
 
 
-        n *= NTOM_MUL;
-        ntom_step = n / m;
+    n *= NTOM_MUL;
+    ntom_step = n / m;
 
 
-        if(ntom_step > 8*NTOM_MUL) {
-                fprintf(stderr,"max. 1:8 conversion allowed!\n");
-                exit(1);
-        }
+    if(ntom_step > 8*NTOM_MUL) {
+        fprintf(stderr,"max. 1:8 conversion allowed!\n");
+        exit(1);
+    }
 
 
-        ntom_val[0] = ntom_val[1] = NTOM_MUL>>1;
+    ntom_val[0] = ntom_val[1] = NTOM_MUL>>1;
 }
 }
 
 
 int synth_ntom_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt)
 int synth_ntom_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt)
@@ -88,7 +79,7 @@ int synth_ntom_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt)
     tmp1 += 2;
     tmp1 += 2;
   }
   }
   *pnt += pnt1 >> 2;
   *pnt += pnt1 >> 2;
-
+  
   return ret;
   return ret;
 }
 }
 
 
@@ -140,7 +131,7 @@ int synth_ntom_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
 
 
   ret = synth_ntom(bandPtr,0,samples,pnt);
   ret = synth_ntom(bandPtr,0,samples,pnt);
   samples += pnt1;
   samples += pnt1;
-
+  
   for(i=0;i<((*pnt-pnt1)>>2);i++) {
   for(i=0;i<((*pnt-pnt1)>>2);i++) {
     ((short *)samples)[1] = ((short *)samples)[0];
     ((short *)samples)[1] = ((short *)samples)[0];
     samples+=4;
     samples+=4;
@@ -158,12 +149,12 @@ int synth_ntom(real *bandPtr,int channel,unsigned char *out,int *pnt)
   short *samples = (short *) (out + *pnt);
   short *samples = (short *) (out + *pnt);
 
 
   real *b0,(*buf)[0x110];
   real *b0,(*buf)[0x110];
-  int clip = 0;
+  int clip = 0; 
   int bo1;
   int bo1;
   int ntom;
   int ntom;
 
 
   if(param.enable_equalizer)
   if(param.enable_equalizer)
-        do_equalizer(bandPtr,channel);
+    do_equalizer(bandPtr,channel);
 
 
   if(!channel) {
   if(!channel) {
     bo--;
     bo--;
@@ -193,7 +184,7 @@ int synth_ntom(real *bandPtr,int channel,unsigned char *out,int *pnt)
   {
   {
     register int j;
     register int j;
     real *window = decwin + 16 - bo1;
     real *window = decwin + 16 - bo1;
-
+ 
     for (j=16;j;j--,window+=0x10)
     for (j=16;j;j--,window+=0x10)
     {
     {
       real sum;
       real sum;

+ 10 - 27
panda/src/mpg123/equalizer.c

@@ -1,20 +1,3 @@
-/* Filename: equalizer.c
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 
 #include "mpg123.h"
 #include "mpg123.h"
 
 
@@ -24,20 +7,20 @@ int equalizer_cnt;
 
 
 real equalizerband[2][SBLIMIT*SSLIMIT];
 real equalizerband[2][SBLIMIT*SSLIMIT];
 
 
-void do_equalizer(real *bandPtr,int channel)
+void do_equalizer(real *bandPtr,int channel) 
 {
 {
-        int i;
+    int i;
 
 
-        if(param.enable_equalizer) {
-                for(i=0;i<32;i++)
-                        bandPtr[i] *= equalizer[channel][i];
-        }
+    if(param.enable_equalizer) {
+        for(i=0;i<32;i++)
+            bandPtr[i] *= equalizer[channel][i];
+    }
 
 
-/*      if(param.equalizer & 0x2) {
+/*  if(param.equalizer & 0x2) {
 
 
-                for(i=0;i<32;i++)
-                        equalizer_sum[channel][i] += bandPtr[i];
-        }
+        for(i=0;i<32;i++)
+            equalizer_sum[channel][i] += bandPtr[i];
+    }
 */
 */
 }
 }
 
 

+ 257 - 275
panda/src/mpg123/genre.h

@@ -1,280 +1,262 @@
-/* Filename: genre.h
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
 char *genre_table[] =
 char *genre_table[] =
 {
 {
-        "Blues",
-        "Classic Rock",
-        "Country",
-        "Dance",
-        "Disco",
-        "Funk",
-        "Grunge",
-        "Hip-Hop",
-        "Jazz",
-        "Metal",
-        "New Age",
-        "Oldies",
-        "Other",
-        "Pop",
-        "R&B",
-        "Rap",
-        "Reggae",
-        "Rock",
-        "Techno",
-        "Industrial",
-        "Alternative",
-        "Ska",
-        "Death Metal",
-        "Pranks",
-        "Soundtrack",
-        "Euro-Techno",
-        "Ambient",
-        "Trip-Hop",
-        "Vocal",
-        "Jazz+Funk",
-        "Fusion",
-        "Trance",
-        "Classical",
-        "Instrumental",
-        "Acid",
-        "House",
-        "Game",
-        "Sound Clip",
-        "Gospel",
-        "Noise",
-        "AlternRock",
-        "Bass",
-        "Soul",
-        "Punk",
-        "Space",
-        "Meditative",
-        "Instrumental Pop",
-        "Instrumental Rock",
-        "Ethnic",
-        "Gothic",
-        "Darkwave",
-        "Techno-Industrial",
-        "Electronic",
-        "Pop-Folk",
-        "Eurodance",
-        "Dream",
-        "Southern Rock",
-        "Comedy",
-        "Cult",
-        "Gangsta",
-        "Top 40",
-        "Christian Rap",
-        "Pop/Funk",
-        "Jungle",
-        "Native American",
-        "Cabaret",
-        "New Wave",
-        "Psychadelic",
-        "Rave",
-        "Showtunes",
-        "Trailer",
-        "Lo-Fi",
-        "Tribal",
-        "Acid Punk",
-        "Acid Jazz",
-        "Polka",
-        "Retro",
-        "Musical",
-        "Rock & Roll",
-        "Hard Rock",
-        "Folk",
-        "Folk/Rock",
-        "National folk",
-        "Swing",
-        "Fast-fusion",
-        "Bebob",
-        "Latin",
-        "Revival",
-        "Celtic",
-        "Bluegrass",
-        "Avantgarde",
-        "Gothic Rock",
-        "Progressive Rock",
-        "Psychedelic Rock",
-        "Symphonic Rock",
-        "Slow Rock",
-        "Big Band",
-        "Chorus",
-        "Easy Listening",
-        "Acoustic",
-        "Humour",
-        "Speech",
-        "Chanson",
-        "Opera",
-        "Chamber Music",
-        "Sonata",
-        "Symphony",
-        "Booty Bass",
-        "Primus",
-        "Porn Groove",
-        "Satire",
-        "Slow Jam",
-        "Club",
-        "Tango",
-        "Samba",
-        "Folklore",
-        "Ballad",
-        "Powder Ballad",
-        "Rhythmic Soul",
-        "Freestyle",
-        "Duet",
-        "Punk Rock",
-        "Drum Solo",
-        "A Capella",
-        "Euro-House",
-        "Dance Hall",
-        "Goa",
-        "Drum & Bass",
-        "Club House",
-        "Hardcore",
-        "Terror",
-        "Indie",
-        "BritPop",
-        "NegerPunk",
-        "Polsk Punk",
-        "Beat",
-        "Christian Gangsta",
-        "Heavy Metal",
-        "Black Metal",
-        "Crossover",
-        "Contemporary C",
-        "Christian Rock",
-        "Merengue",
-        "Salsa",
-        "Thrash Metal",
-        "Anime",
-        "JPop",
-        "SynthPop"
-/*      ,
-        "Unknown",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        "",
-        ""
+    "Blues",
+    "Classic Rock",
+    "Country",
+    "Dance",
+    "Disco",
+    "Funk",
+    "Grunge",
+    "Hip-Hop",
+    "Jazz",
+    "Metal",
+    "New Age",
+    "Oldies",
+    "Other",
+    "Pop",
+    "R&B",
+    "Rap",
+    "Reggae",
+    "Rock",
+    "Techno",
+    "Industrial",
+    "Alternative",
+    "Ska",
+    "Death Metal",
+    "Pranks",
+    "Soundtrack",
+    "Euro-Techno",
+    "Ambient",
+    "Trip-Hop",
+    "Vocal",
+    "Jazz+Funk",
+    "Fusion",
+    "Trance",
+    "Classical",
+    "Instrumental",
+    "Acid",
+    "House",
+    "Game",
+    "Sound Clip",
+    "Gospel",
+    "Noise",
+    "AlternRock",
+    "Bass",
+    "Soul",
+    "Punk",
+    "Space",
+    "Meditative",
+    "Instrumental Pop",
+    "Instrumental Rock",
+    "Ethnic",
+    "Gothic",
+    "Darkwave",
+    "Techno-Industrial",
+    "Electronic",
+    "Pop-Folk",
+    "Eurodance",
+    "Dream",
+    "Southern Rock",
+    "Comedy",
+    "Cult",
+    "Gangsta",
+    "Top 40",
+    "Christian Rap",
+    "Pop/Funk",
+    "Jungle",
+    "Native American",
+    "Cabaret",
+    "New Wave",
+    "Psychadelic",
+    "Rave",
+    "Showtunes",
+    "Trailer",
+    "Lo-Fi",
+    "Tribal",
+    "Acid Punk",
+    "Acid Jazz",
+    "Polka",
+    "Retro",
+    "Musical",
+    "Rock & Roll",
+    "Hard Rock",
+    "Folk",
+    "Folk/Rock",
+    "National folk",
+    "Swing",
+    "Fast-fusion",
+    "Bebob",
+    "Latin",
+    "Revival",
+    "Celtic",
+    "Bluegrass",
+    "Avantgarde",
+    "Gothic Rock",
+    "Progressive Rock",
+    "Psychedelic Rock",
+    "Symphonic Rock",
+    "Slow Rock",
+    "Big Band",
+    "Chorus",
+    "Easy Listening",
+    "Acoustic",
+    "Humour",
+    "Speech",
+    "Chanson",
+    "Opera",
+    "Chamber Music",
+    "Sonata",
+    "Symphony",
+    "Booty Bass",
+    "Primus",
+    "Porn Groove",
+    "Satire",
+    "Slow Jam",
+    "Club",
+    "Tango",
+    "Samba",
+    "Folklore",
+    "Ballad",
+    "Powder Ballad",
+    "Rhythmic Soul",
+    "Freestyle",
+    "Duet",
+    "Punk Rock",
+    "Drum Solo",
+    "A Capella",
+    "Euro-House",
+    "Dance Hall",
+    "Goa",
+    "Drum & Bass",
+    "Club House",
+    "Hardcore",
+    "Terror",
+    "Indie",
+    "BritPop",
+    "NegerPunk",
+    "Polsk Punk",
+    "Beat",
+    "Christian Gangsta",
+    "Heavy Metal",
+    "Black Metal",
+    "Crossover",
+    "Contemporary C",
+    "Christian Rock",
+    "Merengue",
+    "Salsa",
+    "Thrash Metal",
+    "Anime",
+    "JPop",
+    "SynthPop"
+/*  ,
+    "Unknown",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    "",
+    ""
 */
 */
 };
 };
 
 

+ 6 - 24
panda/src/mpg123/getbits.c

@@ -1,32 +1,14 @@
-/* Filename: getbits.c
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
 #include "mpg123.h"
 #include "mpg123.h"
 #include "common.h"
 #include "common.h"
 
 
 #if 0
 #if 0
 static void check_buffer_range(int size)
 static void check_buffer_range(int size)
 {
 {
-        int pos = (bsi->wordpointer-bsbuf) + (size>>3);
+    int pos = (bsi->wordpointer-bsbuf) + (size>>3);
 
 
-        if( pos >= fsizeold) {
-                fprintf(stderr,"Pointer out of range (%d,%d)!\n",pos,fsizeold);
-        }
+    if( pos >= fsizeold) {
+        fprintf(stderr,"Pointer out of range (%d,%d)!\n",pos,fsizeold);
+    }
 }
 }
 #endif
 #endif
 
 
@@ -37,7 +19,7 @@ void backbits(struct bitstream_info *bsi,int number_of_bits)
   bsi->bitindex    &= 0x7;
   bsi->bitindex    &= 0x7;
 }
 }
 
 
-int getbitoffset(struct bitstream_info *bsi)
+int getbitoffset(struct bitstream_info *bsi) 
 {
 {
   return (-bsi->bitindex)&0x7;
   return (-bsi->bitindex)&0x7;
 }
 }
@@ -45,7 +27,7 @@ int getbitoffset(struct bitstream_info *bsi)
 int getbyte(struct bitstream_info *bsi)
 int getbyte(struct bitstream_info *bsi)
 {
 {
 #ifdef DEBUG_GETBITS
 #ifdef DEBUG_GETBITS
-  if(bsi->bitindex)
+  if(bsi->bitindex) 
     fprintf(stderr,"getbyte called unsynched!\n");
     fprintf(stderr,"getbyte called unsynched!\n");
 #endif
 #endif
   return *bsi->wordpointer++;
   return *bsi->wordpointer++;

+ 3 - 17
panda/src/mpg123/getbits.h

@@ -1,20 +1,6 @@
-/* Filename: getbits.h
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/* that's the same file as getits.c but with defines to
+  force inlining */
 
 
 static unsigned long rval;
 static unsigned long rval;
 static unsigned char rval_uc;
 static unsigned char rval_uc;

+ 260 - 271
panda/src/mpg123/httpget.c

@@ -1,20 +1,9 @@
-/* Filename: httpget.c
- * Created by:  
+/*
+ *   httpget.c
  *
  *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ *   Oliver Fromme  <[email protected]>
+ *   Wed Apr  9 20:57:47 MET DST 1997
+ */
 
 
 #undef ALSA
 #undef ALSA
 
 
@@ -42,51 +31,51 @@ extern int errno;
 
 
 void writestring (int fd, char *string)
 void writestring (int fd, char *string)
 {
 {
-        int result, bytes = strlen(string);
-
-        while (bytes) {
-                if ((result = write(fd, string, bytes)) < 0 && errno != EINTR) {
-                        perror ("write");
-                        exit (1);
-                }
-                else if (result == 0) {
-                        fprintf (stderr, "write: %s\n",
-                                "socket closed unexpectedly");
-                        exit (1);
-                }
-                string += result;
-                bytes -= result;
+    int result, bytes = strlen(string);
+
+    while (bytes) {
+        if ((result = write(fd, string, bytes)) < 0 && errno != EINTR) {
+            perror ("write");
+            exit (1);
+        }
+        else if (result == 0) {
+            fprintf (stderr, "write: %s\n",
+                "socket closed unexpectedly");
+            exit (1);
         }
         }
+        string += result;
+        bytes -= result;
+    }
 }
 }
 
 
 void readstring (char *string, int maxlen, FILE *f)
 void readstring (char *string, int maxlen, FILE *f)
 {
 {
 #if 0
 #if 0
-        char *result;
+    char *result;
 #endif
 #endif
-        int pos = 0;
-
-        while(1) {
-                if( read(fileno(f),string+pos,1) == 1) {
-                        pos++;
-                        if(string[pos-1] == '\n') {
-                                string[pos] = 0;
-                                break;
-                        }
-                }
-                else if(errno != EINTR) {
-                        fprintf (stderr, "Error reading from socket or unexpected EOF.\n");
-                        exit(1);
-                }
+    int pos = 0;
+
+    while(1) {
+        if( read(fileno(f),string+pos,1) == 1) {
+            pos++;
+            if(string[pos-1] == '\n') {
+                string[pos] = 0;
+                break;
+            }
         }
         }
-#if 0
-        do {
-                result = fgets(string, maxlen, f);
-        } while (!result  && errno == EINTR);
-        if (!result) {
-                fprintf (stderr, "Error reading from socket or unexpected EOF.\n");
-                exit (1);
+        else if(errno != EINTR) {
+            fprintf (stderr, "Error reading from socket or unexpected EOF.\n");
+            exit(1);
         }
         }
+    }
+#if 0
+    do {
+        result = fgets(string, maxlen, f);
+    } while (!result  && errno == EINTR);
+    if (!result) {
+        fprintf (stderr, "Error reading from socket or unexpected EOF.\n");
+        exit (1);
+    }
 #endif
 #endif
 
 
 }
 }
@@ -149,73 +138,73 @@ static char *defaultportstr = "80";
 
 
 char *url2hostport (char *url, char **hname, unsigned long *hip, unsigned char **port)
 char *url2hostport (char *url, char **hname, unsigned long *hip, unsigned char **port)
 {
 {
-        char *h, *p;
-        char *hostptr;
-        char *r_hostptr;
-        char *pathptr;
-        char *portptr;
-        char *p0;
-        size_t stringlength;
-
-        p = url;
-        if (strncmp(p, "http://", 7) == 0)
-                p += 7;
-        hostptr = p;
-        while (*p && *p != '/')
-                p++;
-        pathptr = p;
-
-        r_hostptr = --p;
-        while (*p && hostptr < p && *p != ':' && *p != ']')
-                p--;
-
-        if (!*p || p < hostptr || *p != ':') {
-                portptr = NULL;
-        }
-        else{
-                portptr = p + 1;
-                r_hostptr = p - 1;
-        }
-        if (*hostptr == '[' && *r_hostptr == ']') {
-                hostptr++;
-                r_hostptr--;
-        }
+    char *h, *p;
+    char *hostptr;
+    char *r_hostptr;
+    char *pathptr;
+    char *portptr;
+    char *p0;
+    size_t stringlength;
+
+    p = url;
+    if (strncmp(p, "http://", 7) == 0)
+        p += 7;
+    hostptr = p;
+    while (*p && *p != '/')
+        p++;
+    pathptr = p;
+
+    r_hostptr = --p;
+    while (*p && hostptr < p && *p != ':' && *p != ']')
+        p--;
+
+    if (!*p || p < hostptr || *p != ':') {
+        portptr = NULL;
+    }
+    else{
+        portptr = p + 1;
+        r_hostptr = p - 1;
+    }
+    if (*hostptr == '[' && *r_hostptr == ']') {
+        hostptr++;
+        r_hostptr--;
+    }
 
 
-        stringlength = r_hostptr - hostptr + 1;
-        h = malloc(stringlength + 1); /* removed the strndup for better portability */
-        if (h == NULL) {
-                *hname = NULL;
-                *port = NULL;
-                return NULL;
-        }
-        strncpy(h, hostptr, stringlength);
-        *(h+stringlength) = '\0';
-        *hname = h;
+    stringlength = r_hostptr - hostptr + 1;
+    h = malloc(stringlength + 1); /* removed the strndup for better portability */
+    if (h == NULL) {
+        *hname = NULL;
+        *port = NULL;
+        return NULL;
+    }
+    strncpy(h, hostptr, stringlength);
+    *(h+stringlength) = '\0';
+    *hname = h;
 
 
-        if (portptr) {
-                stringlength = (pathptr - portptr);
-                if(!stringlength) portptr = NULL;
-        }
-        if (portptr == NULL) {
-                portptr = defaultportstr;
-                stringlength = strlen(defaultportstr);
-        }
-        p0 = malloc(stringlength + 1);
-        if (p0 == NULL) {
-                free(h);
-                *hname = NULL;
-                *port = NULL;
-                return NULL;
-        }
-        strncpy(p0, portptr, stringlength);
-        *(p0 + stringlength) = '\0';
+    if (portptr) {
+        stringlength = (pathptr - portptr);
+        if(!stringlength) portptr = NULL;
+    }
+    if (portptr == NULL) {
+        portptr = defaultportstr;
+        stringlength = strlen(defaultportstr);
+    }
+    p0 = malloc(stringlength + 1);
+    if (p0 == NULL) {
+        free(h);
+        *hname = NULL;
+        *port = NULL;
+        return NULL;
+    }
+    strncpy(p0, portptr, stringlength);
+    *(p0 + stringlength) = '\0';
 
 
-        for (p = p0; *p && isdigit((unsigned char) *p); p++) ;
+    for (p = p0; *p && isdigit((unsigned char) *p); p++) ;
 
 
-        *p = '\0';
-        *port = (unsigned char *) p0;
+    *p = '\0';
+    *port = (unsigned char *) p0;
 
 
-        return pathptr;
+    return pathptr;
 }
 }
 
 
 char *proxyurl = NULL;
 char *proxyurl = NULL;
@@ -229,190 +218,190 @@ char httpauth1[256];
 
 
 int http_open (char *url)
 int http_open (char *url)
 {
 {
-        char *purl, *host, *request, *sptr;
-        int linelength;
-        unsigned long myip;
-        unsigned char *myport;
-        int sock;
-        int relocate, numrelocs = 0;
-        FILE *myfile;
+    char *purl, *host, *request, *sptr;
+    int linelength;
+    unsigned long myip;
+    unsigned char *myport;
+    int sock;
+    int relocate, numrelocs = 0;
+    FILE *myfile;
 #ifdef INET6
 #ifdef INET6
-        struct addrinfo hints, *res, *res0;
-        int error;
+    struct addrinfo hints, *res, *res0;
+    int error;
 #else
 #else
-        struct hostent *hp;
-        struct sockaddr_in sin;
+    struct hostent *hp;
+    struct sockaddr_in sin;
 #endif
 #endif
 
 
-        host = NULL;
-        proxyport = NULL;
-        myport = NULL;
-        if (!proxyip) {
-                if (!proxyurl)
-                        if (!(proxyurl = getenv("MP3_HTTP_PROXY")))
-                                if (!(proxyurl = getenv("http_proxy")))
-                                        proxyurl = getenv("HTTP_PROXY");
-                if (proxyurl && proxyurl[0] && strcmp(proxyurl, "none")) {
-                        if (!(url2hostport(proxyurl, &host, &proxyip, &proxyport))) {
-                                fprintf (stderr, "Unknown proxy host \"%s\".\n",
-                                        host ? host : "");
-                                exit (1);
-                        }
+    host = NULL;
+    proxyport = NULL;
+    myport = NULL;
+    if (!proxyip) {
+        if (!proxyurl)
+            if (!(proxyurl = getenv("MP3_HTTP_PROXY")))
+                if (!(proxyurl = getenv("http_proxy")))
+                    proxyurl = getenv("HTTP_PROXY");
+        if (proxyurl && proxyurl[0] && strcmp(proxyurl, "none")) {
+            if (!(url2hostport(proxyurl, &host, &proxyip, &proxyport))) {
+                fprintf (stderr, "Unknown proxy host \"%s\".\n",
+                    host ? host : "");
+                exit (1);
+            }
 #if 0
 #if 0
-                        if (host)
-                                free (host);
+            if (host)
+                free (host);
 #endif
 #endif
-                }
-                else
-                        proxyip = INADDR_NONE;
         }
         }
+        else
+            proxyip = INADDR_NONE;
+    }
 
 
-        if ((linelength = strlen(url)+200) < 1024)
-                linelength = 1024;
-        if (!(request = malloc(linelength)) || !(purl = malloc(1024))) {
-                fprintf (stderr, "malloc() failed, out of memory.\n");
-                exit (1);
-        }
-        strncpy (purl, url, 1023);
-        purl[1023] = '\0';
+    if ((linelength = strlen(url)+200) < 1024)
+        linelength = 1024;
+    if (!(request = malloc(linelength)) || !(purl = malloc(1024))) {
+        fprintf (stderr, "malloc() failed, out of memory.\n");
+        exit (1);
+    }
+    strncpy (purl, url, 1023);
+    purl[1023] = '\0';
 
 
         getauthfromURL(purl,httpauth1);
         getauthfromURL(purl,httpauth1);
 
 
-        do {
-                strcpy (request, "GET ");
-                if (proxyip != INADDR_NONE) {
-                        if (strncmp(url, "http://", 7))
-                                strcat (request, "http://");
-                        strcat (request, purl);
-                        myport = proxyport;
-                        myip = proxyip;
-                }
-                else {
-                        if (host) {
-                                free(host);
-                                host=NULL;
-                        }
-                        if (proxyport) {
-                                free(proxyport);
-                                proxyport=NULL;
-                        }
-                        if (!(sptr = url2hostport(purl, &host, &myip, &myport))) {
-                                fprintf (stderr, "Unknown host \"%s\".\n",
-                                        host ? host : "");
-                                exit (1);
-                        }
-                        strcat (request, sptr);
-                }
-                sprintf (request + strlen(request),
-                        " HTTP/1.0\r\nUser-Agent: %s/%s\r\n",
-                        prgName, prgVersion);
-                if (host) {
-                        sprintf(request + strlen(request),
-                                "Host: %s:%s\r\n", host, myport);
+    do {
+        strcpy (request, "GET ");
+        if (proxyip != INADDR_NONE) {
+            if (strncmp(url, "http://", 7))
+                strcat (request, "http://");
+            strcat (request, purl);
+            myport = proxyport;
+            myip = proxyip;
+        }
+        else {
+            if (host) {
+                free(host);
+                host=NULL;
+            }
+            if (proxyport) {
+                free(proxyport);
+                proxyport=NULL;
+            }
+            if (!(sptr = url2hostport(purl, &host, &myip, &myport))) {
+                fprintf (stderr, "Unknown host \"%s\".\n",
+                    host ? host : "");
+                exit (1);
+            }
+            strcat (request, sptr);
+        }
+        sprintf (request + strlen(request),
+            " HTTP/1.0\r\nUser-Agent: %s/%s\r\n",
+            prgName, prgVersion);
+        if (host) {
+            sprintf(request + strlen(request),
+                "Host: %s:%s\r\n", host, myport);
 #if 0
 #if 0
-                        free (host);
+            free (host);
 #endif
 #endif
-                }
-                strcat (request, ACCEPT_HEAD);
+        }
+        strcat (request, ACCEPT_HEAD);
 
 
 #ifdef INET6
 #ifdef INET6
-                memset(&hints, 0, sizeof(hints));
-                hints.ai_socktype = SOCK_STREAM;
-                error = getaddrinfo(host, (char *)myport, &hints, &res0);
-                if (error) {
-                        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error));
-                        exit(1);
-                }
+        memset(&hints, 0, sizeof(hints));
+        hints.ai_socktype = SOCK_STREAM;
+        error = getaddrinfo(host, (char *)myport, &hints, &res0);
+        if (error) {
+            fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(error));
+            exit(1);
+        }
 
 
+        sock = -1;
+        for (res = res0; res; res = res->ai_next) {
+            if ((sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
+                continue;
+            }
+            if (connect(sock, res->ai_addr, res->ai_addrlen)) {
+                close(sock);
                 sock = -1;
                 sock = -1;
-                for (res = res0; res; res = res->ai_next) {
-                        if ((sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) {
-                                continue;
-                        }
-                        if (connect(sock, res->ai_addr, res->ai_addrlen)) {
-                                close(sock);
-                                sock = -1;
-                                continue;
-                        }
-                        break;
-                }
-
-                freeaddrinfo(res0);
+                continue;
+            }
+            break;
+        }
+
+        freeaddrinfo(res0);
 #else
 #else
-                sock = -1;
-                hp = gethostbyname(host);
-                if (!hp)
-                        goto fail;
-                if (hp->h_length != sizeof(sin.sin_addr))
-                        goto fail;
-                sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-                if (sock < 0)
-                        goto fail;
-                memset(&sin, 0, sizeof(sin));
-                sin.sin_family = AF_INET;
-                /* sin.sin_len = sizeof(struct sockaddr_in); */
-                memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
-                if (connect(sock, (struct sockaddr *)&sin, sizeof(struct sockaddr_in) ) < 0) {
-                        close(sock);
-                        sock = -1;
-                }
+        sock = -1;
+        hp = gethostbyname(host);
+        if (!hp)
+            goto fail;
+        if (hp->h_length != sizeof(sin.sin_addr))
+            goto fail;
+        sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+        if (sock < 0)
+            goto fail;
+        memset(&sin, 0, sizeof(sin));
+        sin.sin_family = AF_INET;
+        /* sin.sin_len = sizeof(struct sockaddr_in); */
+        memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);
+        if (connect(sock, (struct sockaddr *)&sin, sizeof(struct sockaddr_in) ) < 0) {
+            close(sock);
+            sock = -1;
+        }
 fail:
 fail:
 #endif
 #endif
 
 
-                if (sock < 0) {
-                        perror("socket");
-                        exit(1);
-                }
+        if (sock < 0) {
+            perror("socket");
+            exit(1);
+        }
 
 
-                if (strlen(httpauth1) || httpauth) {
-                        char buf[1023];
-                        strcat (request,"Authorization: Basic ");
+        if (strlen(httpauth1) || httpauth) {
+            char buf[1023];
+            strcat (request,"Authorization: Basic ");
                         if(strlen(httpauth1))
                         if(strlen(httpauth1))
                           encode64(httpauth1,buf);
                           encode64(httpauth1,buf);
                         else
                         else
-                          encode64(httpauth,buf);
-                        strcat (request,buf);
-                        strcat (request,"\r\n");
-                }
-                strcat (request, "\r\n");
-
-                writestring (sock, request);
-                if (!(myfile = fdopen(sock, "rb"))) {
-                        perror ("fdopen");
-                        exit (1);
-                };
-                relocate = FALSE;
-                purl[0] = '\0';
-                readstring (request, linelength-1, myfile);
-                if ((sptr = strchr(request, ' '))) {
-                        switch (sptr[1]) {
-                                case '3':
-                                        relocate = TRUE;
-                                case '2':
-                                        break;
-                                default:
-                                        fprintf (stderr, "HTTP request failed: %s",
-                                                sptr+1); /* '\n' is included */
-                                        exit (1);
-                        }
-                }
-                do {
-                        readstring (request, linelength-1, myfile);
-                        if (!strncmp(request, "Location:", 9))
-                                strncpy (purl, request+10, 1023);
-                } while (request[0] != '\r' && request[0] != '\n');
-        } while (relocate && purl[0] && numrelocs++ < 5);
-        if (relocate) {
-                fprintf (stderr, "Too many HTTP relocations.\n");
-                exit (1);
+              encode64(httpauth,buf);
+            strcat (request,buf);
+            strcat (request,"\r\n");
+        }
+        strcat (request, "\r\n");
+
+        writestring (sock, request);
+        if (!(myfile = fdopen(sock, "rb"))) {
+            perror ("fdopen");
+            exit (1);
+        };
+        relocate = FALSE;
+        purl[0] = '\0';
+        readstring (request, linelength-1, myfile);
+        if ((sptr = strchr(request, ' '))) {
+            switch (sptr[1]) {
+                case '3':
+                    relocate = TRUE;
+                case '2':
+                    break;
+                default:
+                    fprintf (stderr, "HTTP request failed: %s",
+                        sptr+1); /* '\n' is included */
+                    exit (1);
+            }
         }
         }
-        free (purl);
-        free (request);
-        free(host);
-        free(proxyport);
-        free(myport);
+        do {
+            readstring (request, linelength-1, myfile);
+            if (!strncmp(request, "Location:", 9))
+                strncpy (purl, request+10, 1023);
+        } while (request[0] != '\r' && request[0] != '\n');
+    } while (relocate && purl[0] && numrelocs++ < 5);
+    if (relocate) {
+        fprintf (stderr, "Too many HTTP relocations.\n");
+        exit (1);
+    }
+    free (purl);
+    free (request);
+    free(host);
+    free(proxyport);
+    free(myport);
 
 
-        return sock;
+    return sock;
 }
 }
 
 
 #else
 #else

+ 12 - 22
panda/src/mpg123/huffman.h

@@ -1,29 +1,19 @@
-/* Filename: huffman.h
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/*
+ * huffman tables ... recalcualted to work with my optimzed
+ * decoder scheme (MH)
+ * 
+ * probably we could save a few bytes of memory, because the 
+ * smaller tables are often the part of a bigger table
+ */
 
 
-struct newhuff
+struct newhuff 
 {
 {
   unsigned int linbits;
   unsigned int linbits;
   short *table;
   short *table;
 };
 };
 
 
-static short tab0[] =
-{
+static short tab0[] = 
+{ 
    0
    0
 };
 };
 
 
@@ -296,7 +286,7 @@ static short tab_c1[] =
 
 
 
 
 
 
-static struct newhuff ht[] =
+static struct newhuff ht[] = 
 {
 {
  { /* 0 */ 0 , tab0  } ,
  { /* 0 */ 0 , tab0  } ,
  { /* 2 */ 0 , tab1  } ,
  { /* 2 */ 0 , tab1  } ,
@@ -333,7 +323,7 @@ static struct newhuff ht[] =
  { /* 16 */ 13, tab24 }
  { /* 16 */ 13, tab24 }
 };
 };
 
 
-static struct newhuff htc[] =
+static struct newhuff htc[] = 
 {
 {
  { /* 1 , 1 , */ 0 , tab_c0 } ,
  { /* 1 , 1 , */ 0 , tab_c0 } ,
  { /* 1 , 1 , */ 0 , tab_c1 }
  { /* 1 , 1 , */ 0 , tab_c1 }

+ 135 - 146
panda/src/mpg123/l2tables.h

@@ -1,159 +1,148 @@
-/* Filename: l2tables.h
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/*
+ * Layer 2 Alloc tables .. 
+ * most other tables are calculated on program start (which is (of course)
+ * not ISO-conform) .. 
+ * Layer-3 huffman table is in huffman.h
+ */
 
 
 struct al_table alloc_0[] = {
 struct al_table alloc_0[] = {
-        {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
-        {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
-        {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
-        {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
-        {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
-        {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {2,0},{5,3},{7,5},{16,-32767},
-        {2,0},{5,3},{7,5},{16,-32767},
-        {2,0},{5,3},{7,5},{16,-32767},
-        {2,0},{5,3},{7,5},{16,-32767} };
+    {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+    {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+    {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+    {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+    {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+    {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {2,0},{5,3},{7,5},{16,-32767},
+    {2,0},{5,3},{7,5},{16,-32767},
+    {2,0},{5,3},{7,5},{16,-32767},
+    {2,0},{5,3},{7,5},{16,-32767} };
 
 
 struct al_table alloc_1[] = {
 struct al_table alloc_1[] = {
-        {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
-        {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
-        {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
-        {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
-        {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
-        {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
-        {2,0},{5,3},{7,5},{16,-32767},
-        {2,0},{5,3},{7,5},{16,-32767},
-        {2,0},{5,3},{7,5},{16,-32767},
-        {2,0},{5,3},{7,5},{16,-32767},
-        {2,0},{5,3},{7,5},{16,-32767},
-        {2,0},{5,3},{7,5},{16,-32767},
-        {2,0},{5,3},{7,5},{16,-32767} };
+    {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+    {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+    {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+    {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+    {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511},
+    {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+    {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767},
+    {2,0},{5,3},{7,5},{16,-32767},
+    {2,0},{5,3},{7,5},{16,-32767},
+    {2,0},{5,3},{7,5},{16,-32767},
+    {2,0},{5,3},{7,5},{16,-32767},
+    {2,0},{5,3},{7,5},{16,-32767},
+    {2,0},{5,3},{7,5},{16,-32767},
+    {2,0},{5,3},{7,5},{16,-32767} };
 
 
 struct al_table alloc_2[] = {
 struct al_table alloc_2[] = {
-        {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
-        {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
-        {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
-        {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} };
+    {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
+    {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
+    {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
+    {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} };
 
 
 struct al_table alloc_3[] = {
 struct al_table alloc_3[] = {
-        {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
-        {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
-        {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
-        {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} };
+    {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
+    {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
+    {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},
+    {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} };
 
 
 struct al_table alloc_4[] = {
 struct al_table alloc_4[] = {
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-                {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-                {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-                {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
-        {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
-                {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
-        {2,0},{5,3},{7,5},{10,9},
-        {2,0},{5,3},{7,5},{10,9},
-        {2,0},{5,3},{7,5},{10,9},
-        {2,0},{5,3},{7,5},{10,9},
-        {2,0},{5,3},{7,5},{10,9},
-        {2,0},{5,3},{7,5},{10,9},
-        {2,0},{5,3},{7,5},{10,9},
-        {2,0},{5,3},{7,5},{10,9},
-        {2,0},{5,3},{7,5},{10,9},
-        {2,0},{5,3},{7,5},{10,9},
-        {2,0},{5,3},{7,5},{10,9},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
+    {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},
+        {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
+    {2,0},{5,3},{7,5},{10,9},
     {2,0},{5,3},{7,5},{10,9},
     {2,0},{5,3},{7,5},{10,9},
     {2,0},{5,3},{7,5},{10,9},
     {2,0},{5,3},{7,5},{10,9},
     {2,0},{5,3},{7,5},{10,9},
     {2,0},{5,3},{7,5},{10,9},

+ 10 - 18
panda/src/mpg123/layer1.c

@@ -1,20 +1,12 @@
-/* Filename: layer1.c
- * Created by:  
+/* 
+ * Mpeg Layer-1 audio decoder 
+ * --------------------------
+ * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
+ * near unoptimzed ...
  *
  *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * may have a few bugs after last optimization ... 
  *
  *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ */
 
 
 #include "mpg123.h"
 #include "mpg123.h"
 
 
@@ -28,7 +20,7 @@ void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],stru
   if(fr->stereo) {
   if(fr->stereo) {
     int i;
     int i;
     int jsbound = fr->jsbound;
     int jsbound = fr->jsbound;
-    for (i=0;i<jsbound;i++) {
+    for (i=0;i<jsbound;i++) { 
       *ba++ = getbits(4);
       *ba++ = getbits(4);
       *ba++ = getbits(4);
       *ba++ = getbits(4);
     }
     }
@@ -61,7 +53,7 @@ void I_step_one(unsigned int balloc[], unsigned int scale_index[2][SBLIMIT],stru
 }
 }
 
 
 void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
 void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
-        unsigned int scale_index[2][SBLIMIT],struct frame *fr)
+    unsigned int scale_index[2][SBLIMIT],struct frame *fr)
 {
 {
   int i,n;
   int i,n;
   int smpb[2*SBLIMIT]; /* values: 0-65535 */
   int smpb[2*SBLIMIT]; /* values: 0-65535 */
@@ -80,7 +72,7 @@ void I_step_two(real fraction[2][SBLIMIT],unsigned int balloc[2*SBLIMIT],
       if ((n = *ba++))
       if ((n = *ba++))
         *sample++ = getbits(n+1);
         *sample++ = getbits(n+1);
     }
     }
-    for (i=jsbound;i<SBLIMIT;i++)
+    for (i=jsbound;i<SBLIMIT;i++) 
       if ((n = *ba++))
       if ((n = *ba++))
         *sample++ = getbits(n+1);
         *sample++ = getbits(n+1);
 
 

+ 23 - 34
panda/src/mpg123/layer2.c

@@ -1,20 +1,9 @@
-/* Filename: layer2.c
- * Created by:  
+/* 
+ * Mpeg Layer-2 audio decoder 
+ * --------------------------
+ * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
  *
  *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ */
 
 
 #include "mpg123.h"
 #include "mpg123.h"
 #include "l2tables.h"
 #include "l2tables.h"
@@ -25,7 +14,7 @@ static int grp_3tab[32 * 3] = { 0, };   /* used: 27 */
 static int grp_5tab[128 * 3] = { 0, };  /* used: 125 */
 static int grp_5tab[128 * 3] = { 0, };  /* used: 125 */
 static int grp_9tab[1024 * 3] = { 0, }; /* used: 729 */
 static int grp_9tab[1024 * 3] = { 0, }; /* used: 729 */
 
 
-real muls[27][64];      /* also used by layer 1 */
+real muls[27][64];  /* also used by layer 1 */
 
 
 void init_layer2(void)
 void init_layer2(void)
 {
 {
@@ -64,9 +53,9 @@ void init_layer2(void)
     double m=mulmul[k];
     double m=mulmul[k];
     table = muls[k];
     table = muls[k];
 #ifdef USE_MMX
 #ifdef USE_MMX
-    if(!param.down_sample)
+    if(!param.down_sample) 
         for(j=3,i=0;i<63;i++,j--)
         for(j=3,i=0;i<63;i++,j--)
-          *table++ = 16384 * m * pow(2.0,(double) j / 3.0);
+      *table++ = 16384 * m * pow(2.0,(double) j / 3.0);
     else
     else
 #endif
 #endif
     for(j=3,i=0;i<63;i++,j--)
     for(j=3,i=0;i<63;i++,j--)
@@ -121,21 +110,21 @@ void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr)
 
 
     bita = bit_alloc;
     bita = bit_alloc;
     scfsi=scfsi_buf;
     scfsi=scfsi_buf;
-    for (i=sblimit2;i;i--)
+    for (i=sblimit2;i;i--) 
       if (*bita++)
       if (*bita++)
-        switch (*scfsi++)
+        switch (*scfsi++) 
         {
         {
-          case 0:
+          case 0: 
                 *scale++ = getbits_fast(6);
                 *scale++ = getbits_fast(6);
                 *scale++ = getbits_fast(6);
                 *scale++ = getbits_fast(6);
                 *scale++ = getbits_fast(6);
                 *scale++ = getbits_fast(6);
                 break;
                 break;
-          case 1 :
+          case 1 : 
                 *scale++ = sc = getbits_fast(6);
                 *scale++ = sc = getbits_fast(6);
                 *scale++ = sc;
                 *scale++ = sc;
                 *scale++ = getbits_fast(6);
                 *scale++ = getbits_fast(6);
                 break;
                 break;
-          case 2:
+          case 2: 
                 *scale++ = sc = getbits_fast(6);
                 *scale++ = sc = getbits_fast(6);
                 *scale++ = sc;
                 *scale++ = sc;
                 *scale++ = sc;
                 *scale++ = sc;
@@ -164,17 +153,17 @@ void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale
       step = alloc1->bits;
       step = alloc1->bits;
       for (j=0;j<stereo;j++)
       for (j=0;j<stereo;j++)
       {
       {
-        if ( (ba=*bita++) )
+        if ( (ba=*bita++) ) 
         {
         {
           k=(alloc2 = alloc1+ba)->bits;
           k=(alloc2 = alloc1+ba)->bits;
-          if( (d1=alloc2->d) < 0)
+          if( (d1=alloc2->d) < 0) 
           {
           {
             real cm=muls[k][scale[x1]];
             real cm=muls[k][scale[x1]];
             fraction[j][0][i] = ((real) ((int)getbits(k) + d1)) * cm;
             fraction[j][0][i] = ((real) ((int)getbits(k) + d1)) * cm;
             fraction[j][1][i] = ((real) ((int)getbits(k) + d1)) * cm;
             fraction[j][1][i] = ((real) ((int)getbits(k) + d1)) * cm;
             fraction[j][2][i] = ((real) ((int)getbits(k) + d1)) * cm;
             fraction[j][2][i] = ((real) ((int)getbits(k) + d1)) * cm;
-          }
-          else
+          }        
+          else 
           {
           {
             static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
             static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab };
             unsigned int idx,*tab,m=scale[x1];
             unsigned int idx,*tab,m=scale[x1];
@@ -182,7 +171,7 @@ void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale
             tab = (unsigned int *) (table[d1] + idx + idx + idx);
             tab = (unsigned int *) (table[d1] + idx + idx + idx);
             fraction[j][0][i] = muls[*tab++][m];
             fraction[j][0][i] = muls[*tab++][m];
             fraction[j][1][i] = muls[*tab++][m];
             fraction[j][1][i] = muls[*tab++][m];
-            fraction[j][2][i] = muls[*tab][m];
+            fraction[j][2][i] = muls[*tab][m];  
           }
           }
           scale+=3;
           scale+=3;
         }
         }
@@ -225,13 +214,13 @@ void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale
         fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] =
         fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] =
         fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0;
         fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0;
       }
       }
-/*
+/* 
    should we use individual scalefac for channel 2 or
    should we use individual scalefac for channel 2 or
    is the current way the right one , where we just copy channel 1 to
    is the current way the right one , where we just copy channel 1 to
-   channel 2 ??
+   channel 2 ?? 
    The current 'strange' thing is, that we throw away the scalefac
    The current 'strange' thing is, that we throw away the scalefac
    values for the second channel ...!!
    values for the second channel ...!!
--> changed .. now we use the scalefac values of channel one !!
+-> changed .. now we use the scalefac values of channel one !! 
 */
 */
     }
     }
 
 
@@ -289,10 +278,10 @@ int do_layer2(struct mpstr *mp,struct frame *fr,int outmode,struct audio_info_st
 
 
   II_step_one(bit_alloc, scale, fr);
   II_step_one(bit_alloc, scale, fr);
 
 
-  for (i=0;i<SCALE_BLOCK;i++)
+  for (i=0;i<SCALE_BLOCK;i++) 
   {
   {
     II_step_two(bit_alloc,fraction,scale,fr,i>>2);
     II_step_two(bit_alloc,fraction,scale,fr,i>>2);
-    for (j=0;j<3;j++)
+    for (j=0;j<3;j++) 
     {
     {
       if(single >= 0)
       if(single >= 0)
       {
       {

+ 74 - 81
panda/src/mpg123/layer3.c

@@ -1,20 +1,13 @@
-/* Filename: layer3.c
- * Created by:  
+/* 
+ * Mpeg Layer-3 audio decoder 
+ * --------------------------
+ * copyright (c) 1995-1999 by Michael Hipp.
+ * All rights reserved. See also 'README'
  *
  *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ * Optimize-TODO: put short bands into the band-field without the stride 
+ *                of 3 reals
+ * Length-optimze: unify long and short band code where it is possible
+ */ 
 
 
 #include <stdlib.h>
 #include <stdlib.h>
 #include "mpg123.h"
 #include "mpg123.h"
@@ -52,7 +45,7 @@ struct bandInfoStruct {
 int longLimit[9][23];
 int longLimit[9][23];
 int shortLimit[9][14];
 int shortLimit[9][14];
 
 
-struct bandInfoStruct bandInfo[9] = {
+struct bandInfoStruct bandInfo[9] = { 
 
 
 /* MPEG 1.0 */
 /* MPEG 1.0 */
  { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576},
  { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576},
@@ -116,8 +109,8 @@ static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */
 static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16];
 static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16];
 static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16];
 static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16];
 
 
-/*
- * init tables for layer-3
+/* 
+ * init tables for layer-3 
  */
  */
 void init_layer3(int down_sample_sblimit)
 void init_layer3(int down_sample_sblimit)
 {
 {
@@ -329,11 +322,11 @@ static int III_get_side_info(struct III_sideinfo *si,int stereo,
 
 
    static const int tabs[2][5] = { { 2,9,5,3,4 } , { 1,8,1,2,9 } };
    static const int tabs[2][5] = { { 2,9,5,3,4 } , { 1,8,1,2,9 } };
    const int *tab = tabs[lsf];
    const int *tab = tabs[lsf];
-
+   
    si->main_data_begin = getbits(tab[1]);
    si->main_data_begin = getbits(tab[1]);
    if (stereo == 1)
    if (stereo == 1)
      si->private_bits = getbits_fast(tab[2]);
      si->private_bits = getbits_fast(tab[2]);
-   else
+   else 
      si->private_bits = getbits_fast(tab[3]);
      si->private_bits = getbits_fast(tab[3]);
 
 
    if(!lsf) {
    if(!lsf) {
@@ -376,8 +369,8 @@ static int III_get_side_info(struct III_sideinfo *si,int stereo,
            fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n");
            fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n");
            return 0;
            return 0;
          }
          }
-
-         /* region_count/start parameters are implicit in this case. */
+      
+         /* region_count/start parameters are implicit in this case. */       
          if(!lsf || gr_info->block_type == 2)
          if(!lsf || gr_info->block_type == 2)
            gr_info->region1start = 36>>1;
            gr_info->region1start = 36>>1;
          else {
          else {
@@ -463,7 +456,7 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
           numbits += num0 * 6;
           numbits += num0 * 6;
         }
         }
         else {
         else {
-          scf += 6;
+          scf += 6; 
         }
         }
 
 
         if(!(scfsi & 0x4)) {
         if(!(scfsi & 0x4)) {
@@ -481,7 +474,7 @@ static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
           numbits += num1 * 5;
           numbits += num1 * 5;
         }
         }
         else {
         else {
-          scf += 5;
+          scf += 5; 
         }
         }
 
 
         if(!(scfsi & 0x1)) {
         if(!(scfsi & 0x1)) {
@@ -510,7 +503,7 @@ static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_ster
    { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} ,
    { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} ,
      {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } ,
      {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } ,
    { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} ,
    { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} ,
-     { 6,15,12,0 } , { 6,12, 9,6 } , {  6,18,9,0} } };
+     { 6,15,12,0 } , { 6,12, 9,6 } , {  6,18,9,0} } }; 
 
 
   if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */
   if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */
     slen = i_slen2[gr_info->scalefac_compress>>1];
     slen = i_slen2[gr_info->scalefac_compress>>1];
@@ -519,7 +512,7 @@ static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_ster
 
 
   gr_info->preflag = (slen>>15) & 0x1;
   gr_info->preflag = (slen>>15) & 0x1;
 
 
-  n = 0;
+  n = 0;  
   if( gr_info->block_type == 2 ) {
   if( gr_info->block_type == 2 ) {
     n++;
     n++;
     if(gr_info->mixed_block_flag)
     if(gr_info->mixed_block_flag)
@@ -541,7 +534,7 @@ static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_ster
         *scf++ = 0;
         *scf++ = 0;
     }
     }
   }
   }
-
+  
   n = (n << 1) + 1;
   n = (n << 1) + 1;
   for(i=0;i<n;i++)
   for(i=0;i<n;i++)
     *scf++ = 0;
     *scf++ = 0;
@@ -584,10 +577,10 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
     int region1  = gr_info->region1start;
     int region1  = gr_info->region1start;
     int region2  = gr_info->region2start;
     int region2  = gr_info->region2start;
 
 
-    l3 = ((576>>1)-bv)>>1;
+    l3 = ((576>>1)-bv)>>1;   
 /*
 /*
- * we may lose the 'odd' bit here !!
- * check this later again
+ * we may lose the 'odd' bit here !! 
+ * check this later again 
  */
  */
     if(bv <= region1) {
     if(bv <= region1) {
       l[0] = bv; l[1] = l[2] = 0;
       l[0] = bv; l[1] = l[2] = 0;
@@ -602,10 +595,10 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
       }
       }
     }
     }
   }
   }
-
+ 
   if(gr_info->block_type == 2) {
   if(gr_info->block_type == 2) {
     /*
     /*
-     * decoding with short or mixed mode BandIndex table
+     * decoding with short or mixed mode BandIndex table 
      */
      */
     int i,max[4];
     int i,max[4];
     int step=0,lwin=3,cb=0;
     int step=0,lwin=3,cb=0;
@@ -720,8 +713,8 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
         mask <<= 1;
         mask <<= 1;
       }
       }
       if(part2remain+num <= 0) {
       if(part2remain+num <= 0) {
-        num -= part2remain+num;
-        break;
+    num -= part2remain+num;
+    break;
       }
       }
 
 
       for(i=0;i<4;i++) {
       for(i=0;i<4;i++) {
@@ -747,7 +740,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
           if(part2remain+num <= 0) {
           if(part2remain+num <= 0) {
             break;
             break;
           }
           }
-          if(mask < 0)
+          if(mask < 0) 
             *xrpnt = -v;
             *xrpnt = -v;
           else
           else
             *xrpnt = v;
             *xrpnt = v;
@@ -833,7 +826,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
 
 
         if (x == 15 && h->linbits) {
         if (x == 15 && h->linbits) {
           max = cb;
           max = cb;
-          REFRESH_MASK;
+      REFRESH_MASK;
           x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
           x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
           num -= h->linbits+1;
           num -= h->linbits+1;
           mask <<= h->linbits;
           mask <<= h->linbits;
@@ -857,7 +850,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
 
 
         if (y == 15 && h->linbits) {
         if (y == 15 && h->linbits) {
           max = cb;
           max = cb;
-          REFRESH_MASK;
+      REFRESH_MASK;
           y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
           y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
           num -= h->linbits+1;
           num -= h->linbits+1;
           mask <<= h->linbits;
           mask <<= h->linbits;
@@ -896,7 +889,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
         mask <<= 1;
         mask <<= 1;
       }
       }
       if(part2remain+num <= 0) {
       if(part2remain+num <= 0) {
-        num -= part2remain+num;
+    num -= part2remain+num;
         break;
         break;
       }
       }
 
 
@@ -937,7 +930,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
   backbits(num);
   backbits(num);
   num = 0;
   num = 0;
 
 
-  while(xrpnt < &xr[SBLIMIT][0])
+  while(xrpnt < &xr[SBLIMIT][0]) 
     *xrpnt++ = 0.0;
     *xrpnt++ = 0.0;
 
 
   while( part2remain > 16 ) {
   while( part2remain > 16 ) {
@@ -955,7 +948,7 @@ static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
   return 0;
   return 0;
 }
 }
 
 
-/*
+/* 
  * III_stereo: calculate real channel values for Joint-I-Stereo-mode
  * III_stereo: calculate real channel values for Joint-I-Stereo-mode
  */
  */
 static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
 static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
@@ -967,10 +960,10 @@ static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
       const real *tab1,*tab2;
       const real *tab1,*tab2;
 
 
       int tab;
       int tab;
-      static const real *tabs[3][2][2] = {
+      static const real *tabs[3][2][2] = { 
          { { tan1_1,tan2_1 }     , { tan1_2,tan2_2 } },
          { { tan1_1,tan2_1 }     , { tan1_2,tan2_2 } },
          { { pow1_1[0],pow2_1[0] } , { pow1_2[0],pow2_2[0] } } ,
          { { pow1_1[0],pow2_1[0] } , { pow1_2[0],pow2_2[0] } } ,
-         { { pow1_1[1],pow2_1[1] } , { pow1_2[1],pow2_2[1] } }
+         { { pow1_1[1],pow2_1[1] } , { pow1_2[1],pow2_2[1] } } 
       };
       };
 
 
       tab = lsf + (gr_info->scalefac_compress & lsf);
       tab = lsf + (gr_info->scalefac_compress & lsf);
@@ -979,7 +972,7 @@ static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
 #if 0
 #if 0
       if(lsf) {
       if(lsf) {
         int p = gr_info->scalefac_compress & 0x1;
         int p = gr_info->scalefac_compress & 0x1;
-        if(ms_stereo) {
+    if(ms_stereo) {
           tab1 = pow1_2[p]; tab2 = pow2_2[p];
           tab1 = pow1_2[p]; tab2 = pow2_2[p];
         }
         }
         else {
         else {
@@ -1008,7 +1001,7 @@ static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
              do_l = 0;
              do_l = 0;
 
 
            for(;sfb<12;sfb++) {
            for(;sfb<12;sfb++) {
-             is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
+             is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ 
              if(is_p != 7) {
              if(is_p != 7) {
                real t1,t2;
                real t1,t2;
                sb  = bi->shortDiff[sfb];
                sb  = bi->shortDiff[sfb];
@@ -1023,7 +1016,7 @@ static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
            }
            }
 
 
 #if 1
 #if 1
-/* in the original: copy 10 to 11 , here: copy 11 to 12
+/* in the original: copy 10 to 11 , here: copy 11 to 12 
 maybe still wrong??? (copy 12 to 13?) */
 maybe still wrong??? (copy 12 to 13?) */
            is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
            is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
            sb   = bi->shortDiff[12];
            sb   = bi->shortDiff[12];
@@ -1036,7 +1029,7 @@ maybe still wrong??? (copy 12 to 13?) */
            if(is_p != 7) {
            if(is_p != 7) {
              real t1,t2;
              real t1,t2;
              t1 = tab1[is_p]; t2 = tab2[is_p];
              t1 = tab1[is_p]; t2 = tab2[is_p];
-             for ( ; sb > 0; sb--,idx+=3 ) {
+             for ( ; sb > 0; sb--,idx+=3 ) {  
                real v = xr[0][idx];
                real v = xr[0][idx];
                xr[0][idx] = v * t1;
                xr[0][idx] = v * t1;
                xr[1][idx] = v * t2;
                xr[1][idx] = v * t2;
@@ -1045,7 +1038,7 @@ maybe still wrong??? (copy 12 to 13?) */
          } /* end for(lwin; .. ; . ) */
          } /* end for(lwin; .. ; . ) */
 
 
 /* also check l-part, if ALL bands in the three windows are 'empty'
 /* also check l-part, if ALL bands in the three windows are 'empty'
- * and mode = mixed_mode
+ * and mode = mixed_mode 
  */
  */
          if (do_l) {
          if (do_l) {
            int sfb = gr_info->maxbandl;
            int sfb = gr_info->maxbandl;
@@ -1063,17 +1056,17 @@ maybe still wrong??? (copy 12 to 13?) */
                  xr[1][idx] = v * t2;
                  xr[1][idx] = v * t2;
                }
                }
              }
              }
-             else
+             else 
                idx += sb;
                idx += sb;
            }
            }
-         }
-      }
+         }     
+      } 
       else { /* ((gr_info->block_type != 2)) */
       else { /* ((gr_info->block_type != 2)) */
        int sfb = gr_info->maxbandl;
        int sfb = gr_info->maxbandl;
        int is_p,idx = bi->longIdx[sfb];
        int is_p,idx = bi->longIdx[sfb];
 
 
 /* hmm ... maybe the maxbandl stuff for i-stereo is buggy? */
 /* hmm ... maybe the maxbandl stuff for i-stereo is buggy? */
-       if(sfb <= 21) {
+       if(sfb <= 21) { 
         for ( ; sfb<21; sfb++) {
         for ( ; sfb<21; sfb++) {
           int sb = bi->longDiff[sfb];
           int sb = bi->longDiff[sfb];
           is_p = scalefac[sfb]; /* scale: 0-15 */
           is_p = scalefac[sfb]; /* scale: 0-15 */
@@ -1093,7 +1086,7 @@ maybe still wrong??? (copy 12 to 13?) */
         is_p = scalefac[20];
         is_p = scalefac[20];
         if(is_p != 7) {  /* copy l-band 20 to l-band 21 */
         if(is_p != 7) {  /* copy l-band 20 to l-band 21 */
           int sb;
           int sb;
-          real t1 = tab1[is_p],t2 = tab2[is_p];
+          real t1 = tab1[is_p],t2 = tab2[is_p]; 
 
 
           for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ ) {
           for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ ) {
             real v = xr[0][idx];
             real v = xr[0][idx];
@@ -1109,9 +1102,9 @@ static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info) {
    int sblim;
    int sblim;
 
 
    if(gr_info->block_type == 2) {
    if(gr_info->block_type == 2) {
-      if(!gr_info->mixed_block_flag)
+      if(!gr_info->mixed_block_flag) 
         return;
         return;
-      sblim = 1;
+      sblim = 1; 
    }
    }
    else {
    else {
      sblim = gr_info->maxb-1;
      sblim = gr_info->maxb-1;
@@ -1139,7 +1132,7 @@ static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info) {
   }
   }
 }
 }
 
 
-/*
+/* 
  This is an optimized DCT from Jeff Tsay's maplay 1.2+ package.
  This is an optimized DCT from Jeff Tsay's maplay 1.2+ package.
  Saved one multiplication by doing the 'twiddle factor' stuff
  Saved one multiplication by doing the 'twiddle factor' stuff
  together with the window mul. (MH)
  together with the window mul. (MH)
@@ -1204,7 +1197,7 @@ void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
 #if 1
 #if 1
     {
     {
      real t3;
      real t3;
-     {
+     { 
       real t0, t1, t2;
       real t0, t1, t2;
 
 
       t0 = COS6_2 * (in[8] + in[16] - in[4]);
       t0 = COS6_2 * (in[8] + in[16] - in[4]);
@@ -1381,23 +1374,23 @@ void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
     out2[8-(v)] = tmp * w[26-(v)];  } \
     out2[8-(v)] = tmp * w[26-(v)];  } \
     sum0 -= sum1; \
     sum0 -= sum1; \
     ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \
     ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \
-    ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)];
+    ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)]; 
 #define MACRO1(v) { \
 #define MACRO1(v) { \
-        real sum0,sum1; \
+    real sum0,sum1; \
     sum0 = tmp1a + tmp2a; \
     sum0 = tmp1a + tmp2a; \
-        sum1 = (tmp1b + tmp2b) * tfcos36[(v)]; \
-        MACRO0(v); }
+    sum1 = (tmp1b + tmp2b) * tfcos36[(v)]; \
+    MACRO0(v); }
 #define MACRO2(v) { \
 #define MACRO2(v) { \
     real sum0,sum1; \
     real sum0,sum1; \
     sum0 = tmp2a - tmp1a; \
     sum0 = tmp2a - tmp1a; \
     sum1 = (tmp2b - tmp1b) * tfcos36[(v)]; \
     sum1 = (tmp2b - tmp1b) * tfcos36[(v)]; \
-        MACRO0(v); }
+    MACRO0(v); }
 
 
     register const real *c = COS9;
     register const real *c = COS9;
     register real *out2 = o2;
     register real *out2 = o2;
-        register real *w = wintab;
-        register real *out1 = o1;
-        register real *ts = tsbuf;
+    register real *w = wintab;
+    register real *out1 = o1;
+    register real *ts = tsbuf;
 
 
     real ta33,ta66,tb33,tb66;
     real ta33,ta66,tb33,tb66;
 
 
@@ -1406,7 +1399,7 @@ void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
     tb33 = in[2*3+1] * c[3];
     tb33 = in[2*3+1] * c[3];
     tb66 = in[2*6+1] * c[6] + in[2*0+1];
     tb66 = in[2*6+1] * c[6] + in[2*0+1];
 
 
-    {
+    { 
       real tmp1a,tmp2a,tmp1b,tmp2b;
       real tmp1a,tmp2a,tmp1b,tmp2b;
       tmp1a = in[2*1+0] * c[1] + ta33 + in[2*5+0] * c[5] + in[2*7+0] * c[7];
       tmp1a = in[2*1+0] * c[1] + ta33 + in[2*5+0] * c[5] + in[2*7+0] * c[7];
       tmp1b = in[2*1+1] * c[1] + tb33 + in[2*5+1] * c[5] + in[2*7+1] * c[7];
       tmp1b = in[2*1+1] * c[1] + tb33 + in[2*5+1] * c[5] + in[2*7+1] * c[7];
@@ -1450,12 +1443,12 @@ void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
       MACRO2(5);
       MACRO2(5);
     }
     }
 
 
-        {
-                real sum0,sum1;
+    {
+        real sum0,sum1;
         sum0 =  in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0];
         sum0 =  in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0];
         sum1 = (in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ) * tfcos36[4];
         sum1 = (in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ) * tfcos36[4];
-                MACRO0(4);
-        }
+        MACRO0(4);
+    }
   }
   }
 #endif
 #endif
 
 
@@ -1503,7 +1496,7 @@ static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,registe
      register real *out1 = rawout1;
      register real *out1 = rawout1;
      ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2];
      ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2];
      ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5];
      ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5];
-
+ 
      DCT12_PART1
      DCT12_PART1
 
 
      {
      {
@@ -1537,7 +1530,7 @@ static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,registe
   {
   {
      real in0,in1,in2,in3,in4,in5;
      real in0,in1,in2,in3,in4,in5;
      register real *out2 = rawout2;
      register real *out2 = rawout2;
-
+ 
      DCT12_PART1
      DCT12_PART1
 
 
      {
      {
@@ -1566,7 +1559,7 @@ static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,registe
      ts[(17-2)*SBLIMIT] += in4 * wi[5-2];
      ts[(17-2)*SBLIMIT] += in4 * wi[5-2];
   }
   }
 
 
-  in++;
+  in++; 
 
 
   {
   {
      real in0,in1,in2,in3,in4,in5;
      real in0,in1,in2,in3,in4,in5;
@@ -1624,7 +1617,7 @@ static void III_hybrid(struct mpstr *mp,real fsIn[SBLIMIT][SSLIMIT],real tsOut[S
      rawout2=mp->hybrid_block[b][ch];
      rawout2=mp->hybrid_block[b][ch];
      mp->hybrid_blc[ch] = b;
      mp->hybrid_blc[ch] = b;
    }
    }
-
+  
    if(gr_info->mixed_block_flag) {
    if(gr_info->mixed_block_flag) {
      sb = 2;
      sb = 2;
 #ifdef USE_3DNOW
 #ifdef USE_3DNOW
@@ -1636,7 +1629,7 @@ static void III_hybrid(struct mpstr *mp,real fsIn[SBLIMIT][SSLIMIT],real tsOut[S
 #endif
 #endif
      rawout1 += 36; rawout2 += 36; tspnt += 2;
      rawout1 += 36; rawout2 += 36; tspnt += 2;
    }
    }
-
+ 
    bt = gr_info->block_type;
    bt = gr_info->block_type;
    if(bt == 2) {
    if(bt == 2) {
      for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
      for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
@@ -1720,7 +1713,7 @@ int do_layer3(struct mpstr *mp,struct frame *fr,int outmode,struct audio_info_st
     if(stereo == 2) {
     if(stereo == 2) {
       struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
       struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
       long part2bits;
       long part2bits;
-      if(fr->lsf)
+      if(fr->lsf) 
         part2bits = III_get_scale_factors_2(scalefacs[1],gr_info,i_stereo);
         part2bits = III_get_scale_factors_2(scalefacs[1],gr_info,i_stereo);
       else
       else
         part2bits = III_get_scale_factors_1(scalefacs[1],gr_info);
         part2bits = III_get_scale_factors_1(scalefacs[1],gr_info);
@@ -1747,7 +1740,7 @@ int do_layer3(struct mpstr *mp,struct frame *fr,int outmode,struct audio_info_st
         III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->lsf);
         III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->lsf);
 
 
       if(ms_stereo || i_stereo || (single == 3) ) {
       if(ms_stereo || i_stereo || (single == 3) ) {
-        if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb)
+        if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb) 
           sideinfo.ch[0].gr[gr].maxb = gr_info->maxb;
           sideinfo.ch[0].gr[gr].maxb = gr_info->maxb;
         else
         else
           gr_info->maxb = sideinfo.ch[0].gr[gr].maxb;
           gr_info->maxb = sideinfo.ch[0].gr[gr].maxb;
@@ -1759,7 +1752,7 @@ int do_layer3(struct mpstr *mp,struct frame *fr,int outmode,struct audio_info_st
             register int i;
             register int i;
             register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
             register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
             for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++)
             for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++)
-              *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */
+              *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */ 
           }
           }
           break;
           break;
         case 1:
         case 1:
@@ -1803,19 +1796,19 @@ int do_layer3(struct mpstr *mp,struct frame *fr,int outmode,struct audio_info_st
         int n;
         int n;
         n=(audiobufsize - pcm_point) / (2*2*32);
         n=(audiobufsize - pcm_point) / (2*2*32);
         if (n > (SSLIMIT-ss)) n=SSLIMIT-ss;
         if (n > (SSLIMIT-ss)) n=SSLIMIT-ss;
-
+        
         synth_1to1_486(hybridOut[0][ss],0,pcm_sample+pcm_point,n);
         synth_1to1_486(hybridOut[0][ss],0,pcm_sample+pcm_point,n);
         synth_1to1_486(hybridOut[1][ss],1,pcm_sample+pcm_point,n);
         synth_1to1_486(hybridOut[1][ss],1,pcm_sample+pcm_point,n);
         ss+=n;
         ss+=n;
         pcm_point+=(2*2*32)*n;
         pcm_point+=(2*2*32)*n;
-
+        
         if(pcm_point >= audiobufsize)
         if(pcm_point >= audiobufsize)
           audio_flush(outmode,ai);
           audio_flush(outmode,ai);
       }
       }
     }
     }
 #endif
 #endif
   }
   }
-
+  
   return clip;
   return clip;
 }
 }
 
 

+ 17 - 30
panda/src/mpg123/mpg123.h

@@ -1,20 +1,7 @@
-/* Filename: mpg123.h
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/*
+ * mpg123 defines 
+ * used source: musicout.h from mpegaudio package
+ */
 
 
 #include        <stdio.h>
 #include        <stdio.h>
 #include        <string.h>
 #include        <string.h>
@@ -51,7 +38,7 @@ typedef unsigned char byte;
 # define WIN32
 # define WIN32
 
 
 # define M_PI       3.14159265358979323846
 # define M_PI       3.14159265358979323846
-# define M_SQRT2        1.41421356237309504880
+# define M_SQRT2    1.41421356237309504880
 # define REAL_IS_FLOAT
 # define REAL_IS_FLOAT
 # define NEW_DCT9
 # define NEW_DCT9
 
 
@@ -88,7 +75,7 @@ typedef unsigned char byte;
 #include "mpgaudio.h"
 #include "mpgaudio.h"
 
 
 /* AUDIOBUFSIZE = n*64 with n=1,2,3 ...  */
 /* AUDIOBUFSIZE = n*64 with n=1,2,3 ...  */
-#define         AUDIOBUFSIZE            16384
+#define     AUDIOBUFSIZE        16384
 
 
 #define         FALSE                   0
 #define         FALSE                   0
 #define         TRUE                    1
 #define         TRUE                    1
@@ -112,7 +99,7 @@ typedef unsigned char byte;
 #define AUSHIFT (3)
 #define AUSHIFT (3)
 
 
 
 
-struct al_table
+struct al_table 
 {
 {
   short bits;
   short bits;
   short d;
   short d;
@@ -156,21 +143,21 @@ struct frame {
 #define VBR_SCALE_FLAG      0x0008
 #define VBR_SCALE_FLAG      0x0008
 
 
 struct vbrHeader {
 struct vbrHeader {
-        unsigned long flags;
-        unsigned long frames;
-        unsigned long bytes;
-        unsigned long scale;
-        unsigned char toc[100];
+    unsigned long flags;
+    unsigned long frames;
+    unsigned long bytes;
+    unsigned long scale;
+    unsigned char toc[100];
 };
 };
 
 
 struct parameter {
 struct parameter {
     int aggressive; /* renice to max. priority */
     int aggressive; /* renice to max. priority */
-    int shuffle;        /* shuffle/random play */
+    int shuffle;    /* shuffle/random play */
     int remote; /* remote operation */
     int remote; /* remote operation */
-    int outmode;        /* where to out the decoded sampels */
+    int outmode;    /* where to out the decoded sampels */
     int quiet;  /* shut up! */
     int quiet;  /* shut up! */
     int xterm_title;  /* print filename in xterm title */
     int xterm_title;  /* print filename in xterm title */
-    long usebuffer;     /* second level buffer size */
+    long usebuffer; /* second level buffer size */
     int tryresync;  /* resync stream after error */
     int tryresync;  /* resync stream after error */
     int verbose;    /* verbose level */
     int verbose;    /* verbose level */
 #ifdef TERM_CONTROL
 #ifdef TERM_CONTROL
@@ -394,8 +381,8 @@ extern int au_close(void);
 extern int cdr_open(struct audio_info_struct *ai, char *cdrfilename);
 extern int cdr_open(struct audio_info_struct *ai, char *cdrfilename);
 extern int cdr_close(void);
 extern int cdr_close(void);
 
 
-extern int getVBRHeader(struct vbrHeader *head,unsigned char *buf,
-        struct frame *fr);
+extern int getVBRHeader(struct vbrHeader *head,unsigned char *buf, 
+    struct frame *fr);
 
 
 
 
 extern unsigned char *conv16to8;
 extern unsigned char *conv16to8;

+ 7 - 21
panda/src/mpg123/mpgaudio.h

@@ -1,31 +1,17 @@
-/* Filename: mpgaudio.h
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/* 
+ * Audio 'LIB' defines
+ */
 
 
 #define AUDIO_OUT_HEADPHONES       0x01
 #define AUDIO_OUT_HEADPHONES       0x01
 #define AUDIO_OUT_INTERNAL_SPEAKER 0x02
 #define AUDIO_OUT_INTERNAL_SPEAKER 0x02
 #define AUDIO_OUT_LINE_OUT         0x04
 #define AUDIO_OUT_LINE_OUT         0x04
 
 
 enum { DECODE_TEST, DECODE_AUDIO, DECODE_FILE, DECODE_BUFFER, DECODE_WAV,
 enum { DECODE_TEST, DECODE_AUDIO, DECODE_FILE, DECODE_BUFFER, DECODE_WAV,
-        DECODE_AU,DECODE_CDR,DECODE_AUDIOFILE };
+    DECODE_AU,DECODE_CDR,DECODE_AUDIOFILE };
 
 
-#define AUDIO_FORMAT_MASK         0x100
-#define AUDIO_FORMAT_16           0x100
-#define AUDIO_FORMAT_8            0x000
+#define AUDIO_FORMAT_MASK     0x100
+#define AUDIO_FORMAT_16       0x100
+#define AUDIO_FORMAT_8        0x000
 
 
 #define AUDIO_FORMAT_SIGNED_16    0x110
 #define AUDIO_FORMAT_SIGNED_16    0x110
 #define AUDIO_FORMAT_UNSIGNED_16  0x120
 #define AUDIO_FORMAT_UNSIGNED_16  0x120

+ 148 - 159
panda/src/mpg123/mpgbuffer.c

@@ -1,20 +1,9 @@
-/* Filename: mpgbuffer.c
- * Created by:  
+/*
+ *   buffer.c
  *
  *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ *   Oliver Fromme  <[email protected]>
+ *   Mon Apr 14 03:53:18 MET DST 1997
+ */
 
 
 #include <stdlib.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <errno.h>
@@ -35,12 +24,12 @@ static int usr1flag = FALSE;
 
 
 static void catch_interrupt (void)
 static void catch_interrupt (void)
 {
 {
-        intflag = TRUE;
+    intflag = TRUE;
 }
 }
 
 
 static void catch_usr1 (void)
 static void catch_usr1 (void)
 {
 {
-        usr1flag = TRUE;
+    usr1flag = TRUE;
 }
 }
 
 
 /* Interfaces to writer process */
 /* Interfaces to writer process */
@@ -50,36 +39,36 @@ extern void buffer_sig(int signal, int block);
 void buffer_ignore_lowmem(void)
 void buffer_ignore_lowmem(void)
 {
 {
 #ifndef NOXFERMEM
 #ifndef NOXFERMEM
-        if(buffermem->wakeme[XF_READER])
-                xfermem_putcmd(buffermem->fd[XF_WRITER], XF_CMD_WAKEUP);
+    if(buffermem->wakeme[XF_READER])
+        xfermem_putcmd(buffermem->fd[XF_WRITER], XF_CMD_WAKEUP);
 #endif
 #endif
 }
 }
 
 
 void buffer_end(void)
 void buffer_end(void)
 {
 {
 #ifndef NOXFERMEM
 #ifndef NOXFERMEM
-        xfermem_putcmd(buffermem->fd[XF_WRITER], XF_CMD_TERMINATE);
+    xfermem_putcmd(buffermem->fd[XF_WRITER], XF_CMD_TERMINATE);
 #endif
 #endif
 }
 }
 
 
 void buffer_resync(void)
 void buffer_resync(void)
 {
 {
-        buffer_sig(SIGINT, TRUE);
+    buffer_sig(SIGINT, TRUE);
 }
 }
 
 
 void buffer_reset(void)
 void buffer_reset(void)
 {
 {
-        buffer_sig(SIGUSR1, TRUE);
+    buffer_sig(SIGUSR1, TRUE);
 }
 }
 
 
 void buffer_start(void)
 void buffer_start(void)
 {
 {
-        buffer_sig(SIGCONT, FALSE);
+    buffer_sig(SIGCONT, FALSE);
 }
 }
 
 
 void buffer_stop(void)
 void buffer_stop(void)
 {
 {
-        buffer_sig(SIGSTOP, FALSE);
+    buffer_sig(SIGSTOP, FALSE);
 }
 }
 
 
 extern int buffer_pid;
 extern int buffer_pid;
@@ -89,158 +78,158 @@ void buffer_sig(int signal, int block)
 
 
 #ifndef NOXFERMEM
 #ifndef NOXFERMEM
 
 
-        kill(buffer_pid, signal);
+    kill(buffer_pid, signal);
 
 
-        if (!buffermem || !block)
-                return;
+    if (!buffermem || !block)
+        return;
 
 
-        if(xfermem_block(XF_WRITER, buffermem) != XF_CMD_WAKEUP)
-                perror("Could not resync/reset buffers");
+    if(xfermem_block(XF_WRITER, buffermem) != XF_CMD_WAKEUP) 
+        perror("Could not resync/reset buffers");
 #endif
 #endif
 
 
-        return;
+    return;
 }
 }
 
 
 #ifndef NOXFERMEM
 #ifndef NOXFERMEM
 
 
 void buffer_loop(struct audio_info_struct *ai, sigset_t *oldsigset)
 void buffer_loop(struct audio_info_struct *ai, sigset_t *oldsigset)
 {
 {
-        int bytes;
-        int my_fd = buffermem->fd[XF_READER];
-        txfermem *xf = buffermem;
-        int done = FALSE;
-
-        catchsignal (SIGINT, catch_interrupt);
-        catchsignal (SIGUSR1, catch_usr1);
-        sigprocmask (SIG_SETMASK, oldsigset, NULL);
-        if (param.outmode == DECODE_AUDIO) {
+    int bytes;
+    int my_fd = buffermem->fd[XF_READER];
+    txfermem *xf = buffermem;
+    int done = FALSE;
+
+    catchsignal (SIGINT, catch_interrupt);
+    catchsignal (SIGUSR1, catch_usr1);
+    sigprocmask (SIG_SETMASK, oldsigset, NULL);
+    if (param.outmode == DECODE_AUDIO) {
+        if (audio_open(ai) < 0) {
+            perror("audio");
+            exit(1);
+        }
+    }
+
+    for (;;) {
+        if (intflag) {
+            intflag = FALSE;
+            if (param.outmode == DECODE_AUDIO)
+                audio_queueflush (ai);
+            xf->readindex = xf->freeindex;
+            if (xf->wakeme[XF_WRITER])
+                xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
+        }
+        if (usr1flag) {
+            usr1flag = FALSE;
+            /*   close and re-open in order to flush
+             *   the device's internal buffer before
+             *   changing the sample rate.   [OF]
+             */
+            /* writer must block when sending SIGUSR1
+             * or we will lose all data processed 
+             * in the meantime! [dk]
+             */
+            xf->readindex = xf->freeindex;
+            /* We've nailed down the new starting location -
+             * writer is now safe to go on. [dk]
+             */
+            if (xf->wakeme[XF_WRITER])
+                xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
+            if (param.outmode == DECODE_AUDIO) {
+                audio_close (ai);
+                ai->rate = xf->buf[0]; 
+                ai->channels = xf->buf[1]; 
+                ai->format = xf->buf[2];
                 if (audio_open(ai) < 0) {
                 if (audio_open(ai) < 0) {
-                        perror("audio");
-                        exit(1);
+                    perror("audio");
+                    exit(1);
                 }
                 }
+            }
         }
         }
-
-        for (;;) {
-                if (intflag) {
-                        intflag = FALSE;
-                        if (param.outmode == DECODE_AUDIO)
-                                audio_queueflush (ai);
-                        xf->readindex = xf->freeindex;
-                        if (xf->wakeme[XF_WRITER])
-                                xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
-                }
-                if (usr1flag) {
-                        usr1flag = FALSE;
-                        /*   close and re-open in order to flush
-                         *   the device's internal buffer before
-                         *   changing the sample rate.   [OF]
-                         */
-                        /* writer must block when sending SIGUSR1
-                         * or we will lose all data processed
-                         * in the meantime! [dk]
+        if ( (bytes = xfermem_get_usedspace(xf)) < outburst ) {
+            /* if we got a buffer underrun we first
+             * fill 1/8 of the buffer before continue/start
+             * playing */
+            preload = xf->size>>3;
+            if(preload < outburst)
+                preload = outburst;
+        }
+        if(bytes < preload) {
+            int cmd;
+            if (done && !bytes) { 
+                break;
+            }
+
+            if(!done) {
+
+                cmd = xfermem_block(XF_READER, xf);
+
+                switch(cmd) {
+
+                    /* More input pending. */
+                    case XF_CMD_WAKEUP_INFO:
+                        continue;
+                    /* Yes, we know buffer is low but
+                     * know we don't care.
+                     */
+                    case XF_CMD_WAKEUP:
+                        break;  /* Proceed playing. */
+                    case XF_CMD_TERMINATE:
+                        /* Proceed playing without 
+                         * blocking any further.
                          */
                          */
+                        done=TRUE;
+                        break;
+                    case -1:
+                        if(errno==EINTR)
+                            continue;
+                        perror("Yuck! Error in buffer handling...");
+                        done = TRUE;
                         xf->readindex = xf->freeindex;
                         xf->readindex = xf->freeindex;
-                        /* We've nailed down the new starting location -
-                         * writer is now safe to go on. [dk]
-                         */
-                        if (xf->wakeme[XF_WRITER])
-                                xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
-                        if (param.outmode == DECODE_AUDIO) {
-                                audio_close (ai);
-                                ai->rate = xf->buf[0];
-                                ai->channels = xf->buf[1];
-                                ai->format = xf->buf[2];
-                                if (audio_open(ai) < 0) {
-                                        perror("audio");
-                                        exit(1);
-                                }
-                        }
-                }
-                if ( (bytes = xfermem_get_usedspace(xf)) < outburst ) {
-                        /* if we got a buffer underrun we first
-                         * fill 1/8 of the buffer before continue/start
-                         * playing */
-                        preload = xf->size>>3;
-                        if(preload < outburst)
-                                preload = outburst;
-                }
-                if(bytes < preload) {
-                        int cmd;
-                        if (done && !bytes) {
-                                break;
-                        }
-
-                        if(!done) {
-
-                                cmd = xfermem_block(XF_READER, xf);
-
-                                switch(cmd) {
-
-                                        /* More input pending. */
-                                        case XF_CMD_WAKEUP_INFO:
-                                                continue;
-                                        /* Yes, we know buffer is low but
-                                         * know we don't care.
-                                         */
-                                        case XF_CMD_WAKEUP:
-                                                break;  /* Proceed playing. */
-                                        case XF_CMD_TERMINATE:
-                                                /* Proceed playing without
-                                                 * blocking any further.
-                                                 */
-                                                done=TRUE;
-                                                break;
-                                        case -1:
-                                                if(errno==EINTR)
-                                                        continue;
-                                                perror("Yuck! Error in buffer handling...");
-                                                done = TRUE;
-                                                xf->readindex = xf->freeindex;
-                                                xfermem_putcmd(xf->fd[XF_READER], XF_CMD_TERMINATE);
-                                                break;
-                                        default:
-                                                fprintf(stderr, "\nEh!? Received unknown command 0x%x in buffer process. Tell Daniel!\n", cmd);
-                                }
-                        }
+                        xfermem_putcmd(xf->fd[XF_READER], XF_CMD_TERMINATE);
+                        break;
+                    default:
+                        fprintf(stderr, "\nEh!? Received unknown command 0x%x in buffer process. Tell Daniel!\n", cmd);
                 }
                 }
-                preload = outburst; /* set preload to lower mark */
-                if (bytes > xf->size - xf->readindex)
-                        bytes = xf->size - xf->readindex;
-                if (bytes > outburst)
-                        bytes = outburst;
-
-                if (param.outmode == DECODE_FILE)
-                        bytes = write(OutputDescriptor, xf->data + xf->readindex, bytes);
-                else if (param.outmode == DECODE_AUDIO)
-                        bytes = audio_play_samples(ai,
-                                (unsigned char *) (xf->data + xf->readindex), bytes);
-
-                if(bytes < 0) {
-                        bytes = 0;
-                        if(errno != EINTR) {
-                                perror("Ouch ... error while writing audio data: ");
-                                /*
-                                 * done==TRUE tells writer process to stop
-                                 * sending data. There might be some latency
-                                 * involved when resetting readindex to
-                                 * freeindex so we might need more than one
-                                 * cycle to terminate. (The number of cycles
-                                 * should be finite unless I managed to mess
-                                 * up something. ;-) [dk]
-                                 */
-                                done = TRUE;
-                                xf->readindex = xf->freeindex;
-                                xfermem_putcmd(xf->fd[XF_READER], XF_CMD_TERMINATE);
-                        }
-                }
-
-                xf->readindex = (xf->readindex + bytes) % xf->size;
-                if (xf->wakeme[XF_WRITER])
-                        xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
+            }
+        }
+        preload = outburst; /* set preload to lower mark */
+        if (bytes > xf->size - xf->readindex)
+            bytes = xf->size - xf->readindex;
+        if (bytes > outburst)
+            bytes = outburst;
+
+        if (param.outmode == DECODE_FILE)
+            bytes = write(OutputDescriptor, xf->data + xf->readindex, bytes);
+        else if (param.outmode == DECODE_AUDIO)
+            bytes = audio_play_samples(ai,
+                (unsigned char *) (xf->data + xf->readindex), bytes);
+
+        if(bytes < 0) {
+            bytes = 0;
+            if(errno != EINTR) {
+                perror("Ouch ... error while writing audio data: ");
+                /*
+                 * done==TRUE tells writer process to stop
+                 * sending data. There might be some latency
+                 * involved when resetting readindex to 
+                 * freeindex so we might need more than one
+                 * cycle to terminate. (The number of cycles
+                 * should be finite unless I managed to mess
+                 * up something. ;-) [dk]
+                 */
+                done = TRUE;
+                xf->readindex = xf->freeindex;
+                xfermem_putcmd(xf->fd[XF_READER], XF_CMD_TERMINATE);
+            }
         }
         }
 
 
-        if (param.outmode == DECODE_AUDIO)
-                audio_close (ai);
+        xf->readindex = (xf->readindex + bytes) % xf->size;
+        if (xf->wakeme[XF_WRITER])
+            xfermem_putcmd(my_fd, XF_CMD_WAKEUP);
+    }
+
+    if (param.outmode == DECODE_AUDIO)
+        audio_close (ai);
 }
 }
 
 
 #endif
 #endif

+ 6 - 17
panda/src/mpg123/mpgbuffer.h

@@ -1,20 +1,9 @@
-/* Filename: mpgbuffer.h
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/*
+ * Application specific interaction between main and buffer
+ * process. This is much less generic than the functions in
+ * xfermem so I chose to put it in buffer.[hc].
+ * 01/28/99 [dk]
+ */
 
 
 void buffer_ignore_lowmem(void);
 void buffer_ignore_lowmem(void);
 void buffer_end(void);
 void buffer_end(void);

+ 116 - 134
panda/src/mpg123/readers.c

@@ -1,21 +1,3 @@
-/* Filename: readers.c
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
 #include <stdlib.h>
 #include <stdlib.h>
 
 
 #include <sys/types.h>
 #include <sys/types.h>
@@ -45,13 +27,13 @@ static int fullread(int fd,unsigned char *buf,int count)
 {
 {
     int ret,cnt=0;
     int ret,cnt=0;
     while(cnt < count) {
     while(cnt < count) {
-        ret = read(fd,buf+cnt,count-cnt);
-        if(ret < 0)
-            return ret;
-        if(ret == 0)
-            break;
-        cnt += ret;
-    }
+    ret = read(fd,buf+cnt,count-cnt);
+    if(ret < 0)
+        return ret;
+    if(ret == 0)
+        break;
+    cnt += ret;
+    } 
 
 
     return cnt;
     return cnt;
 }
 }
@@ -62,12 +44,12 @@ static int default_init(struct reader *rds)
 
 
     rds->filepos = 0;
     rds->filepos = 0;
     rds->filelen = get_fileinfo(rds,buf);
     rds->filelen = get_fileinfo(rds,buf);
-
+  
     if(rds->filelen > 0) {
     if(rds->filelen > 0) {
-        if(!strncmp(buf,"TAG",3)) {
-            rds->flags |= READER_ID3TAG;
-            memcpy(rds->id3buf,buf,128);
-        }
+    if(!strncmp(buf,"TAG",3)) {
+        rds->flags |= READER_ID3TAG;
+        memcpy(rds->id3buf,buf,128);
+    }
     }
     }
     return 0;
     return 0;
 }
 }
@@ -78,16 +60,16 @@ void stream_close(struct reader *rds)
         close(rds->filept);
         close(rds->filept);
 }
 }
 
 
-/****************************************
- * HACK,HACK,HACK: step back <num> frames
+/**************************************** 
+ * HACK,HACK,HACK: step back <num> frames 
  * can only work if the 'stream' isn't a real stream but a file
  * can only work if the 'stream' isn't a real stream but a file
  */
  */
 static int stream_back_bytes(struct reader *rds,int bytes)
 static int stream_back_bytes(struct reader *rds,int bytes)
 {
 {
     if(lseek(rds->filept,-bytes,SEEK_CUR) < 0)
     if(lseek(rds->filept,-bytes,SEEK_CUR) < 0)
-        return -1;
+    return -1;
     if(param.usebuffer)
     if(param.usebuffer)
-        buffer_resync();
+    buffer_resync();
     return 0;
     return 0;
 }
 }
 
 
@@ -98,50 +80,50 @@ static int stream_back_frame(struct reader *rds,struct frame *fr,int num)
     unsigned long newhead;
     unsigned long newhead;
 
 
     if(!firsthead)
     if(!firsthead)
-        return 0;
+    return 0;
 
 
     bytes = (fr->framesize+8)*(num+2);
     bytes = (fr->framesize+8)*(num+2);
 
 
-    /* Skipping back/forth requires a bit more work in buffered mode.
-     * See mapped_back_frame().
+    /* Skipping back/forth requires a bit more work in buffered mode. 
+     * See mapped_back_frame(). 
      */
      */
     if(param.usebuffer)
     if(param.usebuffer)
-        bytes += (long)(xfermem_get_usedspace(buffermem) /
-                        (buffermem->buf[0] * buffermem->buf[1]
-                         * (buffermem->buf[2] & AUDIO_FORMAT_MASK ?
-                            16.0 : 8.0 ))
-                        * (tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index] << 10));
+    bytes += (long)(xfermem_get_usedspace(buffermem) /
+            (buffermem->buf[0] * buffermem->buf[1]
+             * (buffermem->buf[2] & AUDIO_FORMAT_MASK ?
+                16.0 : 8.0 ))
+            * (tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index] << 10));
     /*
     /*
       bytes += (long)(compute_buffer_offset(fr)*compute_bpf(fr));
       bytes += (long)(compute_buffer_offset(fr)*compute_bpf(fr));
     */
     */
     if(lseek(rds->filept,-bytes,SEEK_CUR) < 0)
     if(lseek(rds->filept,-bytes,SEEK_CUR) < 0)
-        return -1;
+    return -1;
 
 
     if(fullread(rds->filept,buf,4) != 4)
     if(fullread(rds->filept,buf,4) != 4)
-        return -1;
+    return -1;
 
 
     newhead = (buf[0]<<24) + (buf[1]<<16) + (buf[2]<<8) + buf[3];
     newhead = (buf[0]<<24) + (buf[1]<<16) + (buf[2]<<8) + buf[3];
 
 
     while( (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK) ) {
     while( (newhead & HDRCMPMASK) != (firsthead & HDRCMPMASK) ) {
-        if(fullread(rds->filept,buf,1) != 1)
-            return -1;
-        newhead <<= 8;
-        newhead |= buf[0];
-        newhead &= 0xffffffff;
+    if(fullread(rds->filept,buf,1) != 1)
+        return -1;
+    newhead <<= 8;
+    newhead |= buf[0];
+    newhead &= 0xffffffff;
     }
     }
 
 
     if( lseek(rds->filept,-4,SEEK_CUR) < 0)
     if( lseek(rds->filept,-4,SEEK_CUR) < 0)
-        return -1;
+    return -1;
 
 
     read_frame(fr);
     read_frame(fr);
     read_frame(fr);
     read_frame(fr);
 
 
     if(fr->lay == 3) {
     if(fr->lay == 3) {
-        set_pointer(512);
+    set_pointer(512);
     }
     }
 
 
     if(param.usebuffer)
     if(param.usebuffer)
-        buffer_resync();
+    buffer_resync();
 
 
     return 0;
     return 0;
 }
 }
@@ -151,13 +133,13 @@ static int stream_head_read(struct reader *rds,unsigned long *newhead)
     unsigned char hbuf[4];
     unsigned char hbuf[4];
 
 
     if(fullread(rds->filept,hbuf,4) != 4)
     if(fullread(rds->filept,hbuf,4) != 4)
-        return FALSE;
-
+    return FALSE;
+  
     *newhead = ((unsigned long) hbuf[0] << 24) |
     *newhead = ((unsigned long) hbuf[0] << 24) |
-        ((unsigned long) hbuf[1] << 16) |
-        ((unsigned long) hbuf[2] << 8)  |
-        (unsigned long) hbuf[3];
-
+    ((unsigned long) hbuf[1] << 16) |
+    ((unsigned long) hbuf[2] << 8)  |
+    (unsigned long) hbuf[3];
+  
     return TRUE;
     return TRUE;
 }
 }
 
 
@@ -166,7 +148,7 @@ static int stream_head_shift(struct reader *rds,unsigned long *head)
     unsigned char hbuf;
     unsigned char hbuf;
 
 
     if(fullread(rds->filept,&hbuf,1) != 1)
     if(fullread(rds->filept,&hbuf,1) != 1)
-        return 0;
+    return 0;
     *head <<= 8;
     *head <<= 8;
     *head |= hbuf;
     *head |= hbuf;
     *head &= 0xffffffff;
     *head &= 0xffffffff;
@@ -176,28 +158,28 @@ static int stream_head_shift(struct reader *rds,unsigned long *head)
 static int stream_skip_bytes(struct reader *rds,int len)
 static int stream_skip_bytes(struct reader *rds,int len)
 {
 {
     if (!param.usebuffer)
     if (!param.usebuffer)
-        return lseek(rds->filept,len,SEEK_CUR);
+    return lseek(rds->filept,len,SEEK_CUR);
 
 
     else {
     else {
 
 
-        int ret = lseek(rds->filept,len,SEEK_CUR);
-        buffer_resync();
-        return ret;
+    int ret = lseek(rds->filept,len,SEEK_CUR);
+    buffer_resync();
+    return ret;
 
 
     }
     }
 }
 }
 
 
 static int stream_read_frame_body(struct reader *rds,unsigned char *buf,
 static int stream_read_frame_body(struct reader *rds,unsigned char *buf,
-                                  int size)
+                  int size)
 {
 {
     long l;
     long l;
 
 
     if( (l=fullread(rds->filept,buf,size)) != size)
     if( (l=fullread(rds->filept,buf,size)) != size)
-        {
-            if(l <= 0)
-                return 0;
-            memset(buf+l,0,size-l);
-        }
+    {
+        if(l <= 0)
+        return 0;
+        memset(buf+l,0,size-l);
+    }
 
 
     return 1;
     return 1;
 }
 }
@@ -210,8 +192,8 @@ static long stream_tell(struct reader *rds)
 static void stream_rewind(struct reader *rds)
 static void stream_rewind(struct reader *rds)
 {
 {
     lseek(rds->filept,0,SEEK_SET);
     lseek(rds->filept,0,SEEK_SET);
-    if(param.usebuffer)
-        buffer_resync();
+    if(param.usebuffer) 
+    buffer_resync();
 }
 }
 
 
 /*
 /*
@@ -223,56 +205,56 @@ static int get_fileinfo(struct reader *rds,char *buf)
     int len;
     int len;
 
 
     if((len=lseek(rds->filept,0,SEEK_END)) < 0) {
     if((len=lseek(rds->filept,0,SEEK_END)) < 0) {
-        return -1;
+    return -1;
     }
     }
     if(lseek(rds->filept,-128,SEEK_END) < 0)
     if(lseek(rds->filept,-128,SEEK_END) < 0)
-        return -1;
+    return -1;
     if(fullread(rds->filept,(unsigned char *)buf,128) != 128) {
     if(fullread(rds->filept,(unsigned char *)buf,128) != 128) {
-        return -1;
+    return -1;
     }
     }
     if(!strncmp(buf,"TAG",3)) {
     if(!strncmp(buf,"TAG",3)) {
-        len -= 128;
+    len -= 128;
     }
     }
     if(lseek(rds->filept,0,SEEK_SET) < 0)
     if(lseek(rds->filept,0,SEEK_SET) < 0)
-        return -1;
+    return -1;
     if(len <= 0)
     if(len <= 0)
-        return -1;
+    return -1;
     return len;
     return len;
 }
 }
 
 
 
 
 #ifdef READ_MMAP
 #ifdef READ_MMAP
 /*********************************************************+
 /*********************************************************+
- * memory mapped operation
+ * memory mapped operation 
  *
  *
  */
  */
 static unsigned char *mapbuf;
 static unsigned char *mapbuf;
 static unsigned char *mappnt;
 static unsigned char *mappnt;
 static unsigned char *mapend;
 static unsigned char *mapend;
 
 
-static int mapped_init(struct reader *rds)
+static int mapped_init(struct reader *rds) 
 {
 {
     long len;
     long len;
     char buf[128];
     char buf[128];
 
 
     len = get_fileinfo(rds,buf);
     len = get_fileinfo(rds,buf);
     if(len < 0)
     if(len < 0)
-        return -1;
+    return -1;
 
 
     if(!strncmp(buf,"TAG",3)) {
     if(!strncmp(buf,"TAG",3)) {
-        rds->flags |= READER_ID3TAG;
-        memcpy(rds->id3buf,buf,128);
+    rds->flags |= READER_ID3TAG;
+    memcpy(rds->id3buf,buf,128);
     }
     }
 
 
     mappnt = mapbuf = (unsigned char *)
     mappnt = mapbuf = (unsigned char *)
-        mmap(NULL, len, PROT_READ, MAP_SHARED , rds->filept, 0);
+    mmap(NULL, len, PROT_READ, MAP_SHARED , rds->filept, 0);
     if(!mapbuf || mapbuf == MAP_FAILED)
     if(!mapbuf || mapbuf == MAP_FAILED)
-        return -1;
+    return -1;
 
 
     mapend = mapbuf + len;
     mapend = mapbuf + len;
 
 
     if(param.verbose > 1)
     if(param.verbose > 1)
-        fprintf(stderr,"Using memory mapped IO for this stream.\n");
+    fprintf(stderr,"Using memory mapped IO for this stream.\n");
 
 
     rds->filelen = len;
     rds->filelen = len;
     return 0;
     return 0;
@@ -281,23 +263,23 @@ static int mapped_init(struct reader *rds)
 static void mapped_rewind(struct reader *rds)
 static void mapped_rewind(struct reader *rds)
 {
 {
     mappnt = mapbuf;
     mappnt = mapbuf;
-    if (param.usebuffer)
-        buffer_resync();
+    if (param.usebuffer) 
+    buffer_resync();
 }
 }
 
 
 static void mapped_close(struct reader *rds)
 static void mapped_close(struct reader *rds)
 {
 {
     munmap((void *)mapbuf,mapend-mapbuf);
     munmap((void *)mapbuf,mapend-mapbuf);
     if (rds->flags & READER_FD_OPENED)
     if (rds->flags & READER_FD_OPENED)
-        close(rds->filept);
+    close(rds->filept);
 }
 }
 
 
-static int mapped_head_read(struct reader *rds,unsigned long *newhead)
+static int mapped_head_read(struct reader *rds,unsigned long *newhead) 
 {
 {
     unsigned long nh;
     unsigned long nh;
 
 
     if(mappnt + 4 > mapend)
     if(mappnt + 4 > mapend)
-        return FALSE;
+    return FALSE;
 
 
     nh = (*mappnt++)  << 24;
     nh = (*mappnt++)  << 24;
     nh |= (*mappnt++) << 16;
     nh |= (*mappnt++) << 16;
@@ -311,7 +293,7 @@ static int mapped_head_read(struct reader *rds,unsigned long *newhead)
 static int mapped_head_shift(struct reader *rds,unsigned long *head)
 static int mapped_head_shift(struct reader *rds,unsigned long *head)
 {
 {
     if(mappnt + 1 > mapend)
     if(mappnt + 1 > mapend)
-        return FALSE;
+    return FALSE;
     *head <<= 8;
     *head <<= 8;
     *head |= *mappnt++;
     *head |= *mappnt++;
     *head &= 0xffffffff;
     *head &= 0xffffffff;
@@ -321,22 +303,22 @@ static int mapped_head_shift(struct reader *rds,unsigned long *head)
 static int mapped_skip_bytes(struct reader *rds,int len)
 static int mapped_skip_bytes(struct reader *rds,int len)
 {
 {
     if(mappnt + len > mapend)
     if(mappnt + len > mapend)
-        return FALSE;
+    return FALSE;
     mappnt += len;
     mappnt += len;
     if (param.usebuffer)
     if (param.usebuffer)
-        buffer_resync();
+    buffer_resync();
     return TRUE;
     return TRUE;
 }
 }
 
 
 static int mapped_read_frame_body(struct reader *rds,unsigned char *buf,
 static int mapped_read_frame_body(struct reader *rds,unsigned char *buf,
-                                  int size)
+                  int size)
 {
 {
     if(size <= 0) {
     if(size <= 0) {
-        fprintf(stderr,"Ouch. Read_frame called with size <= 0\n");
-        return FALSE;
+    fprintf(stderr,"Ouch. Read_frame called with size <= 0\n");
+    return FALSE;
     }
     }
     if(mappnt + size > mapend)
     if(mappnt + size > mapend)
-        return FALSE;
+    return FALSE;
     memcpy(buf,mappnt,size);
     memcpy(buf,mappnt,size);
     mappnt += size;
     mappnt += size;
 
 
@@ -349,7 +331,7 @@ static int mapped_back_bytes(struct reader *rds,int bytes)
         return -1;
         return -1;
     mappnt -= bytes;
     mappnt -= bytes;
     if(param.usebuffer)
     if(param.usebuffer)
-        buffer_resync();
+    buffer_resync();
     return 0;
     return 0;
 }
 }
 
 
@@ -368,14 +350,14 @@ static int mapped_back_frame(struct reader *rds,struct frame *fr,int num)
      * output audio stream we have to make a guess at the number of frames
      * output audio stream we have to make a guess at the number of frames
      * this corresponds to.
      * this corresponds to.
      */
      */
-    if(param.usebuffer)
-        bytes += (long)(xfermem_get_usedspace(buffermem) /
-                        (buffermem->buf[0] * buffermem->buf[1]
-                         * (buffermem->buf[2] & AUDIO_FORMAT_MASK ?
-                            16.0 : 8.0 ))
-                        * (tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index] << 10));
+    if(param.usebuffer) 
+    bytes += (long)(xfermem_get_usedspace(buffermem) /
+            (buffermem->buf[0] * buffermem->buf[1] 
+             * (buffermem->buf[2] & AUDIO_FORMAT_MASK ?
+                16.0 : 8.0 )) 
+            * (tabsel_123[fr->lsf][fr->lay-1][fr->bitrate_index] << 10));
     /*
     /*
-      bytes += (long)(compute_buffer_offset(fr)*compute_bpf(fr));
+      bytes += (long)(compute_buffer_offset(fr)*compute_bpf(fr));  
     */
     */
 
 
     if( (mappnt - bytes) < mapbuf || (mappnt - bytes + 4) > mapend)
     if( (mappnt - bytes) < mapbuf || (mappnt - bytes + 4) > mapend)
@@ -401,8 +383,8 @@ static int mapped_back_frame(struct reader *rds,struct frame *fr,int num)
         set_pointer(512);
         set_pointer(512);
 
 
     if(param.usebuffer)
     if(param.usebuffer)
-        buffer_resync();
-
+    buffer_resync();
+    
     return 0;
     return 0;
 }
 }
 
 
@@ -421,7 +403,7 @@ struct reader *rd;
 struct reader readers[] = {
 struct reader readers[] = {
 #ifdef READ_SYSTEM
 #ifdef READ_SYSTEM
     { system_init,
     { system_init,
-      NULL,     /* filled in by system_init() */
+      NULL, /* filled in by system_init() */
       NULL,
       NULL,
       NULL,
       NULL,
       NULL,
       NULL,
@@ -440,8 +422,8 @@ struct reader readers[] = {
       mapped_back_bytes,
       mapped_back_bytes,
       mapped_back_frame,
       mapped_back_frame,
       mapped_tell,
       mapped_tell,
-      mapped_rewind } ,
-#endif
+      mapped_rewind } , 
+#endif 
     { default_init,
     { default_init,
       stream_close,
       stream_close,
       stream_head_read,
       stream_head_read,
@@ -465,42 +447,42 @@ struct reader *open_stream(char *bs_filenam,int fd)
     int filept;
     int filept;
 
 
     if (!bs_filenam) {
     if (!bs_filenam) {
-        if(fd < 0) {
-            filept = 0;
-            filept_opened = 0;
-        }
-        else
-            filept = fd;
+    if(fd < 0) {
+        filept = 0;
+        filept_opened = 0;
     }
     }
-    else if (!strncmp(bs_filenam, "http://", 7))
-        filept = http_open(bs_filenam);
+    else
+        filept = fd;
+    }
+    else if (!strncmp(bs_filenam, "http://", 7)) 
+    filept = http_open(bs_filenam);
 #ifndef O_BINARY
 #ifndef O_BINARY
 #define O_BINARY (0)
 #define O_BINARY (0)
 #endif
 #endif
     else if ( (filept = open(bs_filenam, O_RDONLY|O_BINARY)) < 0) {
     else if ( (filept = open(bs_filenam, O_RDONLY|O_BINARY)) < 0) {
-        perror (bs_filenam);
-        return NULL;
+    perror (bs_filenam);
+    return NULL;
     }
     }
 
 
     rd = NULL;
     rd = NULL;
     for(i=0;;i++) {
     for(i=0;;i++) {
-        readers[i].filelen = -1;
-        readers[i].filept  = filept;
-        readers[i].flags = 0;
-        if(filept_opened)
-            readers[i].flags |= READER_FD_OPENED;
-        if(!readers[i].init) {
-            fprintf(stderr,"Fatal error!\n");
-            exit(1);
-        }
-        if(readers[i].init(readers+i) >= 0) {
-            rd = &readers[i];
-            break;
-        }
+    readers[i].filelen = -1;
+    readers[i].filept  = filept;
+    readers[i].flags = 0;
+    if(filept_opened)
+        readers[i].flags |= READER_FD_OPENED;
+    if(!readers[i].init) {
+        fprintf(stderr,"Fatal error!\n");
+        exit(1);
+    }
+    if(readers[i].init(readers+i) >= 0) {
+        rd = &readers[i];
+        break;
+    }
     }
     }
 
 
     if(rd && rd->flags & READER_ID3TAG) {
     if(rd && rd->flags & READER_ID3TAG) {
-        print_id3_tag(rd->id3buf);
+    print_id3_tag(rd->id3buf);
     }
     }
 
 
     return rd;
     return rd;

+ 3 - 20
panda/src/mpg123/tabinit.c

@@ -1,20 +1,3 @@
-/* Filename: tabinit.c
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 
 #include <stdlib.h>
 #include <stdlib.h>
 
 
@@ -64,7 +47,7 @@ void make_decode_tables(long scaleval)
   real *costab;
   real *costab;
   int idx;
   int idx;
 
 
-
+  
   for(i=0;i<5;i++)
   for(i=0;i<5;i++)
   {
   {
     kr=0x10>>i; divv=0x40>>i;
     kr=0x10>>i; divv=0x40>>i;
@@ -129,8 +112,8 @@ void make_conv16to8_table(int mode)
         c1 = 127 - (int) (log( 1.0 - 255.0 * (double) i*mul / 32768.0 ) * m);
         c1 = 127 - (int) (log( 1.0 - 255.0 * (double) i*mul / 32768.0 ) * m);
       else
       else
         c1 = 255 - (int) (log( 1.0 + 255.0 * (double) i*mul / 32768.0 ) * m);
         c1 = 255 - (int) (log( 1.0 + 255.0 * (double) i*mul / 32768.0 ) * m);
-      if(c1 < 0 || c1 > 255)
-        fprintf(stderr,"Converror %d %d\n",i,c1);
+      if(c1 < 0 || c1 > 255) 
+    fprintf(stderr,"Converror %d %d\n",i,c1);
       if(c1 == 0)
       if(c1 == 0)
         c1 = 2;
         c1 = 2;
       conv16to8[i] = (unsigned char) c1;
       conv16to8[i] = (unsigned char) c1;

+ 22 - 36
panda/src/mpg123/vbrhead.c

@@ -1,20 +1,6 @@
-/* Filename: vbrhead.c
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+/*
+ * This checks for the VBR Header defined by Xing(tm)
+ */
 
 
 #include "mpg123.h"
 #include "mpg123.h"
 
 
@@ -22,54 +8,54 @@ static unsigned long get32bits(unsigned char *buf) {
     unsigned long ret = 0;
     unsigned long ret = 0;
 
 
     ret = (((unsigned long) buf[0]) << 24) |
     ret = (((unsigned long) buf[0]) << 24) |
-        (((unsigned long) buf[1]) << 16) |
-        (((unsigned long) buf[2]) << 8) |
-        ((unsigned long) buf[3]) ;
+    (((unsigned long) buf[1]) << 16) |
+    (((unsigned long) buf[2]) << 8) |
+    ((unsigned long) buf[3]) ;
 
 
     return ret;
     return ret;
 }
 }
 
 
-int getVBRHeader(struct vbrHeader *head,unsigned char *buf, struct frame *fr)
+int getVBRHeader(struct vbrHeader *head,unsigned char *buf, struct frame *fr) 
 {
 {
     int ssize;
     int ssize;
 
 
     if(fr->lay != 3)
     if(fr->lay != 3)
-        return 0;
+    return 0;
 
 
     if(fr->lsf)
     if(fr->lsf)
-        ssize = (fr->stereo == 1) ? 9 : 17;
+    ssize = (fr->stereo == 1) ? 9 : 17;
     else
     else
-        ssize = (fr->stereo == 1) ? 17 : 32;
+    ssize = (fr->stereo == 1) ? 17 : 32;
 
 
 
 
     buf += ssize;
     buf += ssize;
 
 
     if(( buf[0] != 'X' ) || ( buf[1] != 'i' ) ||
     if(( buf[0] != 'X' ) || ( buf[1] != 'i' ) ||
-       ( buf[2] != 'n' ) || ( buf[3] != 'g' ) )
-        return 0;
+       ( buf[2] != 'n' ) || ( buf[3] != 'g' ) ) 
+    return 0;
     buf+=4;
     buf+=4;
-
+    
     head->flags = get32bits(buf);
     head->flags = get32bits(buf);
     buf+=4;
     buf+=4;
-
+    
     if(head->flags & VBR_FRAMES_FLAG) {
     if(head->flags & VBR_FRAMES_FLAG) {
-        head->frames = get32bits(buf);
-        buf += 4;
+    head->frames = get32bits(buf);
+    buf += 4;
     }
     }
 
 
     if(head->flags & VBR_BYTES_FLAG) {
     if(head->flags & VBR_BYTES_FLAG) {
-        head->bytes  = get32bits(buf);
-        buf += 4;
+    head->bytes  = get32bits(buf); 
+    buf += 4;
     }
     }
 
 
     if(head->flags & VBR_TOC_FLAG) {
     if(head->flags & VBR_TOC_FLAG) {
-        memcpy(head->toc,buf,100);
-        buf += 100;
+    memcpy(head->toc,buf,100);
+    buf += 100;
     }
     }
 
 
     if(head->flags & VBR_SCALE_FLAG) {
     if(head->flags & VBR_SCALE_FLAG) {
-        head->scale = get32bits(buf);
-        buf += 4;
+    head->scale = get32bits(buf);
+    buf += 4;
     }
     }
 
 
     /* fprintf(stderr,"Found XING %04lx\n",head->flags); */
     /* fprintf(stderr,"Found XING %04lx\n",head->flags); */

+ 132 - 141
panda/src/mpg123/xfermem.c

@@ -1,20 +1,11 @@
-/* Filename: xfermem.c
- * Created by:  
+/*
+ *   xfermem.c
  *
  *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ *   Oliver Fromme  <[email protected]>
+ *   Sun Apr  6 02:26:26 MET DST 1997
  *
  *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
- *
- * To contact the maintainers of this program write to
- * [email protected] .
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ *   See xfermem.h for documentation/description.
+ */
 
 
 #ifndef NOXFERMEM
 #ifndef NOXFERMEM
 
 
@@ -53,189 +44,189 @@ extern int errno;
 
 
 void xfermem_init (txfermem **xf, int bufsize, int msize, int skipbuf)
 void xfermem_init (txfermem **xf, int bufsize, int msize, int skipbuf)
 {
 {
-        int regsize = bufsize + msize + skipbuf + sizeof(txfermem);
-        extern int preload;
+    int regsize = bufsize + msize + skipbuf + sizeof(txfermem);
+    extern int preload;
 
 
 #ifdef USE_MMAP
 #ifdef USE_MMAP
 #  ifdef MAP_ANON
 #  ifdef MAP_ANON
-        if ((*xf = (txfermem *) mmap(0, regsize, PROT_READ | PROT_WRITE,
-                        MAP_ANON | MAP_SHARED, -1, 0)) == (txfermem *) -1) {
-                perror ("mmap()");
-                exit (1);
-        }
+    if ((*xf = (txfermem *) mmap(0, regsize, PROT_READ | PROT_WRITE,
+            MAP_ANON | MAP_SHARED, -1, 0)) == (txfermem *) -1) {
+        perror ("mmap()");
+        exit (1);
+    }
 #  else
 #  else
-        int devzero;
-        if ((devzero = open("/dev/zero", O_RDWR, 0)) == -1) {
-                perror ("open(/dev/zero)");
-                exit (1);
-        }
-        if ((*xf = (txfermem *) mmap(0, regsize, PROT_READ | PROT_WRITE,
-                        MAP_SHARED, devzero, 0)) == (txfermem *) -1) {
-                perror ("mmap()");
-                exit (1);
-        }
-        close (devzero);
+    int devzero;
+    if ((devzero = open("/dev/zero", O_RDWR, 0)) == -1) {
+        perror ("open(/dev/zero)");
+        exit (1);
+    }
+    if ((*xf = (txfermem *) mmap(0, regsize, PROT_READ | PROT_WRITE,
+            MAP_SHARED, devzero, 0)) == (txfermem *) -1) {
+        perror ("mmap()");
+        exit (1);
+    }
+    close (devzero);
 #  endif
 #  endif
 #else
 #else
-        struct shmid_ds shmemds;
-        int shmemid;
-        if ((shmemid = shmget(IPC_PRIVATE, regsize, IPC_CREAT | 0600)) == -1) {
-                perror ("shmget()");
-                exit (1);
-        }
-        if ((*xf = (txfermem *) shmat(shmemid, 0, 0)) == (txfermem *) -1) {
-                perror ("shmat()");
-                shmctl (shmemid, IPC_RMID, &shmemds);
-                exit (1);
-        }
-        if (shmctl(shmemid, IPC_RMID, &shmemds) == -1) {
-                perror ("shmctl()");
-                xfermem_done (*xf);
-                exit (1);
-        }
+    struct shmid_ds shmemds;
+    int shmemid;
+    if ((shmemid = shmget(IPC_PRIVATE, regsize, IPC_CREAT | 0600)) == -1) {
+        perror ("shmget()");
+        exit (1);
+    }
+    if ((*xf = (txfermem *) shmat(shmemid, 0, 0)) == (txfermem *) -1) {
+        perror ("shmat()");
+        shmctl (shmemid, IPC_RMID, &shmemds);
+        exit (1);
+    }
+    if (shmctl(shmemid, IPC_RMID, &shmemds) == -1) {
+        perror ("shmctl()");
+        xfermem_done (*xf);
+        exit (1);
+    }
 #endif
 #endif
-        if (socketpair(AF_UNIX, SOCK_STREAM, 0, (*xf)->fd) < 0) {
-                perror ("socketpair()");
-                xfermem_done (*xf);
-                exit (1);
-        }
-        (*xf)->freeindex = (*xf)->readindex = 0;
-        (*xf)->wakeme[0] = (*xf)->wakeme[1] = FALSE;
-        (*xf)->data = ((byte *) *xf) + sizeof(txfermem) + msize;
-        (*xf)->metadata = ((byte *) *xf) + sizeof(txfermem);
-        (*xf)->size = bufsize;
-        (*xf)->metasize = msize + skipbuf;
-        preload = bufsize>>3;
+    if (socketpair(AF_UNIX, SOCK_STREAM, 0, (*xf)->fd) < 0) {
+        perror ("socketpair()");
+        xfermem_done (*xf);
+        exit (1);
+    }
+    (*xf)->freeindex = (*xf)->readindex = 0;
+    (*xf)->wakeme[0] = (*xf)->wakeme[1] = FALSE;
+    (*xf)->data = ((byte *) *xf) + sizeof(txfermem) + msize;
+    (*xf)->metadata = ((byte *) *xf) + sizeof(txfermem);
+    (*xf)->size = bufsize;
+    (*xf)->metasize = msize + skipbuf;
+    preload = bufsize>>3;
 }
 }
 
 
 void xfermem_done (txfermem *xf)
 void xfermem_done (txfermem *xf)
 {
 {
-        if(!xf)
-                return;
+    if(!xf)
+        return;
 #ifdef USE_MMAP
 #ifdef USE_MMAP
-        munmap ((caddr_t) xf, xf->size + xf->metasize + sizeof(txfermem));
+    munmap ((caddr_t) xf, xf->size + xf->metasize + sizeof(txfermem));
 #else
 #else
-        if (shmdt((void *) xf) == -1) {
-                perror ("shmdt()");
-                exit (1);
-        }
+    if (shmdt((void *) xf) == -1) {
+        perror ("shmdt()");
+        exit (1);
+    }
 #endif
 #endif
 }
 }
 
 
 void xfermem_init_writer (txfermem *xf)
 void xfermem_init_writer (txfermem *xf)
 {
 {
-        if(xf)
-                close (xf->fd[XF_READER]);
+    if(xf)
+        close (xf->fd[XF_READER]);
 }
 }
 
 
 void xfermem_init_reader (txfermem *xf)
 void xfermem_init_reader (txfermem *xf)
 {
 {
-        if(xf)
-                close (xf->fd[XF_WRITER]);
+    if(xf)
+        close (xf->fd[XF_WRITER]);
 }
 }
 
 
 int xfermem_get_freespace (txfermem *xf)
 int xfermem_get_freespace (txfermem *xf)
 {
 {
-        int freeindex, readindex;
+    int freeindex, readindex;
 
 
-        if(!xf)
-                return 0;
+    if(!xf)
+        return 0;
 
 
-        if ((freeindex = xf->freeindex) < 0
-                        || (readindex = xf->readindex) < 0)
-                return (0);
-        if (readindex > freeindex)
-                return ((readindex - freeindex) - 1);
-        else
-                return ((xf->size - (freeindex - readindex)) - 1);
+    if ((freeindex = xf->freeindex) < 0
+            || (readindex = xf->readindex) < 0)
+        return (0);
+    if (readindex > freeindex)
+        return ((readindex - freeindex) - 1);
+    else
+        return ((xf->size - (freeindex - readindex)) - 1);
 }
 }
 
 
 int xfermem_get_usedspace (txfermem *xf)
 int xfermem_get_usedspace (txfermem *xf)
 {
 {
-        int freeindex, readindex;
+    int freeindex, readindex;
 
 
-        if(!xf)
-                return 0;
+    if(!xf)
+        return 0;
 
 
-        if ((freeindex = xf->freeindex) < 0
-                        || (readindex = xf->readindex) < 0)
-                return (0);
-        if (freeindex >= readindex)
-                return (freeindex - readindex);
-        else
-                return (xf->size - (readindex - freeindex));
+    if ((freeindex = xf->freeindex) < 0
+            || (readindex = xf->readindex) < 0)
+        return (0);
+    if (freeindex >= readindex)
+        return (freeindex - readindex);
+    else
+        return (xf->size - (readindex - freeindex));
 }
 }
 
 
 int xfermem_getcmd (int fd, int block)
 int xfermem_getcmd (int fd, int block)
 {
 {
-        fd_set selfds;
-        byte cmd;
+    fd_set selfds;
+    byte cmd;
 
 
-        for (;;) {
-                struct timeval selto = {0, 0};
+    for (;;) {
+        struct timeval selto = {0, 0};
 
 
-                FD_ZERO (&selfds);
-                FD_SET (fd, &selfds);
-                /* #ifdef HPUX */ /* seems to trigger performance problems? strange */
+        FD_ZERO (&selfds);
+        FD_SET (fd, &selfds);
+        /* #ifdef HPUX */ /* seems to trigger performance problems? strange */
 #if 0
 #if 0
-                switch (select(FD_SETSIZE, (int *) &selfds, NULL, NULL, block ? NULL : &selto)) {
+        switch (select(FD_SETSIZE, (int *) &selfds, NULL, NULL, block ? NULL : &selto)) {
 #else
 #else
-                switch (select(FD_SETSIZE, &selfds, NULL, NULL, block ? NULL : &selto)) {
+        switch (select(FD_SETSIZE, &selfds, NULL, NULL, block ? NULL : &selto)) {
 #endif
 #endif
-                        case 0:
-                                if (!block)
-                                        return (0);
-                                continue;
+            case 0:
+                if (!block)
+                    return (0);
+                continue;
+            case -1:
+                if (errno == EINTR)
+                    continue;
+                return (-2);
+            case 1:
+                if (FD_ISSET(fd, &selfds))
+                    switch (read(fd, &cmd, 1)) {
+                        case 0: /* EOF */
+                            return (-1);
                         case -1:
                         case -1:
-                                if (errno == EINTR)
-                                        continue;
-                                return (-2);
+                            if (errno == EINTR)
+                                continue;
+                            return (-3);
                         case 1:
                         case 1:
-                                if (FD_ISSET(fd, &selfds))
-                                        switch (read(fd, &cmd, 1)) {
-                                                case 0: /* EOF */
-                                                        return (-1);
-                                                case -1:
-                                                        if (errno == EINTR)
-                                                                continue;
-                                                        return (-3);
-                                                case 1:
-                                                        return (cmd);
-                                                default: /* ?!? */
-                                                        return (-4);
-                                        }
-                                else /* ?!? */
-                                        return (-5);
+                            return (cmd);
                         default: /* ?!? */
                         default: /* ?!? */
-                                return (-6);
-                }
+                            return (-4);
+                    }
+                else /* ?!? */
+                    return (-5);
+            default: /* ?!? */
+                return (-6);
         }
         }
+    }
 }
 }
 
 
 int xfermem_putcmd (int fd, byte cmd)
 int xfermem_putcmd (int fd, byte cmd)
 {
 {
-        for (;;) {
-                switch (write(fd, &cmd, 1)) {
-                        case 1:
-                                return (1);
-                        case -1:
-                                if (errno != EINTR)
-                                        return (-1);
-                }
+    for (;;) {
+        switch (write(fd, &cmd, 1)) {
+            case 1:
+                return (1);
+            case -1:
+                if (errno != EINTR)
+                    return (-1);
         }
         }
+    }
 }
 }
 
 
 int xfermem_block (int readwrite, txfermem *xf)
 int xfermem_block (int readwrite, txfermem *xf)
 {
 {
-        int myfd = xf->fd[readwrite];
-        int result;
+    int myfd = xf->fd[readwrite];
+    int result;
 
 
-        xf->wakeme[readwrite] = TRUE;
-        if (xf->wakeme[1 - readwrite])
-                xfermem_putcmd (myfd, XF_CMD_WAKEUP);
-        result = xfermem_getcmd(myfd, TRUE);
-        xf->wakeme[readwrite] = FALSE;
-        return ((result <= 0) ? -1 : result);
+    xf->wakeme[readwrite] = TRUE;
+    if (xf->wakeme[1 - readwrite])
+        xfermem_putcmd (myfd, XF_CMD_WAKEUP);
+    result = xfermem_getcmd(myfd, TRUE);
+    xf->wakeme[readwrite] = FALSE;
+    return ((result <= 0) ? -1 : result);
 }
 }
 
 
 #elif defined(WIN32)
 #elif defined(WIN32)

+ 21 - 24
panda/src/mpg123/xfermem.h

@@ -1,20 +1,17 @@
-/* Filename: xfermem.h
- * Created by:  
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PANDA 3D SOFTWARE
- * Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
- *
- * All use of this software is subject to the terms of the Panda 3d
- * Software license.  You should have received a copy of this license
- * along with this source code; you will also find a current copy of
- * the license at http://www.panda3d.org/license.txt .
+/*
+ *   xfermem.h
  *
  *
- * To contact the maintainers of this program write to
- * [email protected] .
+ *   Oliver Fromme  <[email protected]>
+ *   Sat Mar 29 04:41:34 MET 1997
  *
  *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+ *   This is a stand-alone module which implements a unidirectional,
+ *   fast pipe using mmap().  Its primary use is to transfer large
+ *   amounts of data from a parent process to its child process,
+ *   with a buffer in between which decouples blocking conditions
+ *   on both sides.  Control information is transferred between the
+ *   processes through a socketpair.  See xftest.c for an example on
+ *   how to use this module.
+ */
 
 
 #ifndef TRUE
 #ifndef TRUE
 #define FALSE 0
 #define FALSE 0
@@ -22,15 +19,15 @@
 #endif
 #endif
 
 
 typedef struct {
 typedef struct {
-        int freeindex;  /* [W] next free index */
-        int readindex;  /* [R] next index to read */
-        int fd[2];
-        int wakeme[2];
-        byte *data;
-        byte *metadata;
-        int size;
-        int metasize;
-        int buf[3];
+    int freeindex;  /* [W] next free index */
+    int readindex;  /* [R] next index to read */
+    int fd[2];
+    int wakeme[2];
+    byte *data;
+    byte *metadata;
+    int size;
+    int metasize;
+    int buf[3];
 } txfermem;
 } txfermem;
 /*
 /*
  *   [W] -- May be written to by the writing process only!
  *   [W] -- May be written to by the writing process only!