Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A2DP sink without pulseaudio

So I'm trying to make my linux server play music sent from my Android phone using bluetooth (the linux machine is the A2DP sink and the phone is the source). What I have done so far is to:

  • install bluez and enable audiosource/audiosink
  • pair phone and server
  • connect to server from phone (phone says it's streaming audio over bluetooth)

But I can't hear anything. Also, most guides on the internet assumes Pulseaudio and I would prefer to use ALSA.

I currently have the following in /etc/asound.conf:

pcm.!default{
    type bluetooth
    profile "auto"
}

I'm running Bluez v4.99 and Alsa v1.0.25. Any ideas?

like image 397
lode Avatar asked Sep 09 '12 11:09

lode


2 Answers

I know this is an old post, but hopefully the answer is useful to people currently working on this.

You can use /etc/bluetooth/audio.conf, which is the system-wide file, or ~/.asoundrc, which is your local file. Both are read by BlueZ/ALSA. However, I think you need to include the MAC address in your config file, z.B.:

pcm.btheadset {
    type bluetooth
    device "XX:XX:XX:XX:XX:XX" #MAC address
    profile "auto"
}

The best resources I've found for this are:

1) James B's blog post: Bluez must be one of the best kept secrets in Linux
He explains the structure and interface between BlueZ and ALSA, which I found nowhere else on the internet.

2) His second post with code: Bluez A2DP AudioSink for ALSA

3) The ALSA site, which introduces the structure of pcm plugins, but doesn't really explain them very well.

4) Some ALSA plugin tutorials: The ALSA wiki

Some useful commands:

$sudo service bluetooth restart
$sudo alsa force-reload

Run these after you change the asoundrc or audio.conf files.

like image 62
MrUser Avatar answered Sep 21 '22 19:09

MrUser


Here you find a manual to configure bluetooth with ALSA or Pulseaudio:

-tested on Linux Mint 17.3 Mate, 64bit / Ubuntu 14.04 Mate, 64bit-

HOW TO MAKE ALSA AND BLUETOOTH WORK TOGETHER WITHOUT PA

This part is for pure ALSA-based systems without Pulseaudio like KXStudio, QStudio64,Tango studio..!

Be sure that Pulseaudio is deinstalled and your soundcards configured right in ALSA!

  • delete pulse-audio cookies and files in /home/USERNAME/.config/pulse

    1. Modify your bluetooth-audio.conf: type:

    gksudo pluma /etc/bluetooth/audio.conf

    Set

    # This section contains options which are not specific to any
    # particular interface
    

    [General] Enable=Socket

Save the file.

  1. setup ~/.asoundrc file type:

sudo hcitool scan

Scanning ... XX:XX:XX:XX:XX:XX Stereo Headset

Create a hidden-file named .asoundrc in your home-folder!and write:

    pcm.!default {
        type plug
        slave.pcm {
             type bluetooth
             device "XX:XX:XX:XX:XX:XX"
             profile "auto"

        }
}

Replace “XX:XX..” with the adress of your device.

Save the file!

Run these after you change the asoundrc or audio.conf files:

sudo service bluetooth restart
sudo alsa force-reload

or reboot your computer! ———————————————————————————————————–—-

Go to your blueman-applet at your taskbar, search & setup your new device! Note: Some bluetooth-devices need a passphrase (eg. 0000) by default

  • while some others takes shuffle-pairing. Keep your found and paired device to “trust”!

Connect your device as AUDIO via A2DP!

————————————————————————————————————

If your device is connected with your system you can play sound with totem (gui), vlc (gui+terminal), mplayer (terminal), qmmp (gui), banshee and browsers over bluetooth while setting the output in players to “default”!

—————————————————————————————————–———

RENAME THE .ASOUNDRC IN HOME-FOLDER TO “.ASOUNDRC_OFF” TO GET YOUR OLD SYSTEM-SETTINGS WITHOUT BLUETOOTH BACK!

type: mv /home/USERNAME/.asoundrc /home/USERNAME/.asoundrcOFF ->to disable the bluetooth-specific asoundrc

type: mv /home/USERNAME/.asoundrcOFF /home/USERNAME/.asoundrc -> to enable it!

Alternative:

Make two “scripts” to activate/deactivate bluetooth with .asoundrc in your home-folder:

Create one empty file and write/paste:

#!/bin/bash
mv /home/USERNAME/.asoundrc /home/USERNAME/.asoundrcOFF
or:
#!/bin/bash
cd /home/USERNAME/
mv .asoundrc .asoundrcOFF

To activate your .asoundrc for bluetooth again, create another file with following entry:

#!/bin/bash
mv /home/USERNAME/.asoundrcOFF /home/USERNAME/.asoundrc

or:

#!/bin/bash
cd /home/USERNAME/
mv .asoundrcOFF .asoundrc

Make the files executable and run them with “open with terminal”! Now you have two “buttons” to switch bluetooth-sound On or Off.

Give them individual-icons: ;-)

————————————————————————————————————-

PLAYERS

————–

It’s recommend to use totem, Qmmp or Banshee-player - because there is nothing more to do than play and listen! Also totem-player shows videos too.

VLC-player needs the “default” sounddriver for bluetooth to working right!

Check in: /home/USERNAME/.config/vlc/vlcrc

that alsa-audio-device in >>line1666<< is:

# ALSA Device Name (string)
alsa-audio-device=default

Use this commands to use players with terminal: To play music, type:

MPlayer

———––

mplayer /home/USERNAME/Musik/1.mp3

If you hear no sound or get errors try:

mplayer -ao alsa:device=default /home/USERNAME/Musik/1.mp3

VLC-Player

—————-

cvlc /home/USERNAME/Musik/1.mp3
vlc /home/USERNAME/Musik/1.mp3
rvlc /home/USERNAME/Musik/1.mp3
To add whole directories type:
rvlc add /home/USERNAME/Musik/

type: start/stop/next... to navigate!

or use the vlc-gui.

—————————————————————————————————–——-

To use mplayer with graphical-interface you have to install the gui-package: type:

sudo apt-get install mplayer-gui

Open a terminal via Ctrl-Alt-T and use the commands below.Use the lines and type/copy one by one to avoid confusion(!):

cd /usr/share/mplayer/skins/default

for FILE in *.png; do sudo convert “$FILE” -define png:format=png24 “$FILE”; done

cd /usr/share/mplayer/skins; sudo rm default; sudo ln -s Blue default

———————————————————————————————————–

Now you can start the mplayer-gui without errors!

If you prefer the terminal type:

gmplayer /home/USERNAME/Musik/1.mp3

or

gmplayer -ao alsa:device=default /home/USERNAME/Musik/1.mp3
if you have problems!

terminal command without gui:

mplayer /DIRECTION/TO/FILE

Available Output-Modules and Drivers:

mplayer -vo help

———————————————————————-

BLUETOOTH WITH PULSEAUDIO

————————————————–--------

For Linux systems that comes with pulseaudio:

(1.) Edit /etc/bluetooth/audio.conf and uncomment the following line:

AutoConnect=true
  1. Run the following command to install latest packages for blueman and related modules:

    sudo add-apt-repository ppa:blueman/ppa

    sudo apt-get update

    sudo apt-get upgrade blueman enter code here

(3.) Check if the following lines are added in /etc/pulse/default.pa:

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

If not, add the lines.

REBOOT!

  1. Run the new blueman-applet.

Right click on the panel applet and turn bluetooth on. The old profie of you bluetooth device would still be there, remove it. Right click on the blueman-panel applet and select Setup New Device. Complete the wizard for your device.(If you have problems with “pairing” restart your system and skip this step!)

Now you get a connected bluetooth device!

To send/hear audio over it just follow these 2 steps:

  • Open Mate-volume control-settings (or pavucontrol) with rightclick in taskbar, browse to “HARDWARE” - and use the dropdown to turn the Built-in audio profiles of all other soundcards “off”

  • so that the bluetooth-device gets active!

  • use the other dropdown to set the bluetooth device to use A2DP

Now start the totem-player or vlc (with pulseaudio-output) to send audio to bluetooth!

Enjoy your sound! ;-)

WLAN-ISSUES:

——————–— In case you see a WiFi connection drop after connecting to the bluetooth device run the following command:

$ echo “options iwlwifi 11n_disable=1 bt_coex_active=0 power_save=0 auto_agg=0 swcrypto=1” |
sudo tee -a /etc/modprobe.d/iwlwifi.conf > /dev/null

tested 2017 for LM 17.3 (Rosa) MATE and Ubuntu 14.04 by chalee:

http://mayastudio.tumblr.com/bluetooth

like image 29
chalee Avatar answered Sep 20 '22 19:09

chalee