This project has moved and is read-only. For the latest updates, please go here.

Possible fix to WaveformPainter? when resizing...

Dec 16, 2011 at 9:59 PM
Edited Dec 16, 2011 at 11:04 PM

I was having an issue with WaveformPainter throwing System.ArgumentOutOfRangeException when i resized my window (From bigger to smaller). I've been writting a VOIP server/client using naudio and nspeex and its working great, thanks for this great library!

To duplicate the exception you have to resize the control from big to small, and the amount audio displayed needs to be greater than what can be shown when its resized. If that makes sense, haha...

Anyway I added one line to the AddMax function...

the change

                if (insertPos < maxSamples)
                    samples[insertPos] = maxSample;

the function with change

        public void AddMax(float maxSample)
            if (maxSamples == 0)
                // sometimes when you minimise, max samples can be set to 0
            if (samples.Count <= maxSamples)
                if (insertPos < maxSamples)
                    samples[insertPos] = maxSample;
            insertPos %= maxSamples;

Now I dont get the exception and the WaveformPainter keeps painting normally after resizing the control. (From bigger to smaller)

Dec 16, 2011 at 10:49 PM

Are you  traing  to make  Volume meter to indicate Voice coming true


Dec 16, 2011 at 10:58 PM
Edited Dec 16, 2011 at 11:22 PM

I have both the VolumeMeter and WaveformPainter being utilized. I'm also using a BufferedWaveProvider to feed audio over the network. I'm also using WaveIn for capturing microphone audio along with showing its samples in a WaveformPainter also so you can see your TX modulation...anyway to give you a better idea of what i'm doing here is a youtube video, the client in the video is actually outdated and it looks a lot different but you can see the waveform and volume meters in action @ about 15 seconds...


NO, i'm not trying to detect voice with the volume meter.

Dec 16, 2011 at 11:24 PM

I'm pretty sure I fixed a WaveformPainter resize bug similar to this in the latest code a while back, but I'll try to reproduce and if I can, I'll see if I can your fix in.


Dec 27, 2011 at 12:20 AM
Edited Dec 27, 2011 at 2:08 AM

More info on what happened...(I am using your latest sources "e43c857bbbe2").

First, I was not using the "OnResize" event of my main window. So I was never "manually" calling waveformPainter.Invalidate().  I noticed by adding a call to waveformPainter.Invalidate(), in my OnWindowResize function, now the app will not have the crash as mentioned above without the fix applied. But some visual weirdness happens. After applying the fix above, the visual weirdness doesn't happen.

I'll try to throw a sample project together along with a video so show the problems I'm generating...will update this post in an hour or so ;)

Sample Project showing bug, (plays a mp3 or wav file, generating waveform and volumemeter)

Youtube video showing bug (unlisted)

Jan 3, 2012 at 2:39 PM

thanks, I've put your fix into the latest source code. That class could do with a proper cleanup in the future, as I still don't think it is thread safe, but this should at least sort out your issue