This project has moved and is read-only. For the latest updates, please go here.

Audiometer in Asio input

Jan 5 at 10:38 AM
Hello
in my callback procedure for a the asio input I can not use the audiometer. there will be a com exception message that this function is not supported. I used the code from asio example:

I used for test explicitlly values for recordChannelCount and NAudio.Wave.AsioOut
               //int recordChannelCount = GetUserSpecifiedChannelCount();
                int recordChannelCount = 1;

                // create device if necessary
                if (this.asioOut == null)
                {
                    //this.asioOut = new NAudio.Wave.AsioOut(comboBoxAsioDevice.Text); 
                    this.asioOut = new NAudio.Wave.AsioOut(0);

                    //this.asioOut.InputChannelOffset = GetUserSpecifiedChannelOffset();
                    this.asioOut.InputChannelOffset = 1;
                    this.asioOut.InitRecordAndPlayback(null, recordChannelCount, 44100);
                    this.asioOut.AudioAvailable += asioOut_AudioAvailable;
                }

                this.fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".wav");
                this.writer = new WaveFileWriter(fileName, new WaveFormat(44100, recordChannelCount));
                this.asioOut.Play();
                this.timer1.Enabled = true;

and the callback function:


void asioOut_AudioAvailable(object sender, AsioAudioAvailableEventArgs e)
        {
            var samples = e.GetAsInterleavedSamples();
            writer.WriteSamples(samples, 0, samples.Length);


            // bwp.AddSamples(e.Buffer, 0, e.BytesRecorded);
            double duckWert = (double)Convert.ToDouble(globalRightVolume) * (double)((double)Convert.ToInt32(Program.myRemoteArranger.myConfigVerwaltung.duckReduktion) / 100);
            var device = (NAudio.CoreAudioApi.MMDevice)Program.myRemoteArranger.myConfigVerwaltung.comboBox1.SelectedItem;
            //int wert = (int)(Math.Round(device.AudioMeterInformation.MasterPeakValue * 1000));
            int wert = (int)(Math.Round(device.AudioMeterInformation.MasterPeakValue * 2000));
//.........
}
the callback procedure crashes at the last line with:
_Das COM-Objekt des Typs "System._ComObject" kann nicht in den Schnittstellentyp "NAudio.CoreAudioApi.Interfaces.IMMDevice" umgewandelt werden. Dieser Vorgang konnte nicht durchgeführt werden, da der QueryInterface-Aufruf an die COM-Komponente für die Schnittstelle mit der IID "{D666063F-1587-4E43-81F1-B948E807363F}" aufgrund des folgenden Fehlers nicht durchgeführt werden konnte: Schnittstelle nicht unterstützt (Ausnahme von HRESULT: 0x80004002 (E_NOINTERFACE)).

Could someone help me? Thank you very much.
Thom