tags:

views:

29

answers:

1

I am using naudio to generate pulse width modulated audio signals for controlling a pair of servo's. Currently I am using the WaveProvider32 class that Mark Heath wrote (http://mark-dot-net.blogspot.com/2009/10/playback-of-sine-wave-in-naudio.html) which implements the IWaveProvider interface. The sample rate is 44100

The audio signal is basically a block N wide where the first part of the signal all the values are high, and for the remainder of the block the values are low. Since the Read operation asks for more samples than the width of the block I just repeat the signal until I fill up the buffer. The problem I have is that the length of the buffer is not a multiple of the width of my signal block, so part of the last block is cut off which screws with the servo and makes it twitch. I realize I could do some code fanciness to keep track of it and offset the beginning of the next read, but I would be easier if I could set the number of values that WaveProvider had to provide at once so that I could make it a multiple (or maybe the exact width) of the signal block size.

Is that possible?

A: 

The amount of data requested by the Read function is determined by the IWaveOut implementation you choose, and the latency and number of buffers it is operating at. You would need to create an intermediate IWaveProvider that ensures that Read methods to the underlying provider always ask for the right number. Have a look at the BlockAlignReductionStream which I created for a similar issue.

Mark Heath