How can I decode GSM 6.10 (Full-Rate) codec audio byte array on the fly in NAudio? Sources says that wave decoding is processed at one time and I can't process several bytes of wave (fix me if I'm wrong).
My situation is that I receive bytes array of GSM 6.10 audio from the server, array size can be specified, but how can i decode it and write to the device?
Edit:
What am I doing wrong? According to Mark's solution this should work but all I hear is distorted sounds:
WaveOut waveO = new WaveOut();
BufferedWaveProvider waveP = new BufferedWaveProvider(new WaveFormat(8000, 16, 1));
waveO.Init(waveP);
waveO.Play();
INetworkChatCodec cod = new Gsm610ChatCodec();
new Thread(delegate()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.nch.com.au/acm/8kgsm.wav");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream resStream = response.GetResponseStream())
{
if (resStream.CanRead)
{
byte[] buf = new byte[65];
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
byte[] decoded = cod.Decode(buf, 0, count);
waveP.AddSamples(decoded, 0, decoded.Length);
Thread.Sleep(50);
}
}
while (count > 0);
}
}
}).Start();