aboutsummaryrefslogtreecommitdiff
path: root/audio/paaudio.c
AgeCommit message (Collapse)AuthorFilesLines
2019-07-03fix microphone lag with PAMartin Schrodt1-1/+1
Several people have reported to have bag microphone lag with the PA backend. While I cannot reproduce the problem here, it seems that their PA somehow decides to buffer the microphone input for way too long, causing this delay. This patch sets an upper limit to the amount of data PA should hold. This fixes the problem reliably on their side, while having no adverse effects on mine. Signed-off-by: Martin Schrodt <martin@schrodt.org> Message-id: 20190615153852.99040-1-martin@schrodt.org Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2019-06-12Include qemu/module.h where needed, drop it from qemu-common.hMarkus Armbruster1-1/+2
Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20190523143508.25387-4-armbru@redhat.com> [Rebased with conflicts resolved automatically, except for hw/usb/dev-hub.c hw/misc/exynos4210_rng.c hw/misc/bcm2835_rng.c hw/misc/aspeed_scu.c hw/display/virtio-vga.c hw/arm/stm32f205_soc.c; ui/cocoa.m fixed up]
2019-03-18audio/paaudio: fix microphone input being unusableMartin Schrodt1-1/+7
The current code does not specify the metrics of the buffers for the input device. This makes PulseAudio choose very bad defaults, which causes input to be unusable: Audio put in gets out 30 seconds later. This patch fixes that and makes the latency configurable as well. Signed-off-by: Martin Schrodt <martin@schrodt.org> Message-id: 20190315084653.120020-4-martin@schrodt.org Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2019-03-18audio/paaudio: prolong and make latency configurableMartin Schrodt1-6/+6
The latency of a connection to the PulseAudio server is determined by the tlength parameter. This was hardcoded to 10ms, which is a bit too tight on my machine, causing audio on host and guest to malfunction. A setting of 15ms works fine here. To allow tweaking, I also made the setting configurable via the new -audiodev config. This allows to squeeze out better timings in scenarios where the emulation allows it. I also removed setting of the minreq parameter to (seemingly arbitrary) half the latency, since it showed worse audio quality during my tests. Allowing PulseAudio to request smaller chunks helped. Signed-off-by: Martin Schrodt <martin@schrodt.org> Message-id: 20190315084653.120020-3-martin@schrodt.org Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2019-03-18audio/paaudio: fix ignored buffer_length settingMartin Schrodt1-3/+21
Audiodev configuration allows to set the length of the buffered data. The setting was ignored and a constant value used instead. This patch makes the code apply the setting properly, and uses the previous default if nothing is supplied. Signed-off-by: Martin Schrodt <martin@schrodt.org> Message-id: 20190315084653.120020-2-martin@schrodt.org Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2019-03-11paaudio: port to -audiodev configKővágó, Zoltán1-52/+29
Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com> Message-id: c74dc9c282075fba6928c40b2deae057fa0d4049.1552083282.git.DirtY.iCE.hu@gmail.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2019-03-11audio: -audiodev command line option basic implementationKővágó, Zoltán1-1/+1
Audio drivers now get an Audiodev * as config paramters, instead of the global audio_option structs. There is some code in audio/audio_legacy.c that converts the old environment variables to audiodev options (this way backends do not have to worry about legacy options). It also contains a replacement of -audio-help, which prints out the equivalent -audiodev based config of the currently specified environment variables. Note that backends are not updated and still rely on environment variables. Also note that (due to moving try-poll from global to backend specific option) currently ALSA and OSS will always try poll mode, regardless of environment variables or -audiodev options. Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com> Message-id: e99a7cbdac0d13512743880660b2032024703e4c.1552083282.git.DirtY.iCE.hu@gmail.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2019-03-11audio: use qapi AudioFormat instead of audfmt_eKővágó, Zoltán1-14/+14
I had to include an enum for audio sampling formats into qapi, but that meant duplicating the audfmt_e enum. This patch replaces audfmt_e and associated values with the qapi generated AudioFormat enum. This patch is mostly a search-and-replace, except for switches where the qapi generated AUDIO_FORMAT_MAX caused problems. Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-id: 01251b2758a1679c66842120b77c0fb46d7d0eaf.1552083282.git.DirtY.iCE.hu@gmail.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2019-01-24audio: check for pulseaudio daemon pidfileGerd Hoffmann1-0/+15
Check whenever the pulseaudio daemon pidfile is present before trying to initialize the pulseaudio backend. Just return NULL if that is not the case, so qemu will check the next backend in line. In case the user explicitly configured a non-default pulseaudio server skip the check. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Message-id: 20190124112055.547-5-kraxel@redhat.com
2018-11-12pulseaudio: process audio data in smaller chunksGerd Hoffmann1-2/+2
The rate of pulseaudio absorbing the audio stream is used to control the the rate of the guests audio stream. When the emulated hardware uses small chunks (like intel-hda does) we need small chunks on the audio backend side too, otherwise that feedback loop doesn't work very well. Cc: Max Ehrlich <maxehr@umiacs.umd.edu> Cc: Martin Schrodt <martin@schrodt.org> Buglink: https://bugs.launchpad.net/bugs/1795527 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-id: 20181109142032.1628-1-kraxel@redhat.com
2018-03-12audio: add driver registryGerd Hoffmann1-1/+7
Add registry for audio drivers, using the existing audio_driver struct. Make all drivers register themself. The old list of audio_driver struct pointers is now a list of audio driver names, specifying the priority (aka probe order) in case no driver is explicitly asked for. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-id: 20180306074053.22856-2-kraxel@redhat.com
2018-02-06audio: Replace AUDIO_FUNC with __func__Alistair Francis1-28/+28
Apparently we don't use __MSC_VER as a compiler anymore and we always require a C99 compiler (which means we always have __func__) so we don't need a special AUDIO_FUNC macro. We can just replace AUDIO_FUNC with __func__ instead. Checkpatch failures were manually fixed. Signed-off-by: Alistair Francis <alistair.francis@xilinx.com> Cc: Gerd Hoffmann <kraxel@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20180203084315.20497-2-armbru@redhat.com>
2018-01-16maint: Fix macros with broken 'do/while(0); ' usageEric Blake1-2/+2
The point of writing a macro embedded in a 'do { ... } while (0)' loop (particularly if the macro has multiple statements or would otherwise end with an 'if' statement) is so that the macro can be used as a drop-in statement with the caller supplying the trailing ';'. Although our coding style frowns on brace-less 'if': if (cond) statement; else something else; that is the classic case where failure to use do/while(0) wrapping would cause the 'else' to pair with any embedded 'if' in the macro rather than the intended outer 'if'. But conversely, if the macro includes an embedded ';', then the same brace-less coding style would now have two statements, making the 'else' a syntax error rather than pairing with the outer 'if'. Thus, even though our coding style with required braces is not impacted, ending a macro with ';' makes our code harder to port to projects that use brace-less styles. The change should have no semantic impact. I was not able to fully compile-test all of the changes (as some of them are examples of the ugly bit-rotting debug print statements that are completely elided by default, and I didn't want to recompile with the necessary -D witnesses - cleaning those up is left as a bite-sized task for another day); I did, however, audit that for all files touched, all callers of the changed macros DID supply a trailing ';' at the callsite, and did not appear to be used as part of a brace-less conditional. Found mechanically via: $ git grep -B1 'while (0);' | grep -A1 \\\\ Signed-off-by: Eric Blake <eblake@redhat.com> Acked-by: Cornelia Huck <cohuck@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Message-Id: <20171201232433.25193-7-eblake@redhat.com> Reviewed-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-06-03audio: pa: Set volume of recording stream instead of recording devicePeter Krempa1-6/+5
Since pulseaudio 1.0 it's possible to set the individual stream volume rather than setting the device volume. With this, setting hardware mixer of a emulated sound card doesn't mess up the volume configuration of the host. A side effect is that this limits compatible pulseaudio version to 1.0 which was released on 2011-09-27. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-id: 78853815be2069971b89b3a2e3181837064dd8f3.1462962512.git.pkrempa@redhat.com Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2016-02-02audio: Clean up includesPeter Maydell1-0/+1
Clean up includes so that osdep.h is included first and headers which it implies are not included manually. This commit was created with scripts/clean-includes. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 1453138432-8324-1-git-send-email-peter.maydell@linaro.org Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2015-06-15paaudio: fix possible resource leakKővágó, Zoltán1-1/+5
qpa_audio_init did not clean up resources properly if the initialization failed. This hopefully fixes it. Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2015-06-15paaudio: do not use global variablesKővágó, Zoltán1-46/+52
Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2015-06-15audio: expose drv_opaque to init_out and init_inKővágó, Zoltán1-2/+3
Currently the opaque pointer returned by audio_driver's init is only exposed to the driver's fini, but not to audio_pcm_ops. This way if someone wants to share a variable with the driver and the pcm, he must use global variables. This patch fixes it by adding a third parameter to audio_pcm_op's init_out and init_in. Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2013-12-09audio: adjust pulse to 100Hz wakeup rateGerd Hoffmann1-4/+4
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-05-04fix build with pulseaudio versions older than 0.9.11Gerd Hoffmann1-1/+29
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: malc <av1474@comtv.ru>
2012-04-25fix paaudio.c warningsGerd Hoffmann1-2/+1
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: malc <av1474@comtv.ru>
2012-04-17Allow controlling volume with PulseAudio backendMarc-André Lureau1-5/+94
Signed-off-by: Marc-Andr? Lureau <marcandre.lureau@redhat.com> Signed-off-by: malc <av1474@comtv.ru>
2012-04-17Do not use pa_simple PulseAudio APIMarc-André Lureau1-38/+339
Unfortunately, pa_simple is a limited API which doesn't let us retrieve the associated pa_stream. It is needed to control the volume of the stream. In v4: - add missing braces Signed-off-by: Marc-Andr? Lureau <marcandre.lureau@redhat.com> Signed-off-by: malc <av1474@comtv.ru>
2011-08-20Use glib memory allocation and free functionsAnthony Liguori1-4/+4
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-01-25pulseaudio: tweak configGerd Hoffmann1-9/+1
Zap unused divisor field. Raise the buffer size default. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: malc <av1474@comtv.ru>
2011-01-25pulseaudio: setup buffer attrsGerd Hoffmann1-1/+11
Request reasonable buffer sizes from pulseaudio. Without this pa_simple_write() can block quite long and lead to dropouts, especially with guests which use small audio ring buffers. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: malc <av1474@comtv.ru>
2011-01-25pulseaudio: process 1/4 buffer max at onceGerd Hoffmann1-13/+9
Limit the size of data pieces processed by the pulseaudio worker threads. Never ever process more than 1/4 of the buffer at once. Background: The buffer area currently processed by the pulseaudio thread is blocked, i.e. the main thread (or iothread) can't fill in more data there. The buffer processing time is roughly real-time due to the pa_simple_write() call blocking when the output queue to the pulse server is full. Thus processing big chunks at once means blocking a large part of the buffer for a long time. This brings high latency and can lead to dropouts. When processing the buffer in smaller chunks the rpos handling becomes a problem though. The thread reads hw->rpos without knowing whenever qpa_run_out has already seen the last (small) chunk processed and updated rpos accordingly. There is no point in reading hw->rpos though, pa->rpos can be used instead. We just need to take care to initialize pa->rpos before kicking the thread. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: malc <av1474@comtv.ru>
2011-01-12audio: split sample conversion and volume mixingMichael Walle1-1/+1
Refactor the volume mixing, so it can be reused for capturing devices. Additionally, it removes superfluous multiplications with the nominal volume within the hardware voice code path. Signed-off-by: Michael Walle <michael@walle.cc> Signed-off-by: malc <av1474@comtv.ru>
2010-09-29pulse-audio: fix bug on updating rposWu Fengguang1-1/+1
Fix a rpos coordination bug between qpa_run_out() and qpa_thread_out(), which shows up as playback noises. qpa_run_out() qpa_thread_out loop N critical section 1 qpa_run_out() qpa_thread_out loop N doing pa_simple_write() qpa_run_out() qpa_thread_out loop N doing pa_simple_write() qpa_thread_out loop N critical section 2 qpa_thread_out loop N+1 critical section 1 qpa_run_out() qpa_thread_out loop N+1 doing pa_simple_write() In the above scheme, "qpa_thread_out loop N+1 critical section 1" will get the same rpos as the one used by "qpa_thread_out loop N critical section 1". So it will be reading dead samples from the old rpos. The rpos can only be updated back to qpa_thread_out when there is a qpa_run_out() run between two qpa_thread_out loops. normal sequence: qpa_thread_out: hw->rpos (X0) => local rpos => pa->rpos (X1) qpa_run_out: pa->rpos (X1) => hw->rpos (X1) qpa_thread_out: hw->rpos (X1) => local rpos => pa->rpos (X2) buggy sequence: qpa_thread_out: hw->rpos (X0) => local rpos => pa->rpos (X1) qpa_thread_out: hw->rpos (X0) => local rpos => pa->rpos (X1') Obviously qpa_run_out() shall be called at least once between any two qpa_thread_out loops (after pa->rpos is set), in order for the new qpa_thread_out loop to see the updated rpos. Setting pa->live to 0 does the trick. The next loop will have to wait for one qpa_run_out() invocation in order to get a non-zero pa->live and proceed. Signed-off-by: malc <av1474@comtv.ru> Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
2009-10-13qemu: allow pulseaudio to be the defaultMichael S. Tsirkin1-1/+1
We're seeing various issues with the SDL audio backend and want to switch to the pulseaudio backend. See e.g. https://bugzilla.redhat.com/495964 https://bugzilla.redhat.com/519540 https://bugzilla.redhat.com/496627 The pulseaudio backend seems to work well, so we should allow it to be selected as the default. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: malc <av1474@comtv.ru>
2009-09-18audio: internal API changemalc1-3/+2
pcm_ops.run_out now takes number of live samples (which will be always greater than zero) as a second argument, every driver was calling audio_pcm_hw_get_live_out anyway with exception of fmod which used audio_pcm_hw_get_live_out2 for no good reason. Signed-off-by: malc <av1474@comtv.ru>
2009-08-11Aestheticsmalc1-20/+30
Reformat to make item borders more visible Fix cases of stray tabs and vertical misalignments Signed-off-by: malc <av1474@comtv.ru>
2009-08-11use C99 initializers for all audio/*Juan Quintela1-5/+2
Signed-off-by: Juan Quintela <quintela@redhat.com>
2009-08-11use C99 initializers for audio_pcm_opsJuan Quintela1-10/+11
Signed-off-by: Juan Quintela <quintela@redhat.com>
2009-08-11Use C99 initializers for audio_optionJuan Quintela1-16/+21
Signed-off-by: Juan Quintela <quintela@redhat.com>
2009-08-11Use proper struct initializers and remove INIT_FIELD() macroJuan Quintela1-11/+11
Signed-off-by: Juan Quintela <quintela@redhat.com>
2009-06-19fix qemu_alloc/qemu_free for audio subsystemJean-Christophe Dubois1-2/+2
Signed-off-by: Jean-Christophe DUBOIS <jcd@tribudubois.net>
2008-12-03Make audio violate POSIX lessmalc1-5/+5
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5864 c046a42c-6fe2-441c-8c8c-71466251a162
2008-10-06Prepare for changing audio_pcm_ops dynamically (partially revert r5422)blueswir11-1/+1
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5435 c046a42c-6fe2-441c-8c8c-71466251a162
2008-10-05Make audio_pcm_opsstatic constblueswir11-1/+1
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5422 c046a42c-6fe2-441c-8c8c-71466251a162
2008-07-02Pulseaudio drivermalc1-0/+515
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4827 c046a42c-6fe2-441c-8c8c-71466251a162