Skip to content

Instantly share code, notes, and snippets.

@programmin1
Created November 2, 2019 05:57
Show Gist options
  • Save programmin1/c011dba09ac7d30f734926b074863167 to your computer and use it in GitHub Desktop.
Save programmin1/c011dba09ac7d30f734926b074863167 to your computer and use it in GitHub Desktop.
Some custom IWaveProvider... does not work
class MuLawConversionProvider : IWaveProvider
{
private SampleToWaveProvider16 _sourceBuffer;
private WaveFormat _theformat;
public MuLawConversionProvider(SampleToWaveProvider16 SrcBuffer, WaveFormat theformat)
{
_sourceBuffer = SrcBuffer;
_theformat = theformat;
}
public WaveFormat WaveFormat => throw new NotImplementedException();
public int Read(byte[] destinationBuffer, int offset, int readingCount)
{
// Source buffer has twice as many items as the output array.
var sizeOfPcmBuffer = readingCount * 2;
//Cannot convert _sourceBuffer to byte[]???:
_sourceBuffer = BufferHelpers.Ensure(_sourceBuffer, sizeOfPcmBuffer);
var sourceBytesRead = _sourceProvider.Read(_sourceBuffer, offset * 2, sizeOfPcmBuffer);
var samplesRead = sourceBytesRead / 2;
var outIndex = 0;
for (var n = 0; n < sizeOfPcmBuffer; n += 2)
{
destinationBuffer[outIndex++] = MuLawEncoder.LinearToMuLawSample(BitConverter.ToInt16(_sourceBuffer, offset + n));
}
return samplesRead * 2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment