C# - NAudio - How to convert a float[] to ISampleProvider?

Viewed 57

I'm coding my first audio application, and I'm struggling for hours on trying to convert a buffer in float[] format to ISampleProvider. I need this for further gluing together several pieces of audio. How do I do this? Code:

    float dt;//= 1f / nSamplesPerSec;
    int nChannels = 1;
    int duration = 30;
    int nSamplesPerChannel;//= nSamplesPerSec * duration / 1000;
    float[] buffer;

    void CreateBuffer()
    {
        dt = 1f / nSamplesPerSec;
        nSamplesPerChannel = nSamplesPerSec * duration / 1000;
        d = nSamplesPerChannel * dt;
        buffer = new float[nSamplesPerChannel];

        float f = 800;//frequency
        generate(f, 0);
    }

    void generate(float f, float p)
    {
        double koef = 0.22;
        int newSamples = (int)(nSamplesPerChannel * koef);

        for (int i = 0; i < nSamplesPerChannel; i++)
        {
            double AmpRamp = 1.0D;
            buffer[i] = (float)(AmpRamp*Math.Sin(2 * Math.PI * (f * dt * i + p)));
        }
    }
0 Answers
Related