我试图使用CScore获取单个32位样本。到目前为止我所拥有的是
public MainWindow()
{
InitializeComponent();
var wasapiCapture = new WasapiCapture();
wasapiCapture.Initialize();
wasapiCapture.Start();
var wasapiCaptureSource = new SoundInSource(wasapiCapture);
var stereoSource = wasapiCaptureSource.ToStereo();
var ieeeFloatToSample = new IeeeFloatToSample(stereoSource);
var sampleProvider = new SampleProvider(ieeeFloatToSample);
var wavesource = sampleProvider.ToWaveSource();
var wasapiOut = new WasapiOut();
wasapiOut.Initialize(wavesource);
wasapiOut.Play();
}
和一个班级
class SampleProvider : ISampleSource
{
private ISampleSource _source;
public SampleProvider(ISampleSource source)
{
this._source = source;
}
public int Read(float[] buffer, int offset, int count)
{
var sampleRead = _source.Read(buffer, 0, count);
return sampleRead;
}
public void Dispose()
{
throw new NotImplementedException();
}
public WaveFormat WaveFormat { get; private set; }
public long Position { get; set; }
public long Length { get; private set; }
}
我认为会传递音频不变,但我在sampleProvider.ToWaveSource()上收到错误;说"对象引用未设置为对象的实例"
有什么想法吗?感谢。
答案 0 :(得分:0)
如果您浏览CSCore源代码,您会发现ToWaveSource
最终克隆了您的SampleProvider的WaveFormat
- 您尚未定义。您可以从上游源返回WaveFormat:
public WaveFormat WaveFormat { get { return _source.WaveFormat; } }