diff options
Diffstat (limited to 'src/plugins/Output/waveout')
| -rw-r--r-- | src/plugins/Output/waveout/outputwaveout.cpp | 107 | ||||
| -rw-r--r-- | src/plugins/Output/waveout/outputwaveout.h | 10 | ||||
| -rw-r--r-- | src/plugins/Output/waveout/outputwaveoutfactory.cpp | 2 | ||||
| -rw-r--r-- | src/plugins/Output/waveout/outputwaveoutfactory.h | 10 |
4 files changed, 71 insertions, 58 deletions
diff --git a/src/plugins/Output/waveout/outputwaveout.cpp b/src/plugins/Output/waveout/outputwaveout.cpp index f95100aac..57b70b7e3 100644 --- a/src/plugins/Output/waveout/outputwaveout.cpp +++ b/src/plugins/Output/waveout/outputwaveout.cpp @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2009 by Ilya Kotov *
+ * Copyright (C) 2009-2012 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -31,19 +31,19 @@ #include <qmmp/visual.h>
#include "outputwaveout.h"
-#define MAX_WAVEBLOCKS 32
+#define MAX_WAVEBLOCKS 256
static CRITICAL_SECTION cs;
static HWAVEOUT dev = NULL;
-static int ScheduledBlocks = 0;
+static unsigned int ScheduledBlocks = 0;
static int PlayedWaveHeadersCount = 0; // free index
static WAVEHDR* PlayedWaveHeaders [MAX_WAVEBLOCKS];
-static void CALLBACK wave_callback (HWAVE hWave, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 )
+static void CALLBACK wave_callback (HWAVE hWave, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
{
- if ( uMsg == WOM_DONE )
+ if (uMsg == WOM_DONE)
{
EnterCriticalSection (&cs);
PlayedWaveHeaders [PlayedWaveHeadersCount++] = (WAVEHDR*) dwParam1;
@@ -52,38 +52,28 @@ static void CALLBACK wave_callback (HWAVE hWave, UINT uMsg, DWORD dwInstance, DW }
static void
-free_memory ( void )
+free_memory (void)
{
WAVEHDR* wh;
HGLOBAL hg;
- EnterCriticalSection ( &cs );
+ EnterCriticalSection (&cs);
wh = PlayedWaveHeaders [--PlayedWaveHeadersCount];
ScheduledBlocks--; // decrease the number of USED blocks
- LeaveCriticalSection ( &cs );
+ LeaveCriticalSection (&cs);
- waveOutUnprepareHeader ( dev, wh, sizeof (WAVEHDR) );
+ waveOutUnprepareHeader (dev, wh, sizeof (WAVEHDR));
- hg = GlobalHandle ( wh -> lpData ); // Deallocate the buffer memory
+ hg = GlobalHandle (wh -> lpData); // Deallocate the buffer memory
GlobalUnlock (hg);
GlobalFree (hg);
- hg = GlobalHandle ( wh ); // Deallocate the header memory
+ hg = GlobalHandle (wh); // Deallocate the header memory
GlobalUnlock (hg);
GlobalFree (hg);
}
-static int
-Box ( const char* msg )
-{
- //MessageBox ( NULL, ms"Error Message . . .", MB_OK | MB_ICONEXCLAMATION );
- return -1;
-}
-
-
-
-OutputWaveOut::OutputWaveOut(QObject * parent)
- : Output(parent)
+OutputWaveOut::OutputWaveOut(QObject * parent) : Output(parent)
{
//m_connection = 0;
//m_dev = 0;
@@ -139,7 +129,7 @@ bool OutputWaveOut::initialize(quint32 freq, int chan, Qmmp::AudioFormat format) }
waveOutReset (dev);
- InitializeCriticalSection ( &cs );
+ InitializeCriticalSection (&cs);
configure(freq, chan, format);
return true;
@@ -159,60 +149,88 @@ qint64 OutputWaveOut::writeAudio(unsigned char *data, qint64 len) void* allocptr;
len = qMin(len, (qint64)1024);
- do
- {
- while ( PlayedWaveHeadersCount > 0 ) // free used blocks ...
- free_memory ();
-
- if ( ScheduledBlocks < sizeof(PlayedWaveHeaders)/sizeof(*PlayedWaveHeaders) ) // wait for a free block ...
- break;
- usleep (500);
+
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
+ free_memory ();
+ if (ScheduledBlocks >= sizeof(PlayedWaveHeaders)/sizeof(*PlayedWaveHeaders)) // wait for a free block ...
+ {
+ usleep(500);
+ return 0;
+ }
+
+ if ((hg2 = GlobalAlloc (GMEM_MOVEABLE, len)) == NULL) // allocate some memory for a copy of the buffer
+ {
+ qWarning("OutputWaveOut: GlobalAlloc failed");
+ return 0;
}
- while (1);
-
- if ( (hg2 = GlobalAlloc ( GMEM_MOVEABLE, len )) == NULL ) // allocate some memory for a copy of the buffer
- return Box ( "GlobalAlloc failed." );
allocptr = GlobalLock (hg2);
- CopyMemory ( allocptr, data, len ); // Here we can call any modification output functions we want....
+ CopyMemory (allocptr, data, len); // Here we can call any modification output functions we want....
- if ( (hg = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof (WAVEHDR))) == NULL ) // now make a header and WRITE IT!
+ if ((hg = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof (WAVEHDR))) == NULL) // now make a header and WRITE IT!
return -1;
wh = (wavehdr_tag*)GlobalLock (hg);
wh->dwBufferLength = len;
wh->lpData = (CHAR *)allocptr;
- if ( waveOutPrepareHeader ( dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR )
+ if (waveOutPrepareHeader (dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR)
{
GlobalUnlock (hg);
GlobalFree (hg);
return -1;
}
- if ( waveOutWrite ( dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR )
+ if (waveOutWrite (dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR)
{
GlobalUnlock (hg);
GlobalFree (hg);
return -1;
}
- EnterCriticalSection ( &cs );
+ EnterCriticalSection (&cs);
ScheduledBlocks++;
- LeaveCriticalSection ( &cs );
+ LeaveCriticalSection (&cs);
return len;
}
+void OutputWaveOut::drain()
+{
+ while (ScheduledBlocks > 0)
+ {
+ Sleep(ScheduledBlocks);
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
+ free_memory();
+ }
+}
+
+void OutputWaveOut::suspend()
+{
+ waveOutPause(dev);
+}
+
+void OutputWaveOut::resume()
+{
+ waveOutRestart(dev);
+}
+
+void OutputWaveOut::reset()
+{
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
+ free_memory ();
+ waveOutReset (dev);
+}
+
void OutputWaveOut::uninitialize()
{
if (dev)
{
- while ( ScheduledBlocks > 0 )
+ while (ScheduledBlocks > 0)
{
Sleep (ScheduledBlocks);
- while ( PlayedWaveHeadersCount > 0 ) // free used blocks ...
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
free_memory ();
}
@@ -221,8 +239,7 @@ void OutputWaveOut::uninitialize() dev = 0;
}
- DeleteCriticalSection ( &cs );
+ DeleteCriticalSection (&cs);
ScheduledBlocks = 0;
return;
}
-
diff --git a/src/plugins/Output/waveout/outputwaveout.h b/src/plugins/Output/waveout/outputwaveout.h index 2d019ef6e..0fc5746b1 100644 --- a/src/plugins/Output/waveout/outputwaveout.h +++ b/src/plugins/Output/waveout/outputwaveout.h @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2009 by Ilya Kotov *
+ * Copyright (C) 2009-2012 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -42,10 +42,10 @@ public: private:
//output api
qint64 writeAudio(unsigned char *data, qint64 size);
- void drain(){};
- void suspend(){};
- void resume(){};
- void reset(){};
+ void drain();
+ void suspend();
+ void resume();
+ void reset();
// helper functions
void status();
diff --git a/src/plugins/Output/waveout/outputwaveoutfactory.cpp b/src/plugins/Output/waveout/outputwaveoutfactory.cpp index d3d1776f9..38c7a0a67 100644 --- a/src/plugins/Output/waveout/outputwaveoutfactory.cpp +++ b/src/plugins/Output/waveout/outputwaveoutfactory.cpp @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2009 by Ilya Kotov *
+ * Copyright (C) 2009-2012 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
diff --git a/src/plugins/Output/waveout/outputwaveoutfactory.h b/src/plugins/Output/waveout/outputwaveoutfactory.h index 6a59edbf4..ac43dfcbf 100644 --- a/src/plugins/Output/waveout/outputwaveoutfactory.h +++ b/src/plugins/Output/waveout/outputwaveoutfactory.h @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2009 by Ilya Kotov *
+ * Copyright (C) 2009-2012 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -20,21 +20,18 @@ #ifndef OUTPUTPULSEAUDIOFACTORY_H
#define OUTPUTPULSEAUDIOFACTORY_H
-
#include <QObject>
#include <QString>
#include <QIODevice>
#include <QWidget>
-
#include <qmmp/output.h>
#include <qmmp/outputfactory.h>
-class OutputWaveOutFactory : public QObject,
- OutputFactory
+class OutputWaveOutFactory : public QObject, OutputFactory
{
Q_OBJECT
-Q_INTERFACES(OutputFactory);
+Q_INTERFACES(OutputFactory)
public:
const OutputProperties properties() const;
@@ -43,7 +40,6 @@ public: void showSettings(QWidget* parent);
void showAbout(QWidget *parent);
QTranslator *createTranslator(QObject *parent);
-
};
#endif
|
