It's a fairly simple to convert an IWaveProvider to a WaveStream. An IWaveProvider is just a simplified WaveStream that doesn't support repositioning and has an unknown length. You can create an adapter like this:
public class WaveProviderToWaveStream : WaveStream
{
private readonly IWaveProvider source;
private long position;
public WaveProviderToWaveStream(IWaveProvider source)
{
this.source = source;
}
public override WaveFormat WaveFormat
{
get { return source.WaveFormat; }
}
/// <summary>
/// Don't know the real length of the source, just return a big number
/// </summary>
public override long Length
{
get { return Int32.MaxValue; }
}
public override long Position
{
get
{
// we'll just return the number of bytes read so far
return position;
}
set
{
// can't set position on the source
// n.b. could alternatively ignore this
throw new NotImplementedException();
}
}
public override int Read(byte[] buffer, int offset, int count)
{
int read = source.Read(buffer, offset, count);
position += read;
return read;
}
}
I've put some comments in about the Length and Position properties. What you need to do with them depends on whether the class you are passing this into attempts to make use of those properties or not.
Also, there is nothing stopping you creating your own version of WaveMixerStream32 that works on IWaveProvider. You could simplify things a lot since there would be no need to implement any repositioning logic in the mixer since you can't reposition any of your inputs.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…