I am getting audio using the NAudio library which returns a 32 bit float[]
of audio data. I'm trying to find a way to convert this to a 16 bit byte[]
for playback.
private void sendData(float[] samples)
{
Buffer.BlockCopy(samples, 0, byteArray, 0, samples.Length);
byte[] encoded = codec.Encode(byteArray, 0, byteArray.Length);
waveProvider.AddSamples(byteArray, 0, byteArray.Length);
s.Send(encoded, SocketFlags.None);
}
The audio being sent to waveProvider
is coming out static-y — I don't think I'm converting correctly. How can I convert to a byte array of 16 bit samples?