Added constant.
Fix some arithmetic.

pmax should be initialized to 1 to avoid illegal log.  It never seems
to happen due to AGC, probably.
Use Math functions instead of what I had.
Actually look at the samples returned, instead of the entire buffer.
Don't do programmatic layout.