Reputation: 827
I want to resample audio byte array from 8Khz to 48Khz. The audio stream is obtained as a byte[]
from a network socket.
Reading Mark Heath's Blog about resampling using NAudio, I came across the following code
int outRate = 16000;
var inFile = @"test.mp3";
var outFile = @"test resampled WDL.wav";
using (var reader = new AudioFileReader(inFile))
{
var resampler = new WdlResamplingSampleProvider(reader, outRate);
WaveFileWriter.CreateWaveFile16(outFile, resampler);
}
But this code acts on a file stream (AudioFileReader
) rather than in memory data (byte[]
). How could I modify this code to up-sample my byte array?
Edit: Basically I want to up-sample the 8 KHz data obtained from a network peer to 48 KHz and play using WASAPI.
Upvotes: 3
Views: 3959
Reputation: 49482
Your input to the resampler could be a BufferedWaveProvider
or a RawSourceWaveStream
. You can't use CreateWaveFile16 to resample in real-time though. You'd need to read only the amount of audio you expect to be available and write it to the WAV file.
Upvotes: 2