[pulseaudio-discuss] lots of retry on failure of hw_params interface
Hi community When doing development for Audio driver, I hit an interesting behaviour of pulseaudio Due to some miss configurations in devicetree, my CPU DAI driver always fail on hw_params() interface, when pulseaudio starts to configure driver for the first time, due to the problem in Driver configuration, it fails on hw_params interface. But instead of just exit from execution, (or just retry a few times) pulseaudio continues to retry SNDRV_PCM_IOCTL_HW_PARAMS ioctl call, with the following log message: ... ... I: [pulseaudio] alsa-util.c: snd_pcm_hw_params failed: Invalid argument I: [pulseaudio] alsa-util.c: Failed to set hardware parameters on plug:hw:0: Invalid argument I: [pulseaudio] (alsa-lib)conf.c: Unknown parameters 0 I: [pulseaudio] (alsa-lib)pcm.c: Unknown PCM front:0 I: [pulseaudio] alsa-util.c: Error opening PCM device front:0: Invalid argument I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] alsa-util.c: snd_pcm_hw_params failed: Invalid argument I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] alsa-util.c: snd_pcm_hw_params failed: Invalid argument I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) I: [pulseaudio] (alsa-lib)pcm_hw.c: SNDRV_PCM_IOCTL_HW_PARAMS failed (-22) ... ... as pulseaudio continues its retry of hw_params, it stops the whole system, which doesn't make sense for me. my question is: is this behaviour default for pulseaudio? can I change the retry number (for example, I want pulseaudio only retry a few times), or can I disable the retry mechanism at all? Thanks, Jiada ___ pulseaudio-discuss mailing list pulseaudio-discuss@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss
[pulseaudio-discuss] [PATCH] module-virtual-surround-sink: Move normalization heuristic to its own function
This patch also adds a description how the heuristic works and mentions that there is a scaling factor that can be adjusted if there is audible clipping. --- src/modules/module-virtual-surround-sink.c | 57 +- 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/src/modules/module-virtual-surround-sink.c b/src/modules/module-virtual-surround-sink.c index 1d6cfc6..34f23fd 100644 --- a/src/modules/module-virtual-surround-sink.c +++ b/src/modules/module-virtual-surround-sink.c @@ -519,6 +519,45 @@ static pa_channel_position_t mirror_channel(pa_channel_position_t channel) { } } +static void normalize_hrir(struct userdata *u) { +/* normalize hrir to avoid audible clipping + * + * The following heuristic tries to avoid audible clipping. It cannot avoid + * clipping in the worst case though, because the scaling factor would + * become too large resulting in a too quiet signal. + * The idea of the heuristic is to avoid clipping when a single click is + * played back on all channels. The scaling factor describes the additional + * factor that is necessary to avoid clipping for normal signals. + * + * This algorithm doesn't pretend to be perfect, it's just something that + * appears to work (not too quiet, no audible clipping) on the material that + * it has been tested on. If you find a real-world example where this + * algorithm results in audible clipping, please write a patch that adjusts + * the scaling factor constants or improves the algorithm (or if you can't + * write a patch, at least report the problem to the PulseAudio mailing list + * or bug tracker). */ + +const float scaling_factor = 2.5; + +float hrir_sum, hrir_max; +unsigned i, j; + +hrir_max = 0; +for (i = 0; i u-hrir_samples; i++) { +hrir_sum = 0; +for (j = 0; j u-hrir_channels; j++) +hrir_sum += fabs(u-hrir_data[i * u-hrir_channels + j]); + +if (hrir_sum hrir_max) +hrir_max = hrir_sum; +} + +for (i = 0; i u-hrir_samples; i++) { +for (j = 0; j u-hrir_channels; j++) +u-hrir_data[i * u-hrir_channels + j] /= hrir_max * scaling_factor; +} +} + int pa__init(pa_module*m) { struct userdata *u; pa_sample_spec ss, sink_input_ss; @@ -533,7 +572,6 @@ int pa__init(pa_module*m) { const char *hrir_file; unsigned i, j, found_channel_left, found_channel_right; -float hrir_sum, hrir_max; float *hrir_data; pa_sample_spec hrir_ss; @@ -758,22 +796,7 @@ int pa__init(pa_module*m) { goto fail; } -/* normalize hrir to avoid clipping */ -hrir_max = 0; -for (i = 0; i u-hrir_samples; i++) { -hrir_sum = 0; -for (j = 0; j u-hrir_channels; j++) -hrir_sum += fabs(u-hrir_data[i * u-hrir_channels + j]); - -if (hrir_sum hrir_max) -hrir_max = hrir_sum; -} -if (hrir_max 1) { -for (i = 0; i u-hrir_samples; i++) { -for (j = 0; j u-hrir_channels; j++) -u-hrir_data[i * u-hrir_channels + j] /= hrir_max * 1.2; -} -} +normalize_hrir(u); /* create mapping between hrir and input */ u-mapping_left = (unsigned *) pa_xnew0(unsigned, u-channels); -- 1.9.1 ___ pulseaudio-discuss mailing list pulseaudio-discuss@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss
[pulseaudio-discuss] [PATCH] resampler: Support speex resampler compiled with FIXED_POINT
When Speex is compiled with FIXED_POINT defined, it scales float input to +/-32768 instead of +/-1. In order to make floating point resampler work with speex compiled with FIXED_POINT, we need to rescale the input to speex. Unfortunately, there is no easy way to tell how speex has been built, so we probe at runtime. A patch to fix speex was rejected saying that speex API is stable. Further discussion is here http://lists.openembedded.org/pipermail/openembedded-core/2014-January/087886.html Signed-off-by: Peter Meerwald pme...@pmeerw.net Reported-by: Fahad Arslan fahad_ars...@mentor.com Cc: Damir Jelić poljari...@gmail.com --- src/pulsecore/resampler.c | 81 ++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c index 38389f3..4a9c1f5 100644 --- a/src/pulsecore/resampler.c +++ b/src/pulsecore/resampler.c @@ -39,6 +39,7 @@ #include pulsecore/macro.h #include pulsecore/strbuf.h #include pulsecore/remap.h +#include pulsecore/once.h #include pulsecore/core-util.h #include ffmpeg/avcodec.h @@ -1490,6 +1491,82 @@ static unsigned speex_resample_float(pa_resampler *r, const pa_memchunk *input, return 0; } +/* float resampler when speexdsp is built with FIXED_POINT */ +static unsigned speex_resample_float_fixed(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { +pa_memblock *b; +float *in, *out, *t; +uint32_t inf = in_n_frames, outf = *out_n_frames, i; +unsigned nsamples = r-work_channels * in_n_frames; +SpeexResamplerState *state; + +pa_assert(r); +pa_assert(input); +pa_assert(output); +pa_assert(out_n_frames); + +state = r-impl.data; + +b = pa_memblock_new(r-mempool, nsamples * sizeof(float)); +t = pa_memblock_acquire(b); +in = pa_memblock_acquire_chunk(input); + +/* speexdsp float API sample range is [-32768,32768] instead of [-1,1] + * when compiled with FIXED_POINT, rescale input before passing to speex. */ +for (i = 0; i nsamples; i++) +t[i] = 32768.0f * in[i]; + +pa_memblock_release(input-memblock); + +out = pa_memblock_acquire_chunk(output); + +pa_assert_se(speex_resampler_process_interleaved_float(state, t, inf, out, outf) == 0); + +pa_memblock_release(b); +pa_memblock_unref(b); + +pa_memblock_release(output-memblock); + +pa_assert(inf == in_n_frames); +*out_n_frames = outf; + +return 0; +} + +/* speexdsp has a nasty issue: when built with FIXED_POINT, the float resampler + * expects samples in [-32768,32768] instead of [-1,1]; there is no easy way + * to figure out how speexdsp has been compiled. */ + +static unsigned (*speex_resampler_float)(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) = speex_resample_float; + +static void speex_probe_fixed_point() { +PA_ONCE_BEGIN { +float f_out = -1.0f, f_in = 1.0f; +spx_uint32_t in_len = 1, out_len = 1; + +SpeexResamplerState *s = speex_resampler_init(1, 1, 1, +SPEEX_RESAMPLER_QUALITY_MIN, NULL); +if (!s) +goto done; + +/* feed one sample */ +if (speex_resampler_process_float(s, 0, f_in, in_len, +f_out, out_len) != RESAMPLER_ERR_SUCCESS) +goto done; + +/* expecting sample has been processed, one sample output */ +if (in_len != 1 out_len != 1) +goto done; + +/* FIXED_POINT implementation will output 0.0 */ +if (fabsf(f_out) 0.1f) +speex_resampler_float = speex_resample_float_fixed; + +done: +if (s) +speex_resampler_destroy(s); +} PA_ONCE_END; +} + static unsigned speex_resample_int(pa_resampler *r, const pa_memchunk *input, unsigned in_n_frames, pa_memchunk *output, unsigned *out_n_frames) { int16_t *in, *out; uint32_t inf = in_n_frames, outf = *out_n_frames; @@ -1563,8 +1640,10 @@ static int speex_init(pa_resampler *r) { } else { pa_assert(r-method = PA_RESAMPLER_SPEEX_FLOAT_BASE r-method = PA_RESAMPLER_SPEEX_FLOAT_MAX); +speex_probe_fixed_point(); + q = r-method - PA_RESAMPLER_SPEEX_FLOAT_BASE; -r-impl.resample = speex_resample_float; +r-impl.resample = speex_resampler_float; } pa_log_info(Choosing speex quality setting %i., q); -- 1.9.1 ___ pulseaudio-discuss mailing list pulseaudio-discuss@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss
[pulseaudio-discuss] PulseAudio Python Bindings
Hi PulseAudio developers and Python fans, I am the author of PulseAudio Python Bindings https://github.com/linuxdeepin/pypulseaudio And right now it is public repos, if someone want to maintain it, please let me know, thanks a lot! Regards, Leslie Zhai ___ pulseaudio-discuss mailing list pulseaudio-discuss@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss