Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distorted recording with certain mic (but not in pulseaudio) #720

Open
lowlyocean opened this issue Jun 11, 2024 · 3 comments
Open

Distorted recording with certain mic (but not in pulseaudio) #720

lowlyocean opened this issue Jun 11, 2024 · 3 comments

Comments

@lowlyocean
Copy link

lowlyocean commented Jun 11, 2024

Setup

There are two bluetooth devices:

  1. Bluetooth headset (with plain mic)
  2. Bluetooth speakerphone (with echo-cancelling mic)

That I've been pairing to two machines:

  1. Raspberry Pi OS 64 bit running BlueAlsa (SCO profile for both capture and playback)
    a. I tried both built-in BT chip, and a USB adapter (both show identical behavior)
  2. Desktop PC running Ubuntu Jammy and PulseAudio

Problem

I have an issue when I pair Device 2 (speakerphone) with Machine 1 (Blue Alsa): there is distortion and pitch-shift during recording from the microphone. It sounds demonic.

I can confirm that playback of hcidump -A output.raw contains the distortion, so I suspect the speakerphone's echo cancellation somehow doesn't work well with bluealsa. The same device works paired on the separate PulseAudio machine.. but the separate pair of headphones records on this machine without distortion

Additional context

Configuration of Raspberry Pi with BlueAlsa:

bluealsa -p a2dp-source -p a2dp-sink -p hfp-hf -p hsp-hs -p hfp-ag -p hsp-ag

        UUID: Serial Port               (00001101-0000-1000-8000-00805f9b34fb)
        UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
        UUID: Advanced Audio Distribu.. (0000110d-0000-1000-8000-00805f9b34fb)
        UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
        UUID: Handsfree                 (0000111e-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        UUID: Vendor specific           (fe010000-1234-5678-abcd-00805f9b34fb)

pcm.!default {
type asym
playback.pcm {
type plug
slave.pcm {
type bluealsa
device "12:34:56:78:AB:CD"
profile "sco"
}
}
capture.pcm {
type plug
slave.pcm {
type bluealsa
device "12:34:56:78:AB:CD"
profile "sco"
}
}
}

ctl.!default {
type bluealsa
}

Ubuntu machine with PulseAudio:

sinks

sources

pulseaudio

@lowlyocean lowlyocean changed the title hfp-ag is auto-selected instead of hfp-hf, leads to distorted microphone recording Distorted microphone recording Jun 11, 2024
@lowlyocean lowlyocean changed the title Distorted microphone recording Distorted microphone recording (with one device but not another) Jun 11, 2024
@lowlyocean lowlyocean changed the title Distorted microphone recording (with one device but not another) Distorted recording with certain mic (but not in pulseaudio) Jun 11, 2024
@borine
Copy link
Collaborator

borine commented Jun 12, 2024

Please can you state:

  • the version of bluealsa that you are using, and if self-built from source the options used for configure.
  • The codec and sample rate used by both the devices when used with bluealsa and when used with pulseaudio
  • the application used for recording with bluealsa (with settings used for sample format, sample rate and channels)

I don't have any echo-cancelling devices to try this for myself, but if I am given enough information to reproduce the rest of your set-up I may be able to track down some possible causes.

@lowlyocean
Copy link
Author

lowlyocean commented Jun 12, 2024

Sure, not built from source - pasting relevant distro-provided packages:

> ii  bluez                                            5.66-1+rpt1+deb12u1                       arm64        Bluetooth tools and daemons
> ii  bluez-alsa-utils                                 4.0.0-2                                   arm64        Bluetooth Audio ALSA Backend (utils)
> ii  bluez-firmware                                   1.2-9+rpt3                                all          Firmware for Bluetooth devices
> ii  bluez-hcidump                                    5.66-1+rpt1+deb12u1                       arm64        Analyses Bluetooth HCI packets
> ii  libasound2-plugin-bluez:arm64                    4.0.0-2                                   arm64        Bluetooth Audio ALSA Backend (plugins)

Sample rate & format for speakerphone with bluealsa: arecord -vvv -f S16_LE -r 8000 -c1 <file.wav>. Logs indicated codec was CVSD

For pulseaudio I run systemctl mask bluealsa.service followed by rm /etc/asound.conf, and reboot; then after bluetoothctl connect <address> and pactl set-card-profile bluez_card.<address> handsfree_head_unit, I run the same arecord command

@borine
Copy link
Collaborator

borine commented Jun 12, 2024

arecord -vvv ...

The output from that should show the setup of each ALSA plugin used. Please could you post that section of the output so that we can see which plugins are used, and what the setup of each is? It is possible that the pitch-shift may be caused by a plugin; but it is also possible that dropped SCO frames may result in a raised pitch, combined with frequent underruns. (In this case playing from the hcidump file would also result in the raised pitch, but without the underruns).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants