aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2012-12-03 16:29:44 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2012-12-03 16:29:44 +0000
commitc042c10a3105ae5ac862c22d0598da1053b983bc (patch)
treef929bead0bac1c4a9764e5ab5ecfaff2b7627734
parentecda457355a88453f508dabd8eb7cf3903f4e2d3 (diff)
downloadqmmp-c042c10a3105ae5ac862c22d0598da1053b983bc.tar.gz
qmmp-c042c10a3105ae5ac862c22d0598da1053b983bc.tar.bz2
qmmp-c042c10a3105ae5ac862c22d0598da1053b983bc.zip
waveOut plugin: fixed delays
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3020 90c681e8-e032-0410-971d-27865f9a5e38
-rw-r--r--src/plugins/Output/waveout/outputwaveout.cpp25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/plugins/Output/waveout/outputwaveout.cpp b/src/plugins/Output/waveout/outputwaveout.cpp
index cf51611ba..f4deb58c0 100644
--- a/src/plugins/Output/waveout/outputwaveout.cpp
+++ b/src/plugins/Output/waveout/outputwaveout.cpp
@@ -35,7 +35,7 @@
static CRITICAL_SECTION cs;
static HWAVEOUT dev = NULL;
-static unsigned int ScheduledBlocks = 0;
+static unsigned int ScheduledBlocks = 0;
static int PlayedWaveHeadersCount = 0; // free index
static WAVEHDR* PlayedWaveHeaders [MAX_WAVEBLOCKS];
@@ -47,6 +47,7 @@ static void CALLBACK wave_callback (HWAVE hWave, UINT uMsg, DWORD dwInstance, DW
{
EnterCriticalSection (&cs);
PlayedWaveHeaders [PlayedWaveHeadersCount++] = (WAVEHDR*) dwParam1;
+ ScheduledBlocks--; // decrease the number of USED blocks
LeaveCriticalSection (&cs);
}
}
@@ -59,7 +60,6 @@ free_memory (void)
EnterCriticalSection (&cs);
wh = PlayedWaveHeaders [--PlayedWaveHeadersCount];
- ScheduledBlocks--; // decrease the number of USED blocks
LeaveCriticalSection (&cs);
waveOutUnprepareHeader (dev, wh, sizeof (WAVEHDR));
@@ -199,11 +199,9 @@ qint64 OutputWaveOut::writeAudio(unsigned char *data, qint64 len)
void OutputWaveOut::drain()
{
while (ScheduledBlocks > 0)
- {
- Sleep(ScheduledBlocks);
- while (PlayedWaveHeadersCount > 0) // free used blocks ...
- free_memory();
- }
+ Sleep(10);
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
+ free_memory();
}
void OutputWaveOut::suspend()
@@ -227,12 +225,12 @@ void OutputWaveOut::uninitialize()
{
if (dev)
{
- while (ScheduledBlocks > 0)
- {
- Sleep (ScheduledBlocks);
- while (PlayedWaveHeadersCount > 0) // free used blocks ...
- free_memory ();
- }
+ waveOutReset(dev); // reset the device
+ while (ScheduledBlocks > 0);
+ Sleep (10);
+
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
+ free_memory ();
waveOutReset (dev); // reset the device
waveOutClose (dev); // close the device
@@ -240,6 +238,5 @@ void OutputWaveOut::uninitialize()
}
DeleteCriticalSection (&cs);
- ScheduledBlocks = 0;
return;
}