Faster Refresh Rate of DataAvailable During Recording?

Jun 27, 2009 at 9:26 PM

I've been messing with the WaveInStream object and it's DavaAvailable event. Just for kicks, it draws the spectrum instead of saving it to a file. Once I did that, I realized that it only calls the DataAvailable method once a second (-ish). There doesn't seem to be a way to have it update more often. If it listens for a second, followed by my processing (right now just for displaying it's spectrum), then the delay is very obvious. Anyway to speed this up? Subclass? Subtle change to your API? Anything?

Coordinator
Jun 28, 2009 at 6:15 AM

Hi, I've been making some enhancements to recording recently that should get checked in soon. The idea is that the wave in device will not be opened until you call StartRecording, which will mean you are able to set the number of buffers (currently three) and the size of each buffer (currently 100ms in the WaveIn class, the WaveInStream is now obsolete and used a second I think).

Mark

Jun 28, 2009 at 8:07 AM

I found a quick fix, not sure if it's worth putting in the final project, but it works for my current needs. I changed the signature of the WaveInStream constructor from:

public WaveInStream(int deviceNumber, WaveFormat desiredFormat, System.Windows.Forms.Control callbackWindow)

to:

public WaveInStream(int deviceNumber, WaveFormat desiredFormat, System.Windows.Forms.Control callbackWindow, float SecondsToRecordBeforeCallback)

The new variabls ONLY apperance in your code is changing:

int bufferSize = desiredFormat.AverageBytesPerSecond;

to:

int bufferSize = (int)(desiredFormat.AverageBytesPerSecond * SecondsToRecordBeforeCallback);

I have to admit that it probably won't be an even division because it's rounding down (truncating the decimal completely). For Example: .1 seconds * AverageBytesPerSecond may actually return enough bytes for .099 seconds or something, but to my best understanding, it won't drop information.

Coordinator
Jun 29, 2009 at 8:15 AM

hi, your changes will work fine for your purposes. I have checked the new WaveIn class in, which also has a way of adjusting the buffer size.

Mark