From: David <[EMAIL PROTECTED]>

>This is an example of peak normalization (correct me if I am wrong)..
>
>We have a song in a (stereo 16bit)wavfile called mysong.wav
>
>we scan the wav files and find these values..(they are fake of course)
>
>MaxRightSample = 16000;
>MinRightSample = -8000;
>
>MaxLeftSample = 15876;
>MinLeftSample = -10000;
>
>
>We then choose the loudest sample from either side..
>
>LeftTotal = MaxLeftSample;
>
>if( abs(MinLeftSample) > MaxLeftSample)
>  LeftTotal = abs(MinLeftSample);
>
>RightTotal = MaxLeftSample;
>
>if( abs(MinRightSample) > MaxRightSample)
>  RightTotal = abs(MinRightSample);
>
> Now we calc the am factors
>
>Leftampfactor = (double)65535 / (double)LeftTotal ;
>Reftampfactor = (double)65535 / (double)RightTotal ;
>
>Now we go back through the wav file and multiply the ampfactor to all 
>the samples (left and right).

Uh , I would use the SAME factor for both channels. Otherwise one channel 
will be more apmilified than the other , like if someone turned the 
balance knob.

So :
maxValue = max(RightTotal,LeftTotal);
for(i=0;i<NR_SAMPLES;i++)
{
 sample_left[i] *= 32768/maxValue;
 sample_right[i] *= 32768/maxValue;   /* 32768 is correct , 65535 ; SHORT_MAX = 2^15 , 
one bit is the sign ! */
}


-- 
David Balazic , student
E-mail   : [EMAIL PROTECTED]     |     living in  sLOVEnija
home page: http://surf.to/stein
Computer: Amiga 1200 + Quantum LPS-340AT
--
--
MP3 ENCODER mailing list ( http://geek.rcc.se/mp3encoder/ )

Reply via email to