I got it working with the RawSourceWaveStream
but then tried to simply read the bytes of the file, decode using the G722 Codec and write the bytes out to a wave file. It worked.
private readonly G722CodecState _state = new G722CodecState(64000, G722Flags.SampleRate8000);
private readonly G722Codec _codec = new G722Codec();
private readonly WaveFormat _waveFormat = new WaveFormat(8000, 1);
public MainWindow()
{
InitializeComponent();
var data = File.ReadAllBytes(@"C:\Recordings\000-06Z_chunk00000.g722");
var output = Decode(data, 0, data.Length);
using (WaveFileWriter waveFileWriter = new WaveFileWriter(@"C:\Recordings\000-06Z_chunk00000.wav", _waveFormat))
{
waveFileWriter.Write(output, 0, output.Length);
}
}
private byte[] Decode(byte[] data, int offset, int length)
{
if (offset != 0)
{
throw new ArgumentException("G722 does not yet support non-zero offsets");
}
int decodedLength = length * 4;
var outputBuffer = new byte[decodedLength];
var wb = new WaveBuffer(outputBuffer);
int decoded = _codec.Decode(_state, wb.ShortBuffer, data, length);
return outputBuffer;
}