diff options
author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2023-08-08 21:49:58 +0300 |
---|---|---|
committer | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2023-08-10 03:25:58 +0000 |
commit | 428cae98619584a51c01be135fecf6b347c117b3 (patch) | |
tree | bde8c2b5ad54a3f8040dba6ab72b0d2e06203e6f /src | |
parent | 226d94e94fcfafeca01b6c2cf903b6ee248a0da0 (diff) |
winrt: Fix artifact at the beginning of audio
The artifact was generated by the RIFF/WAV header that was passed into
the audio sink.
Pick-to: 6.6
Change-Id: I33133b069894fecf506eb67c4877306f9d4109b1
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/tts/winrt/qtexttospeech_winrt_audiosource.cpp | 13 | ||||
-rw-r--r-- | src/plugins/tts/winrt/qtexttospeech_winrt_audiosource.h | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/plugins/tts/winrt/qtexttospeech_winrt_audiosource.cpp b/src/plugins/tts/winrt/qtexttospeech_winrt_audiosource.cpp index a680ffe..476bc15 100644 --- a/src/plugins/tts/winrt/qtexttospeech_winrt_audiosource.cpp +++ b/src/plugins/tts/winrt/qtexttospeech_winrt_audiosource.cpp @@ -117,6 +117,19 @@ qint64 AudioSource::readData(char *data, qint64 maxlen) bufferByteAccess->Buffer(&pbyte); pbyte += m_bufferOffset; + // Check and skip the RIFF header if present to prevent an audible + // click at the start of playback. + if (!m_riffHeaderChecked) { + m_riffHeaderChecked = true; + static const int WaveHeaderLength = 44; + const char *descriptor = reinterpret_cast<const char*>(pbyte); + if (maxlen >= WaveHeaderLength && !qstrncmp(descriptor, "RIFF", 4)) { + pbyte += WaveHeaderLength; + m_bufferOffset += WaveHeaderLength; + maxlen -= WaveHeaderLength; + } + } + switch (m_pause) { case NoPause: break; diff --git a/src/plugins/tts/winrt/qtexttospeech_winrt_audiosource.h b/src/plugins/tts/winrt/qtexttospeech_winrt_audiosource.h index dbd9752..79fdf16 100644 --- a/src/plugins/tts/winrt/qtexttospeech_winrt_audiosource.h +++ b/src/plugins/tts/winrt/qtexttospeech_winrt_audiosource.h @@ -124,6 +124,8 @@ private: ComPtr<::Windows::Storage::Streams::IBufferByteAccess> bufferByteAccess; // The data in the IBuffer might be paritally consumed UINT32 m_bufferOffset = 0; + // RIFF header has been checked at the beginning of the stream + bool m_riffHeaderChecked = false; void populateBoundaries(); QList<Boundary> boundaries; |