diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2017-04-18 19:56:55 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2017-04-18 19:56:55 +0000 |
| commit | e7b06c4b734a9978243751e3f44afa8b2faa21ff (patch) | |
| tree | a8407988e15eead05101bd0112f62bb4073f89cc /src/plugins/Output | |
| parent | fcd41290acbb1582f4e463ecaca868e52ec00bfb (diff) | |
| download | qmmp-e7b06c4b734a9978243751e3f44afa8b2faa21ff.tar.gz qmmp-e7b06c4b734a9978243751e3f44afa8b2faa21ff.tar.bz2 qmmp-e7b06c4b734a9978243751e3f44afa8b2faa21ff.zip | |
implemented latency() function for DirectSound and WavOut output plugins
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@7123 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Output')
8 files changed, 33 insertions, 13 deletions
diff --git a/src/plugins/Output/directsound/outputdirectsound.cpp b/src/plugins/Output/directsound/outputdirectsound.cpp index bd9281ca3..2d84ad5ba 100644 --- a/src/plugins/Output/directsound/outputdirectsound.cpp +++ b/src/plugins/Output/directsound/outputdirectsound.cpp @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2014-2016 by Ilya Kotov *
+ * Copyright (C) 2014-2017 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -50,6 +50,8 @@ OutputDirectSound::OutputDirectSound() : Output() m_primaryBuffer = 0;
m_dsBuffer = 0;
m_dsBufferAt = 0;
+ m_latency = 0;
+ m_bytesPerSecond = 0;
instance = this;
}
@@ -61,8 +63,10 @@ OutputDirectSound::~OutputDirectSound() bool OutputDirectSound::initialize(quint32 freq, ChannelMap map, Qmmp::AudioFormat format)
{
+ m_latency = 0;
DSBUFFERDESC bufferDesc;
+
HRESULT result = DirectSoundCreate8(0, &m_ds, 0);
if(result != DS_OK)
{
@@ -178,13 +182,14 @@ bool OutputDirectSound::initialize(quint32 freq, ChannelMap map, Qmmp::AudioForm configure(freq, out_map, format);
if(volumeControl)
volumeControl->restore();
+ m_bytesPerSecond = (sampleRate() * sampleSize() * channels());
return true;
}
qint64 OutputDirectSound::latency()
{
- return 0;
+ return m_latency;
}
qint64 OutputDirectSound::writeAudio(unsigned char *data, qint64 len)
@@ -193,6 +198,7 @@ qint64 OutputDirectSound::writeAudio(unsigned char *data, qint64 len) DWORD size = 0, size2 = 0;
DWORD available = bytesToWrite(); //available bytes
+ m_latency = (DS_BUFSIZE - available) * 1000 / m_bytesPerSecond;
if(available < 128)
{
usleep(5000);
diff --git a/src/plugins/Output/directsound/outputdirectsound.h b/src/plugins/Output/directsound/outputdirectsound.h index 46d2a0b21..295073a18 100644 --- a/src/plugins/Output/directsound/outputdirectsound.h +++ b/src/plugins/Output/directsound/outputdirectsound.h @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2014-2016 by Ilya Kotov *
+ * Copyright (C) 2014-2017 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -74,6 +74,8 @@ private: } DSoundChannels;
static DSoundChannels m_dsound_pos[10];
+ qint64 m_latency;
+ qint32 m_bytesPerSecond;
};
/**
diff --git a/src/plugins/Output/directsound/outputdirectsoundfactory.cpp b/src/plugins/Output/directsound/outputdirectsoundfactory.cpp index d0287ad40..d62b45543 100644 --- a/src/plugins/Output/directsound/outputdirectsoundfactory.cpp +++ b/src/plugins/Output/directsound/outputdirectsoundfactory.cpp @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2014-2016 by Ilya Kotov *
+ * Copyright (C) 2014-2017 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
diff --git a/src/plugins/Output/directsound/outputdirectsoundfactory.h b/src/plugins/Output/directsound/outputdirectsoundfactory.h index c2e23b697..f244789ec 100644 --- a/src/plugins/Output/directsound/outputdirectsoundfactory.h +++ b/src/plugins/Output/directsound/outputdirectsoundfactory.h @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2014 by Ilya Kotov *
+ * Copyright (C) 2014-2017 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/outputwaveout.cpp b/src/plugins/Output/waveout/outputwaveout.cpp index 6b26608b1..7a8b24d4b 100644 --- a/src/plugins/Output/waveout/outputwaveout.cpp +++ b/src/plugins/Output/waveout/outputwaveout.cpp @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2009-2013 by Ilya Kotov *
+ * Copyright (C) 2009-2017 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -75,8 +75,8 @@ free_memory (void) OutputWaveOut::OutputWaveOut() : Output()
{
- //m_connection = 0;
- //m_dev = 0;
+ m_totalWritten = 0;
+ m_frameSize = 0;
}
OutputWaveOut::~OutputWaveOut()
@@ -87,6 +87,7 @@ OutputWaveOut::~OutputWaveOut() bool OutputWaveOut::initialize(quint32 freq, ChannelMap map, Qmmp::AudioFormat format)
{
Q_UNUSED(format);
+ m_totalWritten = 0;
if (!waveOutGetNumDevs ())
{
qWarning("OutputWaveOut: no audio device found");
@@ -132,14 +133,20 @@ bool OutputWaveOut::initialize(quint32 freq, ChannelMap map, Qmmp::AudioFormat f waveOutReset (dev);
InitializeCriticalSection (&cs);
configure(freq, map, Qmmp::PCM_S16LE);
-
+ m_frameSize = channels() * sampleSize();
return true;
}
qint64 OutputWaveOut::latency()
{
- return 0;
+ MMTIME mmtime;
+ mmtime.wType = TIME_SAMPLES;
+
+ if(waveOutGetPosition(dev, &mmtime, sizeof(MMTIME)) != MMSYSERR_NOERROR)
+ return 0;
+
+ return (m_totalWritten / m_frameSize - mmtime.u.sample) * 1000 / sampleRate();
}
qint64 OutputWaveOut::writeAudio(unsigned char *data, qint64 len)
@@ -194,6 +201,7 @@ qint64 OutputWaveOut::writeAudio(unsigned char *data, qint64 len) ScheduledBlocks++;
LeaveCriticalSection (&cs);
+ m_totalWritten += len;
return len;
}
@@ -220,6 +228,7 @@ void OutputWaveOut::reset() while (PlayedWaveHeadersCount > 0) // free used blocks ...
free_memory ();
waveOutReset (dev);
+ m_totalWritten = 0;
}
void OutputWaveOut::uninitialize()
@@ -239,6 +248,7 @@ void OutputWaveOut::uninitialize() }
DeleteCriticalSection (&cs);
+ m_totalWritten = 0;
return;
}
diff --git a/src/plugins/Output/waveout/outputwaveout.h b/src/plugins/Output/waveout/outputwaveout.h index 688d4ed45..18dbc7126 100644 --- a/src/plugins/Output/waveout/outputwaveout.h +++ b/src/plugins/Output/waveout/outputwaveout.h @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2009-2014 by Ilya Kotov *
+ * Copyright (C) 2009-2017 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
@@ -49,6 +49,8 @@ private: // helper functions
void status();
void uninitialize();
+ qint64 m_totalWritten;
+ qint32 m_frameSize;
};
class VolumeWaveOut : public Volume
diff --git a/src/plugins/Output/waveout/outputwaveoutfactory.cpp b/src/plugins/Output/waveout/outputwaveoutfactory.cpp index 102d9cc21..d3861a077 100644 --- a/src/plugins/Output/waveout/outputwaveoutfactory.cpp +++ b/src/plugins/Output/waveout/outputwaveoutfactory.cpp @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2009-2016 by Ilya Kotov *
+ * Copyright (C) 2009-2017 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 f7654dbe1..82d8529a6 100644 --- a/src/plugins/Output/waveout/outputwaveoutfactory.h +++ b/src/plugins/Output/waveout/outputwaveoutfactory.h @@ -1,5 +1,5 @@ /***************************************************************************
- * Copyright (C) 2009-2014 by Ilya Kotov *
+ * Copyright (C) 2009-2017 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* This program is free software; you can redistribute it and/or modify *
|
