[pulseaudio-discuss] Testing echo cancellation on an armhf OMAP phone
Tanu Kaskinen
tanuk at iki.fi
Mon Dec 17 20:58:25 PST 2012
On Mon, 2012-12-17 at 21:49 +0000, Neil Jerram wrote:
> Hi pulseaudio folk. I've been following the list for a while, but this
> is my first post...
>
> I'm working with PulseAudio on the GTA04 phone, specifically trying to
> use it to route the audio during a call, with echo cancellation.
>
> Without the echo cancellation, the picture would be:
>
> +----------+ +--------------------+
> | GSM chip |------ module-loopback -------->|earpiece (sink) |
> | sound | | |
> | card |<------- module-loopback -------|microphone (source) |
> +----------+ +--------------------+
>
> The earpiece and microphone belong to a single sound card, which is
> different from the GSM chip sound card.
>
> The GSM source and sink are named
> alsa_input.platform-soc-audio.1.analog-mono and
> alsa_output.platform-soc-audio.1.analog-mono. The earpiece is
> alsa_output.platform-soc-audio.0.analog-stereo and the microphone is
> alsa_input.platform-soc-audio.0.analog-stereo.
>
> To add in echo cancellation, I load module-echo-cancel, and then start
> up the loopbacks like this:
>
> exec pactl load-module module-loopback \
> source=alsa_input.platform-soc-audio.0.analog-stereo.echo-cancel \
> rate=8000 \
> sink=alsa_output.platform-soc-audio.1.analog-mono
>
> exec pactl load-module module-loopback \
> source=alsa_input.platform-soc-audio.1.analog-mono \
> rate=8000 \
> sink=alsa_output.platform-soc-audio.0.analog-stereo.echo-cancel
>
> Does that all sound correct in theory?
Yes, I think so.
> Now, I'm not actually at the point of doing all that yet. First I'm
> trying to test the echo cancellation. To do that, I:
>
> - load module-echo-cancel
>
> - do "paplay -d
> alsa_output.platform-soc-audio.0.analog-stereo.echo-cancel
> /media/card/Documents/audio/ogg/Do\ They\ Know\ It\'s\ Christmas.ogg"
> in one terminal
>
> - do "parecord -d
> alsa_input.platform-soc-audio.0.analog-stereo.echo-cancel
> --file-format=wav > record1.wav" in another terminal
>
> - speak into the microphone.
>
> Then the idea is that I would play record1.wav back and see if contains
> an echo of the song.
>
> However, I seem to be hitting various problems, which I suspect are all
> to do with resampling.
>
> - With the default resample method (speex-float-3), I don't get any
> sound at the earpiece, except for intermittent crackling.
>
> - I then tried speex-fixed-3. This gives recognisable song playback at
> the earpiece, but with strange echo-like distortions - i.e. as though
> short snatches of the song are being repeated.
>
> - I then tried src-sinc-fastest, and found that PulseAudio exited as
> soon as I loaded module-echo-cancel.
>
> - I then tried src-linear. This gives good song playback, except for
> occasional clicks and crackles.
>
> The song is at 44.1 kHz, I think the sound card's default rate is 48
> kHz, and it looks from the log as though module-echo-cancel causes the
> song to be resampled to 32 kHz (and presumably then back to 48 kHz?).
> Is that all expected, and is there any way of reducing this amount of
> playback resampling?
If you haven't configured the sample rate of module-echo-cancel, then it
will default to 32 kHz (I don't know why), which indeed will cause
unnecessary resampling just as you described. If the hardware runs at 48
kHz, then I think it's best to pass "rate=48000" to module-echo-cancel.
I think it would make sense to modify module-echo-cancel to use the rate
of the microphone by default...
>
> Now - still with src-linear - if I try the parecord line at the same
> time as the playback, the log goes crazy with umpteen rapid repeats of:
>
> Dec 17 21:04:34 neo pulse.sh: I: [alsa-source] alsa-source.c: Trying resume...
> Dec 17 21:04:34 neo pulse.sh: I: [alsa-source] alsa-util.c: Trying to disable ALSA period wakeups, using timers only
> Dec 17 21:04:34 neo pulse.sh: I: [alsa-source] alsa-util.c: Device hw:0 doesn't support 44100 Hz, changed to 48000 Hz.
> Dec 17 21:04:34 neo pulse.sh: I: [alsa-source] alsa-util.c: ALSA period wakeups disabled
> Dec 17 21:04:34 neo pulse.sh: W: [alsa-source] alsa-source.c: Resume failed, couldn't restore original sample settings.
Are only these five lines repeated? I don't understand why this would be
looping, maybe setting the log level to more verbose would reveal the
reason.
Anyway, looping or not, the reason why you can't get anything recorded
is that the source fails to resume from suspended state. If this happens
only when playback is happening at the same time, it suggests that
initially, when playback was not active, the source successfully opened
the device with 44100 sample rate, at which point the rate got locked in
pulseaudio (I think pulseaudio could be fixed to not do that). When
playback is active (presumably at 48 kHz), the hardware doesn't anymore
support capturing at 44.1 kHz, so when pulseaudio tries to open the
device with the old rate, it doesn't work anymore.
You can fix this by setting the default sample rate to 48000.
--
Tanu
More information about the pulseaudio-discuss
mailing list