Strange PulseAudio monitor device behaviour

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

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
https://freedesktop.org/software/pulseaudio/doxygen/
parec-simple_8c-example.html, 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.

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.

Similar code on Windows, Qt based and using Stereo Mixer device as analog
of PulseAudio monitor works without such problems.

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
http://d0.waper.ru/f/462151/23/HgDwimvX37CwxWqW38eywg%
2C1485353628/7d74/9/462151.wav/tada.wav

And here are test results:

==> Test 1. No sound in speaker

    $ time ./main
    30 seconds elapsed, terminating
    5323776 bytes read

    real    0m30.028s
    user    0m0.168s
    sys     0m0.388s

==> 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.

    $ time ./main
    30 seconds elapsed, terminating
    5798912 bytes read

    real    0m30.023s
    user    0m0.120s
    sys     0m0.184s

==> Test 3. 4 Bash for loops with short wav files in background. Bytes
count increase is 7129088 / 5323776 = 1.339 times.

    $ time ./main
    30 seconds elapsed, terminating
    7129088 bytes read

    real    0m30.019s
    user    0m0.164s
    sys     0m0.196s

==> Test 4. mplayer with long mp3 in background. 5288960 / 5323776 = 0.993,
i.e. no significant bytes count difference.

    $ time ./main
    30 seconds elapsed, terminating
    5288960 bytes read

    real    0m30.024s
    user    0m0.096s
    sys     0m0.204s

Tried to execute a set of each test, averaged bytes count - similar
difference.

Thanks in advance.

P.S.: Configuration of my system:
- OS Ubuntu 16.04.1 amd64
- pulseaudio 1:8.0-0ubuntu3.2
- alsa-base 1.0.25+dfsg-0ubuntu5

-- 
Best Regards,
Dmitry Vinokurov
gim6626 at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20170125/7571ab7b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 1786 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20170125/7571ab7b/attachment.cpp>


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux