[Portaudio] calculating average and max peak - beginner confused

Peter Shaw unthoughted at googlemail.com
Sun Mar 18 05:36:49 EDT 2012


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>

> 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
>
> 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. What did i miss off the digital audio lecture back these
> days?
>
> Thanks a lot for taking the time to explain my fault.
>
> Peter
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://music.columbia.edu/pipermail/portaudio/attachments/20120318/1a7c2d4a/attachment.html>


More information about the Portaudio mailing list