# [Portaudio] calculating average and max peak - beginner confused

Sun Mar 18 06:51:53 EDT 2012

```Hi Alan,

hm, maybe i miss something, but i abs my value in the ifclause while less
than 0.
so i summing positive integers only, or not?

if (val < 0) {
val = abs(val) ;
}
...
average += val;
or
average += abs(val);

but i also have to abs my average:
average = abs(average / (int) rawPipeInfo->numBytesOfBuffer);

but isn't it the rule that if i add positive only values that it can't be
negative deviding by any value? 1 / 1000000 is also grater than 0.

This is now very off topic of portaudio and more c basic or math basic, but
maybe it is also interesting for beginners or recommers from long term
java-nuts like me. :-)

Peter

2012/3/18 Alan Wolfe <alan.wolfe at gmail.com>

> Well checking out the code, the average is made by summing all the samples
> then dividing by the sample.  No abs is involved in that so the negative
> makes sense.
>
> I think that is probably the correct way to do it, but you could also abs
> val the average after It's calculated if you want.
>
> Not sure what is most correct mathematically
>
> On Mar 18, 2012 2:47 AM, "Peter Shaw" <unthoughted at googlemail.com> wrote:
>
> ok Alan,
> so: val = -val is the same as val = val *-1.
> ( i took a coffee and get my brain to work.)
>
> but why i got negative values in my average output, too?
>
> Peter
>
>
>
> 2012/3/18 Alan Wolfe <alan.wolfe at gmail.com>
> >
> > The abs looks right to me.  Just flips the sign if...
>
> _______________________________________________
> Portaudio mailing list
> Portaudio at music.columbia.edu
> http://music.columbia.edu/mailman/listinfo/portaudio
>
>
> _______________________________________________
> 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/90c0e37a/attachment.html>
```