<div dir="ltr">Hi,<div><br></div><div><div>I've faced strange PulseAudio monitor device (i.e. audio input device which plays sound sent to speaker) behaviour on Ubuntu 16.04. I've reduced code from my real project to simple example based on code from PulseAudio docs <a href="https://freedesktop.org/software/pulseaudio/doxygen/parec-simple_8c-example.html" target="_blank">https://freedesktop.org/<wbr>software/pulseaudio/doxygen/<wbr>parec-simple_8c-example.html</a>, I've only added time limit and read bytes counting. It works for example 30 seconds and prints read bytes count. Problem is that bytes count vastly differs if something is played during program run. I've executed this program and in parallel executed bash for loop consisting aplay with short tada.wav file. Difference is 9%. To test it more, I tried to run 4 such loops in parallel with PulseAudio example and difference is even more - 34%. But if instead of several aplay with short wav I run mplayer with long mp3 file - there is no such difference, bytes count is similar to case when no sound is played.</div><div><br></div><div>Such behaviour causes failure of sound processing code in my real project, so if somebody could suggest how to solve it - I'll be very grateful.</div><div><br></div><div>Similar code on Windows, Qt based and using Stereo Mixer device as analog of PulseAudio monitor works without such problems.</div><div><br></div><div>Code of my program based on example from PulseAudio docs is attached, It could be built with following command "g++ -o main main.cpp -lpulse -lpulse-simple -std=c++11". Example wav file i've taken from <a href="http://d0.waper.ru/f/462151/23/HgDwimvX37CwxWqW38eywg%2C1485353628/7d74/9/462151.wav/tada.wav" target="_blank">http://d0.waper.ru/f/462151/<wbr>23/HgDwimvX37CwxWqW38eywg%<wbr>2C1485353628/7d74/9/462151.<wbr>wav/tada.wav</a></div><div><br></div><div><div>And here are test results:</div><div><br></div><div>==> Test 1. No sound in speaker</div><div><br></div><div>    $ time ./main</div><div>    30 seconds elapsed, terminating</div><div>    5323776 bytes read</div><div>    <br></div><div>    real    0m30.028s</div><div>    user    0m0.168s</div><div>    sys     0m0.388s</div><div><br></div><div>==> Test 2. Bash for loop "for i in seq 1 22; do aplay tada.wav; done" with short wav files in background. Bytes count increase is 5798912 / 5323776 = 1.089 times.</div><div><br></div><div>    $ time ./main </div><div>    30 seconds elapsed, terminating</div><div>    5798912 bytes read</div><div>    <br></div><div>    real    0m30.023s</div><div>    user    0m0.120s</div><div>    sys     0m0.184s</div><div><br></div><div>==> Test 3. 4 Bash for loops with short wav files in background. Bytes count increase is 7129088 / 5323776 = 1.339 times.</div><div><br></div><div>    $ time ./main </div><div>    30 seconds elapsed, terminating</div><div>    7129088 bytes read</div><div>    <br></div><div>    real    0m30.019s</div><div>    user    0m0.164s</div><div>    sys     0m0.196s</div><div><br></div><div>==> Test 4. mplayer with long mp3 in background. 5288960 / 5323776 = 0.993, i.e. no significant bytes count difference.</div><div><br></div><div>    $ time ./main </div><div>    30 seconds elapsed, terminating</div><div>    5288960 bytes read</div><div>    <br></div><div>    real    0m30.024s</div><div>    user    0m0.096s</div><div>    sys     0m0.204s</div><div><br></div><div>Tried to execute a set of each test, averaged bytes count - similar difference.</div><div><br></div><div>Thanks in advance.</div><div><br></div><div>P.S.: Configuration of my system:</div><div>- OS Ubuntu 16.04.1 amd64</div><div>- pulseaudio 1:8.0-0ubuntu3.2</div><div>- alsa-base 1.0.25+dfsg-0ubuntu5</div></div><div><br></div>-- <br><div class="m_-3420597264997574093gmail_signature"><div dir="ltr"><div><div dir="ltr">Best Regards,</div><div dir="ltr">Dmitry Vinokurov<br><div><a href="mailto:gim6626@gmail.com" target="_blank">gim6626@gmail.com</a></div></div></div></div></div>
</div></div>