This project has moved. For the latest updates, please go here.

1.3 version support for Vista 64 bit

Apr 6, 2011 at 2:44 PM

Hi there, I had 1.2 version of naudio working in my vista 64 bit machine. Was having issues using waveout.stop(). Browsing thr the discussion board, assumed this was resolved in 1.3 version.

Got 1.3 now, but this is what I see at runtime, not even able to run sample demo project.

{"Could not load file or assembly 'NAudio, Version=1.3.8.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format."}

 

Coordinator
Apr 6, 2011 at 2:45 PM

you need to set the main executable to target x86

Mark

Apr 6, 2011 at 3:06 PM

Thanks much Mark for quick response. I tried with the sample code and it worked.

But again in my project, its still the same issue. Please help.

Coordinator
Apr 6, 2011 at 3:12 PM

have you set the target in your project?

Apr 6, 2011 at 4:14 PM

Thanks Mark, changing the traget to x86 works now. But still I see the same issue as in 1.2 with the waveout.stop().

if (this.waveOut != null && this.waveOut.PlaybackState != PlaybackState

.Stopped) {

 this.waveOut.Stop();

}

ContextSwtichDeadlock error

The CLR has been unable to transition from COM context 0x74bed0 to COM context 0x74c040 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

Coordinator
Apr 6, 2011 at 4:18 PM

what sort of application are you running (WinFroms, WPF, something else)? in what what way are you using COM? What callback mechanism are you using for WPF?

Mark

Apr 6, 2011 at 4:36 PM

Its a Winforms app, .net 3.5. not a WPF. This is what we are doing, suspecting something wrong with the flow of events.

  public void PlaySoundFile(string fileName)
        {
            this.StopPlayback();
            FileStream stream = new FileStream(fileName, FileMode.Open);
            PlaySoundFile(stream);
        }

 public void PlaySoundFile(Stream soundStream)
        {
            // Create object
            this.waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback());

            // Set volume
            if (this.playbackVolume != -1F)
            {
                this.waveOut.Volume = this.playbackVolume;
            }

            waveStream = new WaveFileReader(soundStream);
            waveChannel = new WaveChannel32(waveStream);
            this.waveOut.PlaybackStopped += new EventHandler(waveOut_PlaybackStopped);

            bool foundDevice = false;
            // Attempt to set correct device
            for (int i = 0; i < WaveOut.DeviceCount; i++)
            {
                if (WaveOut.GetCapabilities(i).ProductName.Contains(Settings.Default.AudioPlaybackDevice))
                {
                    // Set the device to playback audio on
                    waveOut.DeviceNumber = i;
                    foundDevice = true;
                    break;
                }
            }

            // Make sure we find the audio device
            if (!foundDevice)
            {
                CloseOutputFileAndDispose();
                throw new AudioDeviceNotFoundException(Settings.Default.AudioPlaybackDevice);
            }

            this.waveOut.Init(waveChannel);
            this.waveOut.Play();

        }

     public void StopPlayback()
        {
            if (this.waveOut != null
                && this.waveOut.PlaybackState != PlaybackState.Stopped)
            {
                try
                {
                    this.waveOut.Stop();
                    if (waveStream != null)
                    {
                        // this one really closes the file and ACM conversion
                        waveChannel.Close();
                        waveChannel = null;
                        // this one does the metering stream
                        waveStream.Close();
                        waveStream = null;
                    }

 
                    waveOut.Dispose();
                    waveOut = null;

                }

 

Coordinator
Apr 6, 2011 at 4:40 PM

Try using Window callbacks. Also, in your StopPlayback function, don't dispose of WaveOut yet - it's not necesarily finished doing stuff. Finally, what are you doing in waveOut_PlaybackStopped?

Apr 6, 2011 at 5:54 PM
Edited Apr 6, 2011 at 5:55 PM

 

What do you mean by window callbacks? On paybackstopped, we are cleaning up the wave out object.

 

void waveOut_PlaybackStopped(object sender, EventArgs e)

{

// Clean-up the wave out object

if (this.waveOut != null)

{

this.waveOut.Dispose();

this.waveOut = null;

 

}

}

 

 

 

Apr 8, 2011 at 5:47 AM

You are probably debugging in Visual studio?

see this post for a more deeply explanation: http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/8630a1bb-fc65-49e5-8b37-bf77378e380f/

I have had this several times when dealing with Directx, just configure VS not to react on this.

Coordinator
Apr 9, 2011 at 7:17 AM

try using WaveCallbackInfo.NewWindow() instead of function callbacks. Also, PlaybackStopped can be a dangerous place to call WaveOut.Dispose(), especially when using function callbacks.

Mark

NewWindowW