[Portaudio] calculating average and max peak - beginner confused

Frank Lichtner Frank at Lichtner.de
Sun Mar 18 05:47:06 EDT 2012


Hi Peter,

you need to rectify the value.

int max = 0;
// loop
if(abs(val) > max) {
     max = abs(val);
}
Regards

Frank

Am 18.03.2012 10:36, schrieb Peter Shaw:
> Hi,
> i found it... it was my previous problem that's already told. Frames vs. Bytes,
> so i changed my code to:
> for (i = 0; i < rawPipeInfo->numBytesOfBuffer; i++) {
> instead of:
> rawPipeInfo->framesPerBuffer
>
> So i got a various range of numbers now.
>
> In the examples i found a ABS calculating:
> if (val < 0) {
>      val = -val; /* ABS */
>  }
> on (http://portaudio.com/docs/v19-doxydocs/paex__record_8c_source.html)
> but shouldn't it be:
> val *= -val
> to turn around the sign?
>
> Best regards,
> Peter.
>
>
> 2012/3/18 Peter Shaw <unthoughted at googlemail.com <mailto:unthoughted at googlemail.com>>
>
>     Hi all,
>
>     i am trying to get the average and the max peak of a loop in the blocking-api in debug mode of
>     my application, but all i got is 0 or 2147483648 <tel:2147483648>
>
>     my code looks like this:
>
>         while (1) {
>             Pa_ReadStream(stream, buffer, rawPipeInfo->framesPerBuffer);
>             /* write buffer to pipe */
>             if (application_debug) {
>                 int i;
>                 int max = 0;
>                 int average = 0;
>                 for (i = 0; i < rawPipeInfo->framesPerBuffer; i++) {
>                     int val = buffer[i];
>                     printf("v:%d ", val);
>                     if (val < 0) {
>                         val *= -val; /* ABS */
>                     }
>                     if (val > max) {
>                         max = val;
>                     }
>                     average += val;
>                 }
>                 average = average / (double) rawPipeInfo->framesPerBuffer;
>                 char buf[50];
>                 sprintf(buf, "inputchain: average: %d max: %d\n", average, max);
>                 DEBUG(buf);
>             }
>     .. write to mp3-encoding buffer...
>     }
>
>     My result mp3 file is fine. Clear and nice sound, but my display shows only the two numbers?
>     shuldn't it return a wide range of numbers according to the audio waveform?
>     I run PA with .sampleFormat = paInt16; and .channelCount = 2;
>
>     K thought these is something wrong with my calculation, because it is very early here in
>     germany, but why is v:%d always 0 or 1,   eg: 0 or 2147483648 <tel:2147483648>. What did i
>     miss off the digital audio lecture back these days?
>
>     Thanks a lot for taking the time to explain my fault.
>
>     Peter
>
>
>
>
> _______________________________________________
> Portaudio mailing list
> Portaudio at music.columbia.edu
> http://music.columbia.edu/mailman/listinfo/portaudio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://music.columbia.edu/pipermail/portaudio/attachments/20120318/9bd494fa/attachment-0001.html>


More information about the Portaudio mailing list