MarkJoel60
MarkJoel60

Reputation: 557

Using Naudio to amplify Microphone Input

I have played with the Naudio examples, and am able to amplify a WAV file that is opened in using the "WaveFileStream" function. (Code Example: AudioPlaybackPanel) This works fine:

I add a variable declaration, so I can access the channel later:

    SampleChannel waveFromFile;

And in the existing function, I set it:

     private ISampleProvider CreateInputStream(string fileName)
      {
        ...
        this.fileWaveStream = plugin.CreateWaveStream(fileName);
        var waveChannel =  new SampleChannel(this.fileWaveStream, true);
        waveFromFile = waveChannel;
        ...
    }

Then I add an AMPLIFY button, and this works just as I expect:

    float ampFactor = 1.0f;
    private void ampButton_Click(object sender, EventArgs e)
    {
        ampFactor += 2;
        if (ampFactor >= 9.0f)
            ampFactor = 1.0f;
        waveFromFile.Volume = ampFactor;
    }

But how can I do this when the input is not a WAV file, but instead is a microphone?

If I am looking at the NAudio examples, and try to add this code to the "RecordingPanel" demo, and it is being ignored -- meaning I put the value in the Volume, but there is no change.

Is it possible to amplify the audio coming in from the microphone? And, if so, can someone show a sample code snippet? I've looked online, but I can't seem to find it.

Upvotes: 0

Views: 1607

Answers (1)

Mark Heath
Mark Heath

Reputation: 49482

To take advantage of SampleChannel's ability to modify samples, you'd actually need to pull the audio through the SampleChannel. To do that, you could put the recorded audio into a BufferedWaveProvider and then put that into SampleChannel. Then you'd need to make sure you pulled enough audio back out of the SampleChannel and into the WaveFileWriter so it doesn't fill up. You may also want to use a SampleToWaveProvider16 if you wanted a 16 bit WAV file.

Upvotes: 1

Related Questions