2015-11-09 51 views
0

我試圖使用CScore獲取單個32位樣本。我至今是在cscore中編輯單個樣本

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(); 
    } 

和A類

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

如果您通過CSCore源碼進行搜索,您會發現ToWaveSource最終會克隆SampleProvider的WaveFormat--您尚未定義它。您可能只需從上游源返回WaveFormat:

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

Thanks!我非常親密,但我從來沒有想過這一點。 – dwebb