From 24664700b3162bb67ff2e28a1de2505fb76c3e0b Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Tue, 2 Jan 2018 17:27:33 +0100 Subject: DirectShow: Fix crackling when playing custom sample rate Seems waveOutWrite() requires WAVEHDR->dwBufferLength to be even number otherwise some crackling might be heard while playing. And looks like it is not related to QAudioFormat, any of it produces the issue. Task-number: QTBUG-64931 Change-Id: I87dbe165611325d9c0291a3bffdc091397b42741 Reviewed-by: Maurice Kalinowski --- src/plugins/windowsaudio/qwindowsaudiooutput.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/plugins/windowsaudio') diff --git a/src/plugins/windowsaudio/qwindowsaudiooutput.cpp b/src/plugins/windowsaudio/qwindowsaudiooutput.cpp index eb4caf128..d1c0b475f 100644 --- a/src/plugins/windowsaudio/qwindowsaudiooutput.cpp +++ b/src/plugins/windowsaudio/qwindowsaudiooutput.cpp @@ -241,6 +241,10 @@ bool QWindowsAudioOutput::open() period_size = buffer_size / 5; } + // Make even size of wave block to prevent crackling + // due to waveOutWrite() does not like odd buffer length + period_size &= ~1; + if (period_size == 0) { errorState = QAudio::OpenError; deviceState = QAudio::StoppedState; -- cgit v1.2.1 From a0049de16d9e2a92b8d31b1ee6943c994ffdf7d2 Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Tue, 10 Oct 2017 13:24:27 +0200 Subject: Fix adjusting volume for default device Using WAVE_MAPPER device id (which points to default device) is not possible to get and initialize a mixer object to set volume. Function mixerGetID() does not support WAVE_MAPPER as a device id yet. Since we do not know device number anymore needs to call waveInOpen() first and after that initialize mixer controls using hWaveIn handler. - Fixed default volume from 0.0f -> 1.0f. - Before QWindowsAudioInput::start() is called, use cached volume. - After QWindowsAudioInput::start(), mixer controls are initialized. - QWindowsAudioInput::stop() deinitializes mixer controls. Task-number: QTBUG-61920 Change-Id: I5a94dad282618fb4a2e0f75c34008ca002bd1aeb Reviewed-by: Maurice Kalinowski --- src/plugins/windowsaudio/qwindowsaudioinput.cpp | 25 ++++++++++--------------- src/plugins/windowsaudio/qwindowsaudioinput.h | 1 + 2 files changed, 11 insertions(+), 15 deletions(-) (limited to 'src/plugins/windowsaudio') diff --git a/src/plugins/windowsaudio/qwindowsaudioinput.cpp b/src/plugins/windowsaudio/qwindowsaudioinput.cpp index 4771fe1cc..00b36cfe4 100644 --- a/src/plugins/windowsaudio/qwindowsaudioinput.cpp +++ b/src/plugins/windowsaudio/qwindowsaudioinput.cpp @@ -74,14 +74,13 @@ QWindowsAudioInput::QWindowsAudioInput(const QByteArray &device) waveBlockOffset = 0; mixerID = 0; + cachedVolume = 1.0f; memset(&mixerLineControls, 0, sizeof(mixerLineControls)); - initMixer(); } QWindowsAudioInput::~QWindowsAudioInput() { stop(); - closeMixer(); } void QT_WIN_CALLBACK QWindowsAudioInput::waveInProc( HWAVEIN hWaveIn, UINT uMsg, @@ -183,6 +182,7 @@ QAudio::State QWindowsAudioInput::state() const void QWindowsAudioInput::setVolume(qreal volume) { + cachedVolume = volume; for (DWORD i = 0; i < mixerLineControls.cControls; i++) { MIXERCONTROLDETAILS controlDetails; @@ -204,7 +204,6 @@ void QWindowsAudioInput::setVolume(qreal volume) qreal QWindowsAudioInput::volume() const { - DWORD volume = 0; for (DWORD i = 0; i < mixerLineControls.cControls; i++) { if ((mixerLineControls.pamxctrl[i].dwControlType != MIXERCONTROL_CONTROLTYPE_FADER) && (mixerLineControls.pamxctrl[i].dwControlType != MIXERCONTROL_CONTROLTYPE_VOLUME)) { @@ -226,11 +225,10 @@ qreal QWindowsAudioInput::volume() const continue; if (controlDetails.cbDetails < sizeof(MIXERCONTROLDETAILS_UNSIGNED)) continue; - volume = detailsUnsigned.dwValue; - break; + return detailsUnsigned.dwValue / 65535.0; } - return volume / 65535.0; + return cachedVolume; } void QWindowsAudioInput::setFormat(const QAudioFormat& fmt) @@ -378,6 +376,7 @@ bool QWindowsAudioInput::open() elapsedTimeOffset = 0; totalTimeValue = 0; errorState = QAudio::NoError; + initMixer(); return true; } @@ -396,6 +395,7 @@ void QWindowsAudioInput::close() mutex.unlock(); waveInClose(hWaveIn); + closeMixer(); int count = 0; while(!finished && count < 500) { @@ -406,17 +406,10 @@ void QWindowsAudioInput::close() void QWindowsAudioInput::initMixer() { - QDataStream ds(&m_device, QIODevice::ReadOnly); - quint32 inputDevice; - ds >> inputDevice; - - if (int(inputDevice) < 0) - return; - // Get the Mixer ID from the Sound Device ID UINT mixerIntID = 0; - if (mixerGetID(reinterpret_cast(quintptr(inputDevice)), - &mixerIntID, MIXER_OBJECTF_WAVEIN) != MMSYSERR_NOERROR) + if (mixerGetID(reinterpret_cast(hWaveIn), + &mixerIntID, MIXER_OBJECTF_HWAVEIN) != MMSYSERR_NOERROR) return; mixerID = reinterpret_cast(quintptr(mixerIntID)); @@ -436,6 +429,8 @@ void QWindowsAudioInput::initMixer() mixerLineControls.pamxctrl = new MIXERCONTROL[mixerLineControls.cControls]; if (mixerGetLineControls(mixerID, &mixerLineControls, MIXER_GETLINECONTROLSF_ALL) != MMSYSERR_NOERROR) closeMixer(); + else + setVolume(cachedVolume); } } diff --git a/src/plugins/windowsaudio/qwindowsaudioinput.h b/src/plugins/windowsaudio/qwindowsaudioinput.h index e61a50a89..a0feae257 100644 --- a/src/plugins/windowsaudio/qwindowsaudioinput.h +++ b/src/plugins/windowsaudio/qwindowsaudioinput.h @@ -147,6 +147,7 @@ private: void closeMixer(); HMIXEROBJ mixerID; MIXERLINECONTROLS mixerLineControls; + qreal cachedVolume; private slots: void feedback(); -- cgit v1.2.1