Fix sequence counter becoming invalid for end-of-speech frames.
Reset buffered frames count on encoding failure.

Previously we didn't do so but still discarded the buffer
the count belonged to. This means the encoder would
assume invalid buffered frame count when a previous
encoding run failed.
Calculate peak and max microphone level in the same loop.

Don't needlessly run through the frame twice.