audiocscore

Edit individual samples in cscore


I'm trying to get at the individual 32bit samples using CScore. What I have so far is

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

And a 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; }
}

Which I thought would pass the audio through unchanged but I am getting an error on the sampleProvider.ToWaveSource(); saying "Object reference not set to an instance of an object"

Any ideas? Thanks.


Solution

  • If you poke around through the CSCore source you'll find that ToWaveSource ends up cloning the WaveFormat of your SampleProvider - which you've left undefined. You can probably just return the WaveFormat from the upstream source:

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