public static WaveFormat MarshalFromPtr(IntPtr pointer)
{
WaveFormat waveFormat = (WaveFormat)Marshal.PtrToStructure(pointer, typeof(WaveFormat));
switch (waveFormat.Encoding)
{
case WaveFormatEncoding.Pcm:
// can't rely on extra size even being there for PCM so blank it to avoid reading
// corrupt data
waveFormat.extraSize = 0;
break;
case WaveFormatEncoding.Extensible:
waveFormat = (WaveFormatExtensible)Marshal.PtrToStructure(pointer, typeof(WaveFormatExtensible));
break;
case WaveFormatEncoding.Adpcm:
waveFormat = (AdpcmWaveFormat)Marshal.PtrToStructure(pointer, typeof(AdpcmWaveFormat));
break;
case WaveFormatEncoding.Gsm610:
waveFormat = (Gsm610WaveFormat)Marshal.PtrToStructure(pointer, typeof(Gsm610WaveFormat));
break;
default:
if (waveFormat.ExtraSize > 0)
{
waveFormat = (WaveFormatExtraData)Marshal.PtrToStructure(pointer, typeof(WaveFormatExtraData));
}
break;
}
return waveFormat;
}