Solved Volume changing, even though it shouldn't, while changing microphone
-
Hello,
My team has developed an application that uses Qt's QAudioSource class to get audio data from the computer's microphone. When we change the microphone, the old QAudioSource object is deleted and a new one is created (dynamic memory allocation + deallocation in C++). The change is initiated in the frontend (which uses QML and communicates with the backend using signals and slots).
The problem is, sometimes (maybe 10 - 20 % of the time) the microphone change doesn't work properly, but in addition to changing the microphone, the microphone volume also changes to way too loud (this change is not visible in OS controls, and it's way over 100%).
We haven't found an obvious reason for this bug in our code. Does this sound like it could be caused by Qt (eg. the signal and slot mechanism), or by the OS, or drivers? We have replicated the issue on at least two computers.
Thanks.
-
Hi,
Which version of Qt are you using ?
On which OS does it happen ? -
Qt version: 6.2.2
OS: Windows. I don't know if we've replicated the problem on Linux, we're mainly using the program on Windows.That said, when I change my microphone on Windows normally, meaning outside our Qt application, I have never had such volume problems.
-
Actually, let me correct the problem description in the sense that the volume does not turn very loud, but rather starts clipping heavily (which makes me suspect it exceeded the maximum allowed value).
My teammate who also has had the problem says he may have solved the issue by explicitly setting the QAudioSource volume level each time a new object is instantiated.
-
Further update: my teammate's solution of setting the microphone volume explicitly when changing microphone did not solve the issue, at least on my computer.
-
Did you check the volume value before destroying the source and after creating the new one ?
-
Yes. In both cases, the nominal value is 1.0, the maximum (when calling source->volume()). But once the error happens, the microphone sound is somewhat louder and starts heavily clipping.
-
So, my teammate found the bug coming from our software after all. The audio problem is now fixed, our buffer was working badly. Sorry for the inconvenience.
-
Glad you found out and thanks for sharing !
Can you explain happened with your buffer ?
-
As far as I understand from my teammate's explanation, we have created our own buffer class, and the class sometimes took the last byte of the previous audio sample (we use the 16-bit PCM format) and combined it with the next audio sample's first byte. He fixed the issue by regularly emptying the buffer.
Our buffer class is a subclass of QIODevice.
-
That's surprising to have a residual byte from a 16bit format. Anyway, glad you found the culprit.