0

I am having problems with typing a wav file name and having nAudio accept it as StreamMixToDisk.

Public Sub SetupAudio()
    'Setup the Mixer
    mixer = New WaveMixerStream32()
    mixer.AutoStop = False

    If waveOutDevice Is Nothing Then
        'waveOutDevice = new AsioOut();

        waveOutDevice = New WaveOut(0, 300, False)

        waveOutDevice.Init(mixer)
        waveOutDevice.Play()
    End If
End Sub

Private Sub cmbRecordDirect_Click(sender As Object, e As EventArgs) Handles cmbRecord.Click
    Dim saveFileDialog As New SaveFileDialog()
    saveFileDialog.Title = "Select output file:"
    saveFileDialog.Filter = "WAV Files (*.wav)|*.wav"
    saveFileDialog.FileName = outputFilename

    If saveFileDialog.ShowDialog() = DialogResult.OK Then
        outputFilename = saveFileDialog.FileName
        mixer.StreamMixToDisk(outputFilename)
        mixer.StartStreamingToDisk()
        cmbRecordDirect.Enabled = False
        cmbStopDirect.Enabled = True
        cmbPauseDirect.Enabled = True
    End If
End Sub

The outputFilename is c:\test.wav but once it gets to the mixer.StreamMixToDisk(outputFilename) it has an error saying:

A first chance exception of type 'System.NullReferenceException'
Object reference not set to an instance of an object.

The C# code that was converted to VB.net above is this:

private void cmbRecordDirect_Click(object sender, EventArgs e)
    {
        SaveFileDialog saveFileDialog = new SaveFileDialog();
        saveFileDialog.Title = "Select output file:";
        saveFileDialog.Filter = "WAV Files (*.wav)|*.wav";
        saveFileDialog.FileName = outputFilename;
        if (saveFileDialog.ShowDialog() == DialogResult.OK)
        {
            outputFilename = saveFileDialog.FileName;
            mixer.StreamMixToDisk(outputFilename);
            mixer.StartStreamingToDisk();
            cmbRecordDirect.Enabled = false;
            cmbStopDirect.Enabled = true;
            cmbPauseDirect.Enabled = true;
        }
    }

What could be causing this error to happen?

StealthRT
  • 10,108
  • 40
  • 183
  • 342
  • 1
    Seems like `mixer` hasn't been instantiated anywhere and is therefore null. If `mixer` itself it not null then an object within the`StreamMixToDisk` method is. – keyboardP Apr 03 '13 at 18:13

1 Answers1

0

I was not calling the SetupAudio() in the form_load to start off the mixer.

StealthRT
  • 10,108
  • 40
  • 183
  • 342