我正在尝试使用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()上出现错误。说“对象引用未设置为对象的实例”

有任何想法吗?谢谢。

最佳答案

如果在CSCore源代码中四处浏览,您会发现ToWaveSource最终克隆了SampleProvider的WaveFormat-您尚未定义它。您可能只是从上游源返回WaveFormat:

public WaveFormat WaveFormat { get { return _source.WaveFormat; } }

关于audio - 在cscore中编辑单个样本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33619445/

10-09 18:24