A2DP sink without pulseaudio - linux

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?

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.

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
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.
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
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!
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

My guess is that your audio path isn't routing the bluetooth to your speakers. I have seen similar issue, which was fixed by manually doing step 5 "Connect PulseAudio bluetooth source to PulseAudio ALSA sink" from this link: http://jprvita.wordpress.com/2009/12/15/1-2-3-4-a2dp-stream/

I just tried to do the same thing, I'm using Fedora 19, so your mileage my vary. These are the steps I took.
Made computer discoverable
Pair phone to computer (it had a headphone logo next to it)
On my HTC phone I clicked "connect" on the pairing
Go into gnome3's sound settings
Go to the input tab
Select the bluetooth item for your phone
Maybe adjust volume...

Related

how to give permission to intel realsense camera on Ubuntu

OS:Ubuntu 18.04
camera: Intel realsense D415
I can use cheese to show the compound image of the camera. But when I run
import pyrealsense2 as rs
pipeline = rs.pipeline()
pipeline.start()
It throws out error access failed for 8086:ad6 uid: 1-1-12
Is anyone that knows how to solve this? Thanks!
You need to install Intel Realsense permission scripts located in librealsense source directory.
For that, first, git clone the librealsense to a local folder
git clone https://github.com/IntelRealSense/librealsense
Next, run the following commands to copy the 99-realsense-libusb.rules files to the rules.d folder
sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
And, then udevadm control to modify the internal state of the running udev dameon to reload rules. Also, udevadm trigger to request device events from the kernel.
sudo udevadm control --reload-rules
sudo udevadm trigger
Update: I recently faced the Runtime error: backend-v412.cpp:988 - Frames didn't arrived within 5 seconds. Seems like the pipeline is not able to handle the framebuffers, and there is quite a lot of drop in the frames, specifically above 720p, 15 frames/sec.
Any resolutions?
Update 2:
Resolution: As suspected it is a pipelining issue w.r.t the amount of the data the USB port can carry. To prevent frame drop or overload of data through the USB, it has to be connected to a Motherboard that has USB 3.1 Gen 1 specifications. Refer to page 78 of this document https://www.intelrealsense.com/wp-content/uploads/2020/06/Intel-RealSense-D400-Series-Datasheet-June-2020.pdf

How to automatically run 'sudo modprobe -r ftdi_sio' whenever the device is plugged into my computer

I have a USB device that I'm using and I'm developing an application using WebUSB with Google Chrome.
The thing is whenever I plug the USB device into my Linux computer, I have to manually run sudo modprobe -r ftdi_sio to unload it.
I want it to be unloaded automatically whenever I plug that device into my computer instead of having to type it manually every single time.
Any ideas on how this could be implemented ? Help would be much appreciated
One option would be to "blacklist" the ftdi_sio module to stop it being loaded automatically. To do that create the following file:
/etc/modprobe.d/ftdi_sio-blacklist.conf
# This is a comment. Change it if you want.
blacklist ftdi_sio
Put your command in /etc/rc.local and restart. See if it works. Or you can find how other .ko are configured to automatically load during system startup. Follow the same to make your module load automatically.
The proper way is to create a udev rule that is triggered when the specific USB device is attached.
Create a file /etc/udev/rules.d/99-usb-load.rules, and replace the "7523" and "1a86" with the Product ID and Vendor ID of your USB device.
# For debugging if the rule is working
ACTION=="add", ENV{ID_MODEL_ID}=="7523", ENV{ID_VENDOR}=="1a86", RUN+="/bin/sh -c '/bin/echo inserted device >> /tmp/udev_file'"
ACTION=="remove", ENV{ID_MODEL_ID}=="7523", ENV{ID_VENDOR}=="1a86", RUN+="/bin/sh -c '/bin/echo removed device >> /tmp/udev_file'"
# Actual rules
ACTION=="add", ENV{ID_MODEL_ID}=="7523", ENV{ID_VENDOR}=="1a86", RUN+="/sbin/rmmod ftdi_sio"
ACTION=="remove", ENV{ID_MODEL_ID}=="7523", ENV{ID_VENDOR}=="1a86", RUN+=""
Restart the udev daemon
sudo /etc/init.d/udev restart
The add rule will be executed whenever the USB device with matching PID/VID is attached and it will unload the module ftdi_sio. The first two rules are for debugging purposes which write a line into /tmp/udev_file and can be used to verify if the rules has been triggered.
Looks like USB device is new and there are no existing drivers to handle as soon as it is plugged in. You need an interrupt line and a USB driver code for your requirement. You need to register your device to that driver and driver to the USB bus. Also need to write appropriate interrupt routines to be called as soon as your device is plugged in. This will make it work as you want !!
If you already have a .rules file for the USB device then append the following to the pre-existing file in the /etc/udev/rules.d/ directory. Otherwise, create a file in the /etc/udev/rules.d/ directory with the following content:
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ACTION=="add", RUN+="/sbin/rmmod ftdi_sio"
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6010", ACTION=="remove", RUN+=""
This means that when the device with vendorID 0403 and product ID 6010 is plugged in it runs /sbin/rmmod ftdi_sio which removes the ftdi_sio module. The second rule means nothing will be run when unplugged. See [writing udev rules] for more info on how to name the .rules file (e.g. 99-mydevice.rules)
You'll have to replace 0403 and 6010 with your device's vendor ID and prodcut ID. The vendor ID and product ID can be found by running lsusb on the command line after plugging in the USB device. It will have the format:
Bus xxx Device xxx: ID idVendor:idProduct ManufacturerName
After creating or editing the .rules file in /etc/udev/rules.d/ directory be sure to reload the .rules file with the following command:
sudo udevadm control --reload
Some further references on udev rules:
debian wiki
arch wiki
writing udev rules

Serial port unavaliable arduino

Trying to upload a code to arduino, but whether in the Arduino IDE or Arduino Create, both return this erro while uploading. Running on Linux Tara(mint 19 cinnamon).
./opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -hardware opt/arduino-builder/hardware -hardware ./opt/cores -tools opt/arduino-builder/tools -tools ./opt/tools -built-in-libraries opt/libraries/latest -logger humantags -fqbn arduino:avr:mega:cpu=atmega2560 -build-cache /tmp -build-path /tmp/716441957/build -verbose -libraries /tmp/716441957/custom -libraries /tmp/716441957/pinned /tmp/716441957/sketch_oct8a
Sketch uses 8280 bytes (3%) of program storage space. Maximum is 253952 bytes.
Global variables use 443 bytes (5%) of dynamic memory, leaving 7749 bytes for local variables. Maximum is 8192 bytes.
Programming with: Serial
Flashing with command:/home/jesus/.arduino-create/arduino/avrdude/6.3.0-arduino9/bin/avrdude -C/home/jesus/.arduino-create/arduino/avrdude/6.3.0-arduino9/etc/avrdude.conf -q -q -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/tmp/arduino-create-agent734074237/sketch_oct8a.hex:i
avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied
ioctl("TIOCMGET"): Inappropriate ioctl for device
ioctl("TIOCMGET"): Inappropriate ioctl for device
1#
First, check the port in your IDE. In Arduino tools->port
If the port is hidden or you can not move the cursor over this then run this commands in your terminal.If everything ok then skips this and follow the second part.
sudo apt-get install librxtx-java -y
sudo usermod -aG dialout $USER
sudo apt-get install gnome-system-tools
2#
After this again check the first method. If it is not working then run this commands
ls -l /dev/ttyACM*
sudo usermod -a -G dialout <username>
You probably have another program running which is already using this port.
You should close most other programs like putty or another serial monitor app.
Otherwise, try to reconnect the Arduino to the PC.
I know that these ideas below come from using a Teensy, but they may help you.
Sometimes there are the ACM* ports listed in the Arduino IDE. Try looking at the ser ports. I know when I am running my Teensy, sometimes I have them switched and need to select the correct one.
Also, from my experience with the Teensy, you might need to add a udev rule to allow permissions to access the port from non-root user. Here is the link that shows the udev file.
There is no direct way to solve this issue. In addition to it, you are not using an IDE. I will list the things you need to check, I am sure this will solve your problem.
I am not good at Linux environment so I will refer to applications names as window, you go the corresponding application in Linux.
Go to linux device manager and see for your arduino board. It should have proper naming like "arduino uno at port 3", then use the correct port in your command. If this name does not come properly then it means Driver is not available in your machine. So, go to step2.
Find the driver online and install it in your system, I am not sure about the support of linux with arduino, once it is done please repeat step1.
So, I conclude in short that you do not have the proper driver (which is strongly believe) or pointing the wrong port. I am not an expert with the udev rules, but it is definitely an issue you can experience with these kinds of micro-controllers.

Changing raspberry pi bluetooth device name?

I am trying to change a raspberry pi's bluetooth name to something else (an ip address) so that when I scan and pair my android device it will see this ip as the device name. It worked once but then went back to appearing as "raspberrypi-0"
I have tried both the hciconfig set name command, and have also changed the device name inside /etc/bluetooth/main.conf but still all my device sees is "raspberrypi-0". Its driving me crazy so if anyone knows what the issue is please help!
If you want to change the bluetooth device name permanently, you have to create a file called /etc/machine-info which should have the following content:
PRETTY_HOSTNAME=device-name
Then issue "service bluetooth restart" after that
#Evangelos Nannos answer still works (BlueZ 5.50) but if you want to change bluetooth alias on the fly you may try bluetoothctl (tested on Pi Zero W running Raspbian Stretch & BlueZ 5.50)
To set new alias open terminal:
pi#raspberrypi:~ $ bluetoothctl
[bluetooth]# system-alias 'Your New BT Alias'
Changing Your New BT Alias succeeded
[CHG] Controller AA:BB:CC:DD:EE:FF Alias: Your New BT Alias
Use show to see current bluetooth settings:
[bluetooth]# show
Controller AA:BB:CC:DD:EE:FF
Name: Some_other_name #default or as PRETTY_HOSTNAME
Alias: Your New BT Alias #alias will be shown when scanning for bt devices
(...)
Reset alias and go back to using system device name with:
[bluetooth]# reset-alias
Exit bluetootctl with:
[bluetooth]# quit
With Discoverable on (yes) the device will show up during scaning as Your New BT Alias.
Take note that alias will be kept after reboot!
I've use pexpect to manipulate bluetoothctl, bash works too. There were problems registering Agent on BlueZ 5.43 via pexpect, had to upgrade to 5.50
Alternative command (note it will not return a response):
pi#raspberrypi:~ $ sudo hciconfig hci0 name 'New device name'
It stores the display name in /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/config file. If you wants to change the bluetooth display(broadcast) name then you need to follow the below steps:
delete /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/config file.
Edit /etc/bluetooth/main.conf(For ex: Name=%d-%h to Name=abcd-5)
service bluetooth restart.
Note: If this already paired with some other BT devices, so you need to remove the pairing to see the new BT name of the same device(MAC).
You can also just disable the hostname plugin and configure the name.
Run sudo vim /etc/systemd/system/bluetooth.target.wants/bluetooth.service
and append --noplugin=hostname, like this:
ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=hostname
Then edit the bluetooth config and set your desired name:
sudo vim /etc/bluetooth/main.conf
Name = YourNewName
Just follow the below steps
step 1 - write below code in terminal
sudo nano /etc/machine-info
step 2 - It will open a blank file, Now write this line into it
PRETTY_HOSTNAME=PutYourDeviceNameHere
step 3 - Now restart Bluetooth service OR You can reboot Raspberry Pi
service bluetooth restart
OR
sudo reboot
Hope it's Work For you
Use hostnamectl command for change or set your bluetooth name.
hostnamectl --pretty set-hostname <PutYourDeviceNameHere>

Run command after mount/unmout usb pen drive

I have Raspberry Pi (with Raspbian) and using it as DLNA/UPnP server and renderer. I run minidlna as DLNA server and i have some media files on USB.
I would like to automaticaly rebuild DLNA DB when drive is mounted and unmounted. This is done by command:
sudo service minidlna force-reload
Is threre any way how to autorun this command?
BTW I use "USBmount" package for automount USB drives.
Thanx
You can do this using the tool usbmount.
It has the possibility to add scripts that will be run on mount/umount events in /etc/usbmount/mount.d/ and /etc/usbmount/umount.d/.
Start by finding your device in lsusb. Note the ID (eg 12f5:a91a)
Create a new udev rules file in /etc/udev/rules.d/ eg /etc/udev/rules.d/100-my-mount.rules and write a new rule in there like this:
ACTION=="add", ATTRS{idVendor}=="12f5", ATTRS{idProduct}=="a91a", RUN+="/home/your_username/bin/my-mount-script.sh"
For unmounted device use ACTION=="remove" in rule and another script.

Resources