How to use NAudio to adjust audio wav file speed ?

Mar 29, 2011 at 9:27 AM

I'm trying to use the NAudio library to build a C# programm that allow me to control the play speed (x2, x0.5, ...).

No documentation is available for this topic (as for advanced audio functions).

I try to implement by miself the algorithm that can perform such a task but I still don't know the bases Properties to manipulate.

Can anyone help me with that (I'm using an instance of IWavePlayer and an instance of WaveChannel32 to play my wav files) ?

 

 

Coordinator
Mar 30, 2011 at 9:18 AM

NAudio has no built-in support for playback speed. You would need to implement the DSP yourself as an IWaveProvider, So for 2x you would read twice the bytes you were asked for from your source provider then run your speedup algorithm.

Mark

Mar 30, 2011 at 1:14 PM

Thanks, it was helpful :

Overriding the Read(buffer, offset, count) method of the WaveChannel32 Class that way resolves the problem :

public override int Read(byte[] buffer, int offset, int count)

{

//2X speed exemple

_resultRead = _inputStreamTab.Read(buffer, offset, count);

_resultRead += _inputStreamTab.Read(buffer, offset, count);

return resultRead;

}

 

Coordinator
Mar 31, 2011 at 8:13 AM

Read should not return a number higher than count. You should return count here if you want double-speed playback. Also, you still need to implement the 2x speed algorithm

Mark

Apr 5, 2011 at 2:49 PM

@SourceCodeSeeker: I've implemented exactly that (tempo changes) using NAudio and another open source library (SoundTouch).

Please see:

http://code.google.com/p/practicesharp/

http://www.codeproject.com/KB/audio-video/practice_sharp.aspx

 

Thanks,

Yuval