在 cscore 中编辑单个样本
Edit individual samples in cscore
我正在尝试使用 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
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(); 上收到错误消息;说 "Object reference not set to an instance of an object"
有什么想法吗?谢谢
如果您浏览 CSCore 源代码,您会发现 ToWaveSource
最终克隆了您未定义的 SampleProvider 的 WaveFormat
。您可能只 return 来自上游源的 WaveFormat:
public WaveFormat WaveFormat { get { return _source.WaveFormat; } }
我正在尝试使用 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
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(); 上收到错误消息;说 "Object reference not set to an instance of an object"
有什么想法吗?谢谢
如果您浏览 CSCore 源代码,您会发现 ToWaveSource
最终克隆了您未定义的 SampleProvider 的 WaveFormat
。您可能只 return 来自上游源的 WaveFormat:
public WaveFormat WaveFormat { get { return _source.WaveFormat; } }