--- mpg123-0.59r/common.c.orig Tue Jun 15 23:24:19 1999 +++ mpg123-0.59r/common.c Fri Apr 20 11:17:50 2001 @@ -44,6 +44,8 @@ unsigned char *pcm_sample; int pcm_point = 0; int audiobufsize = AUDIOBUFSIZE; +int peaksample = 0; +int newpeaksample = 0; #ifdef VARMODESUPPORT /* @@ -502,6 +504,15 @@ fprintf(stderr,"Title : %-30s Artist: %s\n",title,artist); fprintf(stderr,"Album : %-30s Year : %4s\n",album,year); fprintf(stderr,"Comment: %-30s Genre : %s\n",comment,genre); + + if (!strncmp ("Peak sample: ", comment, 13)) + { + peaksample = strtol (comment + 13, NULL, 0); + } + else + { + peaksample = 0; + } } #if 0 --- mpg123-0.59r/mpg123.c.orig Tue Jun 15 22:21:36 1999 +++ mpg123-0.59r/mpg123.c Fri Apr 20 12:27:42 2001 @@ -44,7 +44,7 @@ FALSE , /* remote */ DECODE_AUDIO , /* write samples to audio device */ FALSE , /* silent operation */ - 0 , /* second level buffer size */ + 100 , /* second level buffer size */ TRUE , /* resync after stream error */ 0 , /* verbose level */ #ifdef TERM_CONTROL @@ -61,6 +61,8 @@ 0 , /* force_reopen, always (re)opens audio device for next song */ FALSE, /* try to run process in 'realtime mode' */ { 0,}, /* wav,cdr,au Filename */ + 0 , + 0 , }; char *listname = NULL; @@ -527,6 +529,8 @@ {0, "au", GLO_ARG | GLO_CHAR, set_au, 0 , 0 }, {'?', "help", 0, usage, 0, 0 }, {0 , "longhelp" , 0, long_usage, 0, 0 }, + {'N', "normalize", 0, 0, ¶m.normalize, TRUE }, + {'M', "magic", 0, 0, ¶m.magic, TRUE }, {0, 0, 0, 0, 0, 0} }; @@ -696,6 +700,28 @@ #ifndef NOXFERMEM if (param.usebuffer) { + if (param.magic) + { + int cntr = 0; + short sample; + while (cntr < pcm_point) + { + sample = ((short *) pcm_sample)[cntr / 2]; + if (sample > newpeaksample) newpeaksample = sample; + if (-sample > newpeaksample) newpeaksample = -sample; + cntr += 2; + } + } + if (param.normalize && peaksample && peaksample < 0x7f00) + { + int cntr = 0; + float gain = 1.0 * 0x7fff / peaksample; + while (cntr < pcm_point) + { + ((short *) pcm_sample)[cntr / 2] *= gain; + cntr += 2; + } + } if (!intflag) { buffermem->freeindex = (buffermem->freeindex + pcm_point) % buffermem->size; @@ -1027,6 +1053,10 @@ int secs = get_songlen(&fr,frameNum); fprintf(stderr,"\n[%d:%02d] Decoding of %s finished.\n", secs / 60, secs % 60, filename); + if (param.magic) + { + fprintf (stderr, "Peak sample: 0x%4.4x\n", newpeaksample); + } } rd->close(rd); @@ -1115,7 +1145,7 @@ fprintf(stderr," -w write Output as WAV file\n"); fprintf(stderr," -k n skip first n frames [0] -n n decode only n frames [all]\n"); fprintf(stderr," -c check range violations -y DISABLE resync on errors\n"); - fprintf(stderr," -b n output buffer: n Kbytes [0] -f n change scalefactor [32768]\n"); + fprintf(stderr," -b n output buffer: n Kbytes [100] -f n change scalefactor [32768]\n"); fprintf(stderr," -r n set/force samplerate [auto] -g n set audio hardware output gain\n"); fprintf(stderr," -os,-ol,-oh output to built-in speaker,line-out connector,headphones\n"); #ifdef NAS @@ -1136,7 +1166,8 @@ #endif fprintf(stderr," -z shuffle play (with wildcards) -Z random play\n"); fprintf(stderr," -u a HTTP authentication string -E f Equalizer, data from file\n"); - fprintf(stderr," -C enable control keys\n"); + fprintf(stderr," -C enable control keys -N Normalize\n"); + fprintf(stderr," -M Create magic cookie\n"); fprintf(stderr,"See the manpage %s(1) or call %s with --longhelp for more information.\n", prgName,prgName); exit(1); } @@ -1194,6 +1225,8 @@ fprintf(o," -w --wav Writes samples as WAV file in (- is stdout)\n"); fprintf(o," --au Writes samples as Sun AU file in (- is stdout)\n"); fprintf(o," --cdr Writes samples as CDR file in (- is stdout)\n"); + fprintf(o," -N --normalize Normalize output (magic cookie in comment field)\n"); + fprintf(o," -C --cookie Generate cookie and print it to stderr\n"); fprintf(o,"\nSee the manpage %s(1) for more information.\n", prgName); exit(0); --- mpg123-0.59r/mpg123.h.orig Fri May 28 16:51:58 1999 +++ mpg123-0.59r/mpg123.h Fri Apr 20 11:17:50 2001 @@ -147,6 +147,8 @@ int force_reopen; long realtime; char filename[256]; + int normalize; + int magic; }; struct reader { @@ -217,6 +219,8 @@ extern unsigned char *pcm_sample; extern int pcm_point; extern int audiobufsize; +extern int peaksample; +extern int newpeaksample; extern int OutputDescriptor; --- mpg123-0.59r/readers.c.orig Thu Mar 4 12:03:49 1999 +++ mpg123-0.59r/readers.c Fri Apr 20 11:17:50 2001 @@ -480,6 +480,8 @@ } } + peaksample = 0; + newpeaksample = 0; if(rd && rd->flags & READER_ID3TAG) { print_id3_tag(rd->id3buf); }