Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with waveOutWrite and waveOutGetPosition deadlock
    primarykey
    data
    text
    <p>I'm working on an app that plays audio continuously using the <code>waveOut...</code> API from <code>winmm.dll</code>. The app uses "leapfrog" buffers, which are basically a bunch of arrays of samples that you dump into the audio queue. Windows plays them seamlessly in sequence, and as each buffer completes Windows calls a callback function. Inside this function, I load the next set of samples into the buffer, process them however, and then dump the buffer back into the audio queue. In this way, the audio plays indefinitely.</p> <p>For animation purposes, I'm trying to incorporate <code>waveOutGetPosition</code> into the application (since the "buffer done" callbacks are irregular enough to cause jerky animation). <code>waveOutGetPosition</code> returns the current position of playback, so it's hyper-precise.</p> <p>The problem is that in my application, making calls to <code>waveOutGetPosition</code> eventually causes the application to lock up - the sound stops and the call never returns. I've boiled things down to a simple app that demonstrates the problem. You can run the app here:</p> <p><a href="http://www.musigenesis.com/SO/waveOut%20demo.exe" rel="nofollow noreferrer">http://www.musigenesis.com/SO/waveOut%20demo.exe</a></p> <p>If you just hear a tiny bit of piano over and over, it's working. It's just meant to demonstrate the problem. The source code for this project is here (all the meat is in LeapFrogPlayer.cs):</p> <p><a href="http://www.musigenesis.com/SO/WaveOutDemo.zip" rel="nofollow noreferrer">http://www.musigenesis.com/SO/WaveOutDemo.zip</a></p> <p>The first button runs the app in leapfrog mode without making the calls to <code>waveOutGetPosition</code>. If you click this, the app will play forever without breaking (the X button will close it and shut it off). The second button starts the leapfrogger and also starts a forms timer that calls the <code>waveOutGetPosition</code> and displays the current position. Click this and the app will run for a short while and then lock up. On my laptop, it usually locks up in 15-30 seconds; at most it's taken a minute.</p> <p>I have no idea how to fix this, so any help or suggestions would be most welcome. I've found very few posts on this issue, but it seems that there is a potential deadlock, either from multiple calls to <code>waveOutGetPosition</code> or from calls to that and <code>waveOutWrite</code> that occur at the same time. It's possible that I'm calling this too frequently for the system to handle.</p> <p><strong>Edit</strong>: forgot to mention, I'm running this on Windows Vista. This might not happen at all on other OSes.</p> <p><strong>Edit 2</strong>: I've found little about this problem online, except for these (unanswered) posts:</p> <p><a href="http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/c6a1e80e-4a18-47e7-af11-56a89f638ad7" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/c6a1e80e-4a18-47e7-af11-56a89f638ad7</a></p> <p><strong>Edit 3</strong>: Well, I'm now able to reproduce this problem at will. If I call <code>waveOutGetPosition</code> immediately after <code>waveOutWrite</code> (in the following line of code) the application hangs every time. It also hangs in an especially bad way - it seems to lock up my whole OS for awhile, not just the app itself. So it appears that <code>waveOutGetPosition</code> deadlocks if it occurs at <em>nearly</em> the same time as <code>waveOutWrite</code>, not just literally at the same time, which might explain why the locks aren't working for me. Yeesh.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload