GithubHelp home page GithubHelp logo

arkq / bluez-alsa Goto Github PK

View Code? Open in Web Editor NEW
825.0 45.0 184.0 3.03 MB

Bluetooth Audio ALSA Backend

License: MIT License

Makefile 1.27% M4 1.44% C 95.33% Shell 1.13% Python 0.83%
audio bluetooth alsa bluez linux a2dp hfp hsp ofono ble-midi

bluez-alsa's Introduction

Bluetooth Audio ALSA Backend

Build Status Code Coverage

About BlueALSA

This project is a rebirth of a direct integration between BlueZ and ALSA. Since BlueZ >= 5, the built-in integration has been removed in favor of 3rd party audio applications. From now on, BlueZ acts as a middleware between an audio application, which implements Bluetooth audio profile, and a Bluetooth audio device.

The current status quo is, that in order to stream audio from/to a Bluetooth device, one has to install a general-purpose audio server such as PipeWire or PulseAudio, or use BlueZ version 4 which is deprecated and unmaintained.

This project created and maintains a product called BlueALSA, with which one can achieve the same Bluetooth audio profile support as with PulseAudio, but with fewer dependencies and at a lower level in the software stack. BlueALSA registers all known Bluetooth audio profiles in BlueZ, so in theory every Bluetooth device (with audio capabilities) can be connected.

BlueALSA is designed specifically for use on small, low-powered, dedicated audio or audio/visual systems where the high-level audio management features of PulseAudio or PipeWire are not required. The target system must be able to function correctly with all its audio applications interfacing directly with ALSA, with only one application at a time using each Bluetooth audio stream. In such systems BlueALSA adds Bluetooth audio support to the existing ALSA sound card support. Note this means that the applications are constrained by the capabilities of the ALSA API, and the higher-level audio processing features of audio servers such as PulseAudio and PipeWire are not available.

BlueALSA consists of the daemon bluealsa, ALSA plug-ins, and a number of utilities. The basic context is shown in this diagram:

flowchart TD
classDef external fill:#eee,stroke:#333,stroke-width:4px,color:black;
classDef bluealsa fill:#bbf,stroke:#333,stroke-width:4px,color:black;

A[Bluetooth Adapter] <--> B((bluetoothd\ndaemon))
A <--> C((bluealsa daemon))
B <--> C
C <--> D((bluealsa-aplay))
D --> E([ALSA libasound])
E --> K[Speakers]
C <--> F((bluealsa\nALSA plug-ins))
C <--> G((bluealsa-cli))
F <--> H([ALSA libasound])
H <--> I((ALSA\napplications))
C <--> J((other\nD-Bus clients))
C <--> L((ALSA MIDI\nsequencer))
L <--> M([ALSA libasound])
M <--> N((ALSA MIDI\napplication))

class A,B,E,H,I,J,K,L,M,N external;
class C,D,F,G bluealsa;

The heart of BlueALSA is the daemon bluealsa which interfaces with the BlueZ Bluetooth daemon bluetoothd and the local Bluetooth adapter. It handles the profile connection and configuration logic for A2DP, HFP and HSP and presents the resulting audio streams to applications via D-Bus.

BlueALSA includes ALSA plug-ins which hide all the D-Bus specifics and permit applications to use the ALSA PCM and mixer interfaces, so that existing ALSA applications can access Bluetooth audio devices in the same way as they use sound card PCMs and mixers.

In case of BLE MIDI, the daemon creates a simple MIDI port directly in ALSA MIDI sequencer, so that ALSA MIDI application can connect to the remote BLE MIDI device in the same way as it would connect to a local MIDI device.

BlueALSA also includes a number of utility applications. Of particular note are:

  • bluealsa-aplay
    an application to simplify the task of building a Bluetooth speaker using BlueALSA.

  • bluealsa-cli
    an application to allow command-line management of the BlueALSA system.

  • bluealsa-rfcomm
    a command-line application which provides access to the RFCOMM terminal for HFP/HSP devices.

Installation

Build and install instructions are included in the file INSTALL.md and more detailed guidance is available in the wiki.

Usage

bluealsa daemon

The main component of BlueALSA is a program called bluealsa. By default, this program shall be run as a root during system startup. It will register org.bluealsa service in the D-Bus system bus, which can be used for accessing configured audio devices. In general, BlueALSA acts as a proxy between BlueZ and ALSA.

The bluealsa daemon must be running in order to pair, connect, and use remote Bluetooth audio devices. In order to stream audio to e.g. a Bluetooth headset, firstly one has to connect the device. If you are not familiar with the Bluetooth pairing and connecting procedures on Linux, there is a basic guide in the wiki: Bluetooth pairing and connecting.

For details of command-line options to bluealsa, consult the bluealsa manual page.

ALSA plug-ins

When a Bluetooth audio device is connected one can use the bluealsa virtual PCM device with ALSA applications just like any other PCM device:

aplay -D bluealsa Bourree_in_E_minor.wav

If there is more than one Bluetooth device connected, the target one can be specified as a parameter to the PCM:

aplay -D bluealsa:XX:XX:XX:XX:XX:XX, Bourree_in_E_minor.wav

Please note that this PCM device is based on the ALSA software PCM I/O plug-in - it has no associated sound card, and it will not be available in the ALSA Kernel proc interface.

Setup parameters of the bluealsa PCM device can be set in the local .asoundrc configuration file like this:

cat ~/.asoundrc
defaults.bluealsa.service "org.bluealsa"
defaults.bluealsa.device "XX:XX:XX:XX:XX:XX"
defaults.bluealsa.profile "a2dp"
defaults.bluealsa.delay 10000

BlueALSA also allows to capture audio from the connected Bluetooth device. To do so, one has to use the capture PCM device, e.g.:

arecord -D bluealsa -f s16_le -c 2 -r 48000 capture.wav

In addition to A2DP profile, used for high quality audio, BlueALSA also allows to use phone audio connection via SCO link. One can use either built-in HSP/HFP support, which implements only audio related part of the specification, or use oFono service as a back-end. In order to open SCO audio connection one shall switch to sco profile like follows:

aplay -D bluealsa:DEV=XX:XX:XX:XX:XX:XX,PROFILE=sco Bourree_in_E_minor.wav

In order to control input or output audio level, one can use provided bluealsa control plug-in. This plug-in allows adjusting the volume of the audio stream or simply mute/unmute it, e.g.:

amixer -D bluealsa sset '<control name>' 70%

where the control name is the name of a connected Bluetooth device with a control element suffix, e.g.:

amixer -D bluealsa sset 'Jabra MOVE v2.3.0 A2DP' 50%

For full details of the BlueALSA ALSA PCM device and mixer device consult the BlueALSA plug-ins manual page.

There are also a number of articles on the bluez-alsa project wiki giving more examples of using these plug-ins.

For more advanced ALSA configuration, consult the asoundrc on-line documentation provided by the AlsaProject wiki page.

bluealsa-aplay

It is possible to create Bluetooth-powered speaker using BlueALSA. For this it is required to forward the audio signal from the BlueALSA capture PCM to some other playback PCM (e.g. built-in audio card). In order to simplify this task, BlueALSA includes a program called bluealsa-aplay, which acts as a simple BlueALSA player. Connect your Bluetooth device (e.g. smartphone) and do as follows:

bluealsa-aplay XX:XX:XX:XX:XX:XX

For details of command-line options to bluealsa-aplay, consult the bluealsa-aplay manual page. There are also some articles on the bluez-alsa project wiki giving examples of its use.

The list of available BlueALSA PCMs (provided by connected Bluetooth devices with audio capabilities) can be obtained directly from BlueALSA D-Bus API or using bluealsa-aplay as a convenient wrapper as follows:

bluealsa-aplay -L

Contributing

This project welcomes contributions of code, documentation and testing.

Please see the CONTRIBUTING guide for details.

Bug reports, feature requests, and requests for help

The most commonly encountered errors are discussed in the TROUBLESHOOTING guide. Please check that file to see if there is already a solution for your issue.

If you are unable to find a solution in that document or by reading the manual pages, then please search previous issues (both open and closed), and consult the wiki before raising a new issue. Unfortunately the wiki is not indexed by web search engines, so searching on-line for your issue will not discover the information in there.

If reporting a problem as a new issue, please use the appropriate bluez-alsa GitHub issue reporting template and complete each section of the template as fully as possible.

License

BlueALSA is licensed under the terms of the MIT license. See the LICENSE file for details.

Resources

  1. Bluetooth Adopted Specifications
  2. Bluetooth LE MIDI Specification
  3. Bluetooth Design Guidelines
  4. RTP Payload Format for MPEG-4
  5. Coding of MPEG-4 Audio
  6. ALSA project library reference

bluez-alsa's People

Contributors

anonymix007 avatar arkq avatar borine avatar csch10 avatar gioele avatar graham8 avatar guillaumezin avatar jc-kynesim avatar joerg-krause avatar juyrjola avatar kempniu avatar liuming50 avatar paul-1 avatar sgn avatar tassig avatar w0xel avatar wberrier avatar xyzzy42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bluez-alsa's Issues

Record from bluetooth device

Do you know if it's possible to use arecord together with bluealsa? I managed to fix the problem from #6 by disabling pulseaudio-bluetooth and can now play music through my bluetooth headset with aplay, but arecord still gives me the same error. Would I have to set different parameters for device input than for output?

Again I try to provide a full log.

My /etc/asound.conf contains:

defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "E4:22:A5:08:7B:FF"
defaults.bluealsa.profile "a2dp"

So let's start from a freshly booted system (# indicates root, ~ indicates user):

# systemctl start bluetooth
# bluealsa

Output so far:

bluealsa: ctl.c:353: Starting controller loop
bluealsa: bluez.c:677: Registering endpoint: 0000110A-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DP_MPEG24_Source
bluealsa: bluez.c:677: Registering endpoint: 0000110A-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DPSource
bluealsa: bluez.c:677: Registering endpoint: 0000110B-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DP_MPEG24_Sink
bluealsa: bluez.c:677: Registering endpoint: 0000110B-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DPSink
bluealsa: bluez.c:893: Registering profile: 00001108-0000-1000-8000-00805F9B34FB: /Profile/HSPHeadset
bluealsa: bluez.c:893: Registering profile: 00001112-0000-1000-8000-00805F9B34FB: /Profile/HSPAudioGateway
bluealsa: main.c:202: Starting main dispatching loop

Going on:

# bluetoothctl
> power on
> connect E4:22:A5:08:7B:FF

New output:

bluealsa: bluez.c:846: Profile method call: org.bluez.Profile1.NewConnection()
bluealsa: bluez.c:778: HSP Audio Gateway configured for device E4:22:A5:08:7B:FF
bluealsa: transport.c:399: State transition: 0 -> 2
bluealsa: transport.c:91: Created new IO thread: HSP Audio Gateway
bluealsa: io.c:960: Starting IO loop: HSP Audio Gateway
bluealsa: io.c:994: AT command: +VGS=08
bluealsa: io.c:994: AT command: +VGM=15
bluealsa: bluez.c:482: Endpoint method call: org.bluez.MediaEndpoint1.SelectConfiguration()
bluealsa: bluez.c:482: Endpoint method call: org.bluez.MediaEndpoint1.SetConfiguration()
bluealsa: bluez.c:416: A2DP Source (SBC) configured for device E4:22:A5:08:7B:FF
bluealsa: bluez.c:418: Configuration: channels: 2, sampling: 48000
bluealsa: transport.c:399: State transition: 0 -> 0

Headset tells me "PC connected".

Going on:

~ pactl list | grep Legend

no output, nice.

aplay -D bluealsa applause.wav

Gives the following output and plays the applause in my ear:

bluealsa-pcm.c:101: Getting transport for E4:22:A5:08:7B:FF profile 1
bluealsa-pcm.c:502: Setting constraints
Playing WAVE 'applause.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Warning: rate is not accurate (requested = 44100Hz, got = 48000Hz)
         please, try the plug plugin (-Dplug:bluealsa)
bluealsa-pcm.c:337: Initializing HW
bluealsa-pcm.c:137: Requesting PCM open for E4:22:A5:08:7B:FF
bluealsa-pcm.c:154: Opening PCM FIFO (mode: WR): /var/run/bluealsa/hci0-E4:22:A5:08:7B:FF-1
bluealsa-pcm.c:355: FIFO buffer size: 4096
bluealsa-pcm.c:359: Selected HW buffer: 23 periods x 4096 bytes
bluealsa-pcm.c:390: Prepared
bluealsa-pcm.c:296: Starting
bluealsa-pcm.c:238: Starting IO loop
^CAborted by signal Interrupt...
aplay: pcm_write:2004: write error: Interrupted system call
bluealsa-pcm.c:311: Stopping
bluealsa-pcm.c:366: Freeing HW
bluealsa-pcm.c:182: Closing PCM for E4:22:A5:08:7B:FF
bluealsa-pcm.c:327: Closing plugin

And then:

arecord -d 3 -D bluealsa test.wav

Gives the output:

bluealsa-pcm.c:101: Getting transport for E4:22:A5:08:7B:FF profile 2
ALSA lib bluealsa-pcm.c:619:(_snd_pcm_bluealsa_open) Couldn't get BlueALSA transport: No such device
arecord: main:786: audio open error: No such device

On the bluealsa output we now have the new output (for both aplay and arecord, I forgot to split them...):

bluealsa: ctl.c:411: New client accepted: 8
bluealsa: ctl.c:414: +-+-
bluealsa: ctl.c:414: +-+-
bluealsa: ctl.c:226: PCM requested for E4:22:A5:08:7B:FF profile 1
bluealsa: transport.c:481: New transport: 10 (MTU: R:672 W:672)
bluealsa: ctl.c:414: +-+-
bluealsa: bluez.c:990: Signal: PropertiesChanged: org.bluez.MediaTransport1
bluealsa: transport.c:399: State transition: 1 -> 2
bluealsa: transport.c:91: Created new IO thread: A2DP Source (SBC)
bluealsa: io.c:71: Opening FIFO for reading: /var/run/bluealsa/hci0-E4:22:A5:08:7B:FF-1
bluealsa: io.c:448: Starting IO loop: A2DP Source (SBC)
bluealsa: transport.c:616: Cleaning PCM FIFO: /var/run/bluealsa/hci0-E4:22:A5:08:7B:FF-1
bluealsa: transport.c:623: Closing PCM: 11
bluealsa: transport.c:528: Releasing transport: A2DP Source (SBC)
bluealsa: transport.c:556: Closing BT: 10
bluealsa: io.c:61: Exiting IO thread
bluealsa: ctl.c:414: +-+-
bluealsa: bluez.c:990: Signal: PropertiesChanged: org.bluez.MediaTransport1
bluealsa: transport.c:399: State transition: 0 -> 0
bluealsa: ctl.c:385: Client closed connection: 8
bluealsa: ctl.c:414: +-+-
bluealsa: ctl.c:411: New client accepted: 8
bluealsa: ctl.c:414: +-+-
bluealsa: ctl.c:414: +-+-
bluealsa: ctl.c:385: Client closed connection: 8
bluealsa: ctl.c:414: +-+-

Huge delay

Hey!
With my device I'm experimenting a big delay. I have no idea who's to blame to be fair, but I suspect bluealsa might have a lot to do. Taking a look at the delay function it makes me shiver to find a harcoded big number there :D
I did some testing by removing it but not much of a difference to be far! Any ideas?
Also it seems that the device doesn't get exposed in any of the usual ALSA Apis like /proc/asound/cards although "aplay -L" does show it. Is it because the device has to be manually specifed as opposed to "discovered"?
Thanks again and let me know if you need some help!

bluealsa-aplay - no transport: invalid argument

Hi

Based on fresh download todfay. Using:

arecord -f cd -D bluealsa | aplay
Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

Works fine. However

bluealsa-aplay E4:CE:8F:92:67:80 -d hw:0,0 -v // or any variant of
Selected configuration:
HCI device: hci0
PCM device: hw:0,0
PCM buffer time: 500000 us
PCM period time: 100000 us
Bluetooth device: E4:CE:8F:92:67:80
Profile: A2DP
bluealsa-aplay: ../../utils/../src/shared/ctl-client.c:102: Connecting to socket: /var/run/bluealsa/hci0
bluealsa-aplay: ../../utils/../src/shared/ctl-client.c:197: Getting transport for E4:CE:8F:92:67:80 type 1
bluealsa-aplay: Couldn't get BlueALSA transport: Invalid argument

E4:CE:8F:92:67:80 is the iphone I was just using with the previous command. I've also tried this command before the above, restarted things in various sequences still the same the error.
Any idea what the "invalid" argument is?

MPD hardware mixer problem

audio_output {
type "alsa"
name "Bluetooth Speaker"
device "bluealsa:HCI=hci0,DEV=11:22:33:44:55:66,PROFILE=a2dp"
mixer_type "software"
}

Working config.

amixer -D bluealsa:HCI=hci0 sset 'MS425 - A2DP' 100% # loud

amixer -D bluealsa:HCI=hci0 sset 'MS425 - A2DP' 5% # quiet

Looks like there is a hardware mixer.

audio_output {
type "alsa"
name "Bluetooth Speaker"
device "bluealsa:HCI=hci0,DEV=11:22:33:44:55:66,PROFILE=a2dp"
mixer_type "hardware"
mixer_device "bluealsa:HCI=hci0"
mixer_control "MS425 - A2DP"
}

Results in mpd.log

mpd: control.c:223: snd_ctl_poll_descriptors: Assertion `ctl && pfds' failed.
Dec 21 23:44 : zeroconf: No global port, disabling zeroconf
(...)

Debian Strech x64, MPD git, BlueZ 5.43, ALSA 1.1.2, BlueALSA git

Reported to MPD bugtracker. Reply was "An assertion failure is always a bug in the code which raises the failure. This "control.c" file is not part of MPD, thus this is not a MPD bug." Any help?

Workaround for missing libasound_module_pcm_bluealsa.so and other..

Hi,

I have cross-compiled bluealsa for a NXP imx7 and it sort-of runs... I have a couple of questions.

  1. You mentioned in one reply that bluealsa acts as another sound card, is this correct?
  2. This being the case if I want to use my imx7 as a BT speaker I have to link basically link two sound cards together via arecord of similar ( bluealsa <=> aplay )?
  3. If the last answer is yes is there any way to modify blueasla itself to use hw:0,0 directly?
  4. Tying arecord as suggested by another post I get an error message of a missing library: libasound_module_pcm_bluealsa.so. The Yocto version and Bluez5 version I use no longer builds or includes this library. Any suggestions?

So far with other applications on this processor I have got away from using pulseaudio and getting BT to use only alsa via bluez5 would be great. My BT audio ( my board as sink ) works well with pulseaudio, but is has limited resources hence wanting to use bluealse.

Thanks.

Record from bluetooth device(android-phone) via a2dp

I managed to porting bluez-alsa to my platform compiled by uclibc, and have fixed several errors.
can now play music through my bluetooth headset with aplay via a2dp using bluez-5.28 and alsa-lib1.0.28, but arecord still gives me the same error when connecting with android-phone via a2dp.

I tried to provide a full log.

My /etc/asound.conf contains:
defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "C4:07:2F:96:FD:4D"
defaults.bluealsa.profile "a2dp"

then start bluealsa and connect android phone through bluetoothctl,
the output so far
ctl.c:483: Starting controller loop
bluez.c:699: Registering endpoint: 0000110A-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DPSource
bluez.c:699: Registering endpoint: 0000110B-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DPSink
main.c:218: Starting main dispatching loop
bluez.c:504: Endpoint method call: org.bluez.MediaEndpoint1.SelectConfiguration()
bluez.c:504: Endpoint method call: org.bluez.MediaEndpoint1.SetConfiguration()
bluez.c:438: A2DP Sink (SBC) configured for device C4:07:2F:96:FD:4D
bluez.c:440: Configuration: channels: 1, sampling: 44100
transport.c:603: State transition: 0 -> 0

amixer -D bluealsa

Simple mixer control 'HUAWEI MT7-TL10 - A2DP',0
Capabilities: cvolume cvolume-joined cswitch cswitch-joined
Capture channels: Mono
Limits: Capture 0 - 127
Mono: Capture 127 [100%] [on]

arecord -f S16_LE -c 1 -r 44100 -D bluealsa:HCI=hci0,DEV=C4:07:2F:96:FD:4D,P
ROFILE=a2dp /media/sdcard/test.wav

/bluez.c:1039: Signal: PropertiesChanged: org.bluez.MediaTransport1
transport.c:603: State transition: 0 -> 1
transport.c:695: New transport: 9 (MTU: R:672 W:1008)
bluez.c:1039: Signal: PropertiesChanged: org.bluez.MediaTransport1
transport.c:603: State transition: 1 -> 2
transport.c:95: Created new IO thread: A2DP Sink (SBC)
src/io.c:287: Starting IO loop: A2DP Sink (SBC)
src/io.c:290: io_thread_a2dp_sink_sbc
src/io.c:290: io_thread_a2dp_sink_sbc
src/io.c:307: before read
src/io.c:324: befor io_thread_open_pcm_write
io.c:86: Opening FIFO for writing: /var/run/bluealsa/hci0-C4:07:2F:96:FD:4D-1-1
bluealsa-pcm.c:104: Starting IO loop
io.c:290: io_thread_a2dp_sink_sbc
io.c:307: before read
io.c:324: befor io_thread_open_pcm_write
io.c:290: io_thread_a2dp_sink_sbc
io.c:307: before read
io.c:324: befor io_thread_open_pcm_write
io.c:290: io_thread_a2dp_sink_sbc
io.c:307: before read
io.c:324: befor io_thread_open_pcm_write
io.c:290: io_thread_a2dp_sink_sbc
io.c:307: before read
io.c:324: befor io_thread_open_pcm_write
arecord: pcm_read:2031: read error: No such device
bluealsa-pcm.c:249: Stopping
bluealsa-pcm.c:314: Freeing HW
ctl-client.c:348: Closing PCM for C4:07:2F:96:FD:4D
ctl.c:392: PCM close for C4:07:2F:96:FD:4D type 1 stream 1
src/transport.c:848: Cleaning PCM FIFO: /var/run/bluealsa/hci0-C4:07:2F:96:FD:4D-1-1
transport.c:855: Closing PCM: 12
bluealsa-pcm.c:265: Closing plugin
bluez.c:1039: Signal: PropertiesChanged: org.bluez.MediaTransport1
transport.c:603: State transition: 2 -> 0
transport.c:721: Releasing transport: A2DP Sink (SBC)
transport.c:749: Closing BT: 9
io.c:55: Exiting IO thread

At this point test.wav is only 44Bytes. I am stopped at "arecord: pcm_read:2031: read error: No such device"
Can I try or post anything else to help?

Loss of frames with pjsip

Hello and TIA for good work!

I try to use pjsua (SIP application) from pjsip library with latest version of bluez-alsa (SCO profile).

The sound always interrupt, the conversation example here. I have some suspicions with incorrect buffer length of the buffer or drop the buffer before it finish.

The CPU load for pjsua is about 10% and 5% for bluez-alsa. So the problem is not performance.

aplay works fine on the same system with bluez-alsa, pjsua also works fine on the same system with PulseAudio.

How to debug and fix this error?

If to set pcm->frame_size to 15 bytes (calculated as 16) in bluealsa_hw_params function, the sound is almost continuous, but cracks appear.

Adding mSBC mode into HFP

Great piece of software! I am currently working on integrating this into our product in lieu of pulseaudio due to former's excessive CPU usage with BT audio.

I am enhancing the HFP support by adding more AT command handling (some headsets drop the connection if the standard handshake is not followed) and by adding mSBC support.

Before I dive in to the mSBC I wanted to ask if you have thought about how to best implement it? The problematic detail is that the codec negotiation happens in the RFCOMM thread but the information needs to go to both the SCO IO thread and into the control thread since the sampling rates differ between CVSD and mSBC.

I could either delay the creation of the accompanying SCO transport until the codec has been decided upon, or add a more complex logic, maybe a fifo instead of the eventfd to pass more complex communications between the threads.

There is also a race condition where the plugin may attempt to grab the SCO transport before the AT negotiation has finished, this leads me to prefer delaying the creation of the SCO IO thread.

Thoughts?

bad sound with VLC

Hi,
i got that nice thing working. But with VLC, there is a problem with the sound, its very bad, constantly interrupted. If i take a look at the VLC-console-output, i know why:

bluealsa-pcm.c:243: Starting IO loop
bluealsa-pcm.c:340: Stopping
bluealsa-pcm.c:425: Prepared
bluealsa-pcm.c:319: Starting
bluealsa-pcm.c:243: Starting IO loop
bluealsa-pcm.c:340: Stopping
bluealsa-pcm.c:425: Prepared
bluealsa-pcm.c:340: Stopping
bluealsa-pcm.c:340: Stopping

The plugin seems to be constantly started and stopped by vlc. VLC is using the default-alsa device.
That is my .asoundrc:

pcm.btspeaker {
 type plug
  slave {
    pcm {
      type bluealsa
      interface hci0
      device 88:C6:26:C2:76:35
      profile "a2dp"
    }
  }
  hint {
    show on
    description "BT Headset"
  }
}

pcm.!default {
    type plug
    slave.pcm "btspeaker"
}
ctl.!default {
	type hw
	card 0
}

cannot set volume - no controls listed by amixer

Hi!
first of all, thanks a lot for this, i am a true pulseaudio hater and am trying hard to keep it that way :)
amixer -D bluealsa controls
doesn't return anything except:
bluealsa: ctl.c:411: New client accepted: 8
bluealsa: ctl.c:414: +-+-
bluealsa: ctl.c:414: +-+-
bluealsa: ctl.c:414: +-+-
bluealsa: ctl.c:385: Client closed connection: 8
bluealsa: ctl.c:414: +-+-
in bluealsa daemon
also the volume setting command is not working as it can't find the control:
[liviud@devbox ~]$ amixer -D bluealsa sset 'Bose SoundLink Mobile speaker II - A2DP' 50%
amixer: Unable to find simple control 'Bose SoundLink Mobile speaker II - A2DP',0

Address-less BT speaker sink & volume control via phone

Hello,
Using an Arm cross-compiled bluesalsa build things are working on my platform as expected. However as it is a BT speaker changing the address to suit the client sending music each time is not practical.

  1. Is there a way to automatically connect to any address? I need to get this to act the same as a normal BT speaker, pair, connect from any device => render music without any intervention on the speaker side.

  2. This may be a long-shot but is there any way for the volume to be adjusted via the phone/tablet?
    Currently I'm using: arecord -f cd -D bluealsa | aplay.

Cheers.

Alsa config

Hi @arkq

To begin, thank you very very much, your help my life with my alsa problem and bluez5.

I created systemd (debian) daemon and It's work. When I do aplay -D bluealsa:HCI=hci0,DEV=00:0C:8A:6B:8E:BD,PROFILE=a2dp applause.wav I listen my song ( but the first second is croped, but is not the problem here ;) )

Now, i want to config bluealsa with my alsa config.

Without bluealsa, my default config is

# Adapted via http://stackoverflow.com/a/14398926/6268583
#
# Enceinte
pcm.dmixed {
    type dmix
    ipc_key 1024
    ipc_key_add_uid 0
    ipc_perm 0666     # mixing for all users
    slave.pcm "hw:1,0"
}
# Micro
pcm.dsnooped {
    type dsnoop
    ipc_key 1025
    slave.pcm "hw:1,0"
}

pcm.duplex {
    type asym
    playback.pcm "dmixed"
    capture.pcm "dsnooped"
}

# Instruct ALSA to use pcm.duplex as the default device
pcm.!default {
    type plug
    slave.pcm "duplex"
}

# tell ALSA to use hw:0 to control the default device (alsamixer and so on)
ctl.!default {
    type hw
    card 0
}

I use dmixed and duplex, because sometimes I have 2 song started together, all explication is here

Now in my ~/.asoundrc when I copy/past our explication code

cat ~/.asoundrc
defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "00:0C:8A:6B:8E:BD"
defaults.bluealsa.profile "a2dp"

and start aplay applause.wav I don't have a error msg and another, but I doesn't listen my song in my speaker that listened with aplay -D bluealsa:HCI=hci0,DEV=00:0C:8A:6B:8E:BD,PROFILE=a2dp applause.wav

And When I would like to change my pcm.dmixed to replace slave.pcm "hw:1,0" by

defaults.bluealsa {
    interface "hci0"
    device "00:0C:8A:6B:8E:BD"
    profile "a2dp"
}

it isn't work, I have

pi@raspberrypi:~ $ aplay applause.wav
ALSA lib pcm_direct.c:1699:(snd1_pcm_direct_parse_open_conf) Unknown field defaults
aplay: main:722: audio open error: Invalid argument

I have the same problem if I delete defaults , it return me ALSA lib pcm_direct.c:1699:(snd1_pcm_direct_parse_open_conf) Unknown field bluealsa

[Edit]
I try to follow a bluetooth config like here

pcm.dmixed {
    type dmix
    ipc_key 1024
    ipc_key_add_uid 0
    ipc_perm 0666     # mixing for all users
    # A adapter en fonction de la config de reconnaissance
    # par Pi, il se peut que l'ordre ne soit pas le m  me
    slave.pcm {
        type bluealsa
        interface "hci0"
        device "00:0C:8A:6B:8E:BD"
        profile "a2dp"
    }
}

But already a problem the answer is ALSA lib pcm_direct.c:1524:(_snd_pcm_direct_get_slave_ipc_offset) Invalid type 'bluealsa' for slave PCM
[/Edit]

And to finish, I don't config amixer with your explication

pi@raspberrypi:~ $ amixer -D bluealsa '00:0C:8A:6B:8E:BD' sset 70%
amixer: Unknown command '00:0C:8A:6B:8E:BD'...
pi@raspberrypi:~ $ amixer -D bluealsa '<00:0C:8A:6B:8E:BD>' sset 70%
amixer: Unknown command '<00:0C:8A:6B:8E:BD>'...
pi@raspberrypi:~ $ amixer -D bluealsa 00:0C:8A:6B:8E:BD sset 70%
amixer: Unknown command '00:0C:8A:6B:8E:BD'...
pi@raspberrypi:~ $ amixer -D bluealsa "00:0C:8A:6B:8E:BD" sset 70%
amixer: Unknown command '00:0C:8A:6B:8E:BD'...
pi@raspberrypi:~ $ amixer -D bluealsa "DEV=00:0C:8A:6B:8E:BD" sset 70%
amixer: Unknown command 'DEV=00:0C:8A:6B:8E:BD'...

Thanks again

AAC payload fragmentation

If the size of the RTP packet exceeds writing MTU, the RTP payload should be fragmented. According to the RFC 3016, fragmentation of the audioMuxElement requires no extra header - the payload should be fragmented and spread across multiple RTP packets. However, such an implementation seems not to work correctly.

Any help will be much appreciated.

buffer_size and period_size options for bluealsa-aplay

Hello,

I'm using bluez-alsa to use my Raspberry PI 3 with sound card as headless bluetooth speaker for my videprojector.

Currently, I redirect sound of bluetooth to sound card with a command combination looking like arecord ... | aplay ... --buffer-time=100000

I tried to replace it with bluealsa-aplay but the buffer is bigger and I feel latency between video and sound. Would it be possible to add option like --buffer-time / --buffer-size / --period-time / --period-size to bluealsa-aplay ?

Or do you know how to put this value on hw PCM with ALSA ? I see in the code that you inherit values from PCM parameters, but I didn't manage to change them in my /etc/asound.conf.

Thank you.

Guillaume

Possible to have 2 headsets in .asoundrc?

This is not a bug a mere question.
I have 2 different pairs of bluetooth loudspeakers, They both work independently, but right now my .asoundrc looks like this:

# defaults.bluealsa {
#     interface "hci0"
#     device "43:25:03:FF:D5:BF"
#     profile "a2dp"
# }
defaults.bluealsa {
    interface "hci0"
    device "00:E0:4C:E3:44:4F"
    profile "a2dp"
}

As of now, it's one or the other. I can use a script to change/exchange the file as needed, but was wondering if there was another way (e.g. maybe have one as hci1?). To clarify, I don't want to play both of them together, I just want to know if it is possible to declare the two of them without having to change the '.asoundrc' file.

But the way, thanks a lot for bluez-alsa!

How to use this with Firefox?

I want to directly apologize, I'm aware that this issue might be offtopic.

BlueALSA on its own is working great on my system, but to be really useful I would need a way to let it play html5 audio over Firefox. I was unable to find a alsa-configuration or tool support to get the sound of Firefox to the bluealsa plugin. Is there a known or coming solution for FF, or is that something that would need support in the browser?

bluealsa: Unsupported RTP payload type: 1

Hello,

I'm trying to use a raspberry as bluetooth speaker receiver. Currently, the sender is a Kubuntu 16.10 PC.

I launch on the RPi bluealsa then arecord -f cd -D bluealsa:HCI=hci0,DEV=00:21:4F:4E:08:46 toto.wav

I got this:

pi@Sejour ~/bluez-alsa $ sudo bluealsa
bluealsa: ctl.c:484: Starting controller loop
bluealsa: bluez.c:688: Registering endpoint: 0000110A-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DP_MPEG24_Source
bluealsa: bluez.c:688: Registering endpoint: 0000110A-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DPSource
bluealsa: bluez.c:688: Registering endpoint: 0000110B-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DP_MPEG24_Sink
bluealsa: bluez.c:688: Registering endpoint: 0000110B-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DPSink
bluealsa: bluez.c:924: Registering profile: 00001108-0000-1000-8000-00805F9B34FB: /Profile/HSPHeadset
bluealsa: bluez.c:924: Registering profile: 00001112-0000-1000-8000-00805F9B34FB: /Profile/HSPAudioGateway
bluealsa: bluez.c:924: Registering profile: 0000111E-0000-1000-8000-00805F9B34FB: /Profile/HFPHandsFree
bluealsa: bluez.c:924: Registering profile: 0000111F-0000-1000-8000-00805F9B34FB: /Profile/HFPAudioGateway
bluealsa: main.c:212: Starting main dispatching loop
bluealsa: bluez.c:493: Endpoint method call: org.bluez.MediaEndpoint1.SetConfiguration()
bluealsa: bluez.c:427: A2DP Sink (SBC) configured for device 00:21:4F:4E:08:46
bluealsa: bluez.c:429: Configuration: channels: 2, sampling: 44100
bluealsa: transport.c:548: State transition: 0 -> 0
bluealsa: bluez.c:1028: Signal: PropertiesChanged: org.bluez.MediaTransport1
bluealsa: transport.c:548: State transition: 0 -> 1
bluealsa: transport.c:632: New transport: 8 (MTU: R:672 W:672)
bluealsa: bluez.c:1028: Signal: PropertiesChanged: org.bluez.MediaTransport1
bluealsa: transport.c:548: State transition: 1 -> 2
bluealsa: transport.c:94: Created new IO thread: A2DP Sink (SBC)
bluealsa: io.c:330: Starting IO loop: A2DP Sink (SBC)
bluealsa: bluez.c:1028: Signal: PropertiesChanged: org.bluez.MediaTransport1
bluealsa: transport.c:548: State transition: 2 -> 0
bluealsa: transport.c:658: Releasing transport: A2DP Sink (SBC)
bluealsa: transport.c:686: Closing BT: 8
bluealsa: io.c:62: Exiting IO thread
bluealsa: bluez.c:1028: Signal: PropertiesChanged: org.bluez.MediaTransport1
bluealsa: transport.c:548: State transition: 0 -> 1
bluealsa: transport.c:632: New transport: 10 (MTU: R:672 W:672)
bluealsa: bluez.c:1028: Signal: PropertiesChanged: org.bluez.MediaTransport1
bluealsa: transport.c:548: State transition: 1 -> 2
bluealsa: transport.c:94: Created new IO thread: A2DP Sink (SBC)
bluealsa: io.c:330: Starting IO loop: A2DP Sink (SBC)
bluealsa: bluez.c:1028: Signal: PropertiesChanged: org.bluez.MediaTransport1
bluealsa: transport.c:548: State transition: 2 -> 0
bluealsa: transport.c:658: Releasing transport: A2DP Sink (SBC)
bluealsa: transport.c:686: Closing BT: 10
bluealsa: io.c:62: Exiting IO thread
bluealsa: bluez.c:1028: Signal: PropertiesChanged: org.bluez.MediaTransport1
bluealsa: transport.c:548: State transition: 0 -> 1
bluealsa: transport.c:632: New transport: 10 (MTU: R:672 W:672)
bluealsa: bluez.c:1028: Signal: PropertiesChanged: org.bluez.MediaTransport1
bluealsa: transport.c:548: State transition: 1 -> 2
bluealsa: transport.c:94: Created new IO thread: A2DP Sink (SBC)
bluealsa: io.c:330: Starting IO loop: A2DP Sink (SBC)
bluealsa: ctl.c:544: New client accepted: 8
bluealsa: ctl.c:547: +-+-
bluealsa: ctl.c:547: +-+-
bluealsa: ctl.c:326: PCM requested for 00:21:4F:4E:08:46 type 1 stream 1
bluealsa: ctl.c:547: +-+-
bluealsa: io.c:93: Opening FIFO for writing: /var/run/bluealsa/hci0-00:21:4F:4E:08:46-1-1
bluealsa: Unsupported RTP payload type: 1
bluealsa: Unsupported RTP payload type: 1
bluealsa: Unsupported RTP payload type: 1
bluealsa: Unsupported RTP payload type: 1
...

and toto.wav is empty (44 bytes).

Any idea?

Thank you

Default audio card

Hello!

Would you mind providing a bit more info on how making the device default system wide? I was playing around with /etc/asound.conf but setting a default bluetooth environment will lead to alsa trying to load libasound_module_pcm_bluetooth.so which obviously doens't exist in bluez 5.
I was wondering what exactly I should modify in my file in order to make it realize it's a bluealsa device:

pcm.btheadset {
type plug
slave {
pcm {
type bluetooth
device B8:BB:AF:E4:D3:61
profile "a2dp"
}
}
hint {
show on
description "[Samsung] Soundbar J-Series"
}
}
ctl.btheadset {
type bluetooth
}

Thanks for this great project! It's very interesting (I'm using it on the raspberry pi 3 BTW)

Aesthetic issue with volume levels

In this case an example is worth thousands of words.

The following is copied from my shell. I setup the volume with the first command, but strangely it get setup in a weird way (right channel goes to 100%) as shown in the output of the second command.
The third and forth are similar try.

However, it seems just an aesthetic problem as the two channels actually have the same volume.

I also tried to play around with volumes and apparently what is counts is in fact the "Front Right," that strangely is the one that appear messed up.

I am not sure bluealsa is at fault at all, it is well possible that is the hardware being weird?

% amixer -D bluealsa sset 'TREKZ Titanium by Af - A2DP' 10%
Simple mixer control 'TREKZ Titanium by Af - A2DP',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 127
  Mono:
  Front Left: Playback 13 [10%] [on]
  Front Right: Playback 13 [10%] [on]

% amixer -D bluealsa sget 'TREKZ Titanium by Af - A2DP'
Simple mixer control 'TREKZ Titanium by Af - A2DP',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 127
  Mono:
  Front Left: Playback 13 [10%] [on]
  Front Right: Playback 127 [100%] [on]

% amixer -D bluealsa sset 'TREKZ Titanium by Af - A2DP' 20%
Simple mixer control 'TREKZ Titanium by Af - A2DP',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 127
  Mono:
  Front Left: Playback 26 [20%] [on]
  Front Right: Playback 26 [20%] [on]

% amixer -D bluealsa sget 'TREKZ Titanium by Af - A2DP'
Simple mixer control 'TREKZ Titanium by Af - A2DP',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 127
  Mono:
  Front Left: Playback 26 [20%] [on]
  Front Right: Playback 127 [100%] [on]

Bluez-alsa with Alsaequal

I was trying hard this morning to make Bluez-alsa and Alsaequal to work together and I cant find a working solution.
Alsaequal is a big one for me so if you could try it out or simply explain why it cannot work I would appreciate.

Unknown field delay

arecord -D bluealsa:HCI=hci0,DEV=11:22:33:44:55:66,PROFILE=a2dp
ALSA lib ../../../src/asound/bluealsa-pcm.c:660:(_snd_pcm_bluealsa_open) Unknown field delay

Any help?

Multilib support (crash when starting Saints Row 4)

That might be a bit specific, but if it happens in that game it will happen with others as well. When I start this game it crashes. The related output in the console:

ALSA lib dlmisc.c:272:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/i386-linux-gnu/alsa-lib/libasound_module_pcm_bluealsa.so
AL lib: (EE) ALCplaybackAlsa_open: Could not open playback device 'default': No such device or address
*** BREAKPAD CRASH ***

Firefox did work just before, but the youtube tab was of course closed while trying the game. I have the .asoundrc from the FF-issue, plus the defaults.bluealsa.โ€ฆ lines from the readme to be able to control the volume via alsamixer -D bluealsa.

configure: WARNING: unrecognized options: --disable-thread-safety

$ ../configure --disable-thread-safety

results in

configure: WARNING: unrecognized options: --disable-thread-safety
configure: WARNING: *** alsa-lib >= 1.1.2 ***
configure: WARNING: Starting from alsa-lib 1.1.2, it is possible to enable
configure: WARNING: thread-safe API functions. Unfortunately, this feature
configure: WARNING: is not mature enough - software plugins may experience
configure: WARNING: random deadlocks (bluez-alsa PCM plugin is affected).
configure: WARNING: Either compile alsa-lib without this feature or export
configure: WARNING: LIBASOUND_THREAD_SAFE=0 while using bluealsa PCM.

Debian Stretch x64, BlueZ 5.43, ALSA 1.1.2

Root permission required

According to the README [1] is should be possible to run this as non root user as long as bluealsa can write to `/var/run/bluealsa``. I tried that with version 1.1.0 as user bluealsa but it fails not being able to initialize a thread.

 start-stop-daemon --start --exec /usr/bin/bluealsa --user bluealsa --group bluealsa --make-pidfile --pidfile /var/run/bluealsa/bluealsa.pid -- --disable-hsp
/usr/bin/bluealsa: Couldn't initialize controller thread: Permission denied
 * start-stop-daemon: failed to start `/usr/bin/bluealsa'
# grep bluealsa /etc/passwd
bluealsa:x:129:962:added by portage for bluez-alsa:/dev/null:/sbin/nologin
# grep bluealsa /etc/group 
bluealsa:x:962:

[1] root privileges are not required per se, the only requirement is a write access to /var/run/bluealsa

input sound issues

hi,

I've connected phone in Raspi via BT (bluetoothctl) while bluez-alsa service is running (great stuff!)
However, when I play music I cannot hear it in the Pi, nor I could find anyway to route the BT input into my audio card
Appreciate the help

bluealsa sounds garbled with LG HBS900 and Sony MDR-1RBT.

~> cat .asoundrc
defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "B8:AD:3E:01:6E:88"
defaults.bluealsa.profile "a2dp"
defaulta.bluealsa.delay 1000
~> aplay -D bluealsa /usr/share/sounds/freedesktop/stereo/dialog-error.oga 
../shared/ctl-client.c:102: Connecting to socket: /var/run/bluealsa/hci0
../shared/ctl-client.c:197: Getting transport for B8:AD:3E:01:6E:88 type 1
bluealsa-pcm.c:457: Setting constraints
Playing raw data '/usr/share/sounds/freedesktop/stereo/dialog-error.oga' : Unsigned 8 bit, Rate 8000 Hz, Mono
bluealsa-pcm.c:217: Initializing HW
../shared/ctl-client.c:286: Requesting PCM open for B8:AD:3E:01:6E:88
../shared/ctl-client.c:305: Opening PCM FIFO (mode: WR): /var/run/bluealsa/hci0-B8:AD:3E:01:6E:88-1-0
bluealsa-pcm.c:240: FIFO buffer size: 4096
bluealsa-pcm.c:246: Selected HW buffer: 23 periods x 4096 bytes == 94208 bytes
bluealsa-pcm.c:277: Prepared
bluealsa-pcm.c:161: Starting
../shared/ctl-client.c:374: Requesting PCM resume for B8:AD:3E:01:6E:88
bluealsa-pcm.c:85: Starting IO loop
bluealsa-pcm.c:283: Draining
bluealsa-pcm.c:190: Stopping
bluealsa-pcm.c:190: Stopping
bluealsa-pcm.c:253: Freeing HW
../shared/ctl-client.c:348: Closing PCM for B8:AD:3E:01:6E:88
bluealsa-pcm.c:206: Closing plugin
~> pacman -Qs bluez
local/bluez 5.44-1
    Daemons for the bluetooth protocol stack
local/bluez-alsa-git v1.1.0.r102.g9dbefab-1
    Bluetooth Audio ALSA Backend
local/bluez-firmware 1.2-8
    Firmwares for Broadcom BCM203x and STLC2300 Bluetooth chips
local/bluez-libs 5.44-1
    Deprecated libraries for the bluetooth protocol stack
local/bluez-utils 5.44-1
    Development and debugging utilities for the bluetooth protocol stack

When I play anything via aplay, I hear terrible noise that is not music.
It sounds like a distress signal.
Why do I hear such things?

No such device

I disabled the default audio device via the BIOS and fully deleted pulseaudio from the system, compile and install from the latest sources bluez-alsa with alsa-lib 1.1.2.

Then start bluealsa and bluetoothctl 5.40:

power on
scan on
agent on
default-agent
pair 00:19:7F:98:XX:XX
connect 00:19:7F:98:XX:XX
[CHG] Device 00:19:7F:98:XX:XX Connected: yes
Connection successful
[9xxPlantronics]#

But can not set bluealsa as a default audio device. For this, created the file /etc/alsa.conf as below:

pcm.!default {
   type plug
   slave {
       pcm {
           type bluealsa
           device 00:19:7F:98:XX:XX
           profile "a2dp"
       }
   }
   hint {
       show on
       description "BT Headset"
   }
}
ctl.!default {
  type bluealsa
}

And the ~/.asoundrc as below:

defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "00:19:7F:98:XX:XX"
defaults.bluealsa.profile "a2dp"

Then restart bluealsa.

# cat /proc/asound/cards 
--- no soundcards ---

The command # aplay -D bluealsa:HCI=hci0,DEV=00:19:7F:98:XX:XX,PROFILE=a2dp test.wav is finished with error:

ALSA lib ../../../git/src/asound/bluealsa-pcm.c:707:(_snd_pcm_bluealsa_open) Couldn't get BlueALSA transport: No such device
aplay: main:786: audio open error: No such device

Output from bluealsa:

bluealsa: Unsupported AT command: +BRSF=24
bluealsa: Unsupported AT command: +CIND=?

What can I do wrong?

If use pulseaudio instead of bluealsa, BT headset works fine.

Question

hello, I have some question about this bluealsa "device". I don't really understand why "defaults.blu..." and how I can put a nice equal in the connected bluealsa devices. I'm using alsaequal

Volume too loud till ~4%

I can control the volume of my bluetooth headset only via the pcm control, there is no hardware control at the headset itself. The problem is that the software volume controls for bluealsa don't work as expected. It is very loud, and only when lowering the volume (via alsamixer -D bluealsa) to ~4% does it go to a normal level.

This could be a problem with this specific model (Phillips SHB7000), but on my laptop (with pulseaudio, without bluealsa) the volume control did work as expected, which is why I assume it is a bug in here.

Turn off HFP

Hi,

is it possible to turn off the HFP ? Background. I let bluealsa server start via rc.local, ok. Then i wrote a script to start bluealsa-aplay..... when udev recognizes the connection of BT device.

It works like charme, for the first 20 sec or so, but then i can see that udev acts again, because HFP is getting freed by bluealsa server.

This is how my script ( bt.sh in /usr/lib/udev )looks like:

#!/bin/bash

 ACTION=$(expr "$ACTION" : "\([a-zA-Z]\+\).*")
 if [ "$ACTION" = "add" ]
 then

        for dev in $(find /sys/devices/virtual/input/ -name input*)
                do
                        if [ -f "$dev/name" ]
                        then

                        mac=$(cat "$dev/name")

                        sudo -u pi bluealsa-aplay -d plugdmix $mac

                        fi
                done
fi

This is what the udev.rules ( 99-input.rules in /etc/udev/rules.d ) looks like:

SUBSYSTEM=="input", GROUP="input", MODE="0660"
KERNEL=="input[0-9]*", RUN+="/usr/lib/udev/bt.sh"

This happens in udevadm monitor when connecting:

KERNEL[750.803547] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2/1-1.5.2:1.0/bluetooth/hci0/hci0:71 (bluetooth)
UDEV  [750.832100] add      /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.5/1-1.5.2/1-1.5.2:1.0/bluetooth/hci0/hci0:71 (bluetooth)
KERNEL[754.038376] add      /devices/virtual/input/input3 (input)
KERNEL[754.039283] add      /devices/virtual/input/input3/event2 (input)
UDEV  [786.071908] add      /devices/virtual/input/input3 (input)
UDEV  [786.079762] add      /devices/virtual/input/input3/event2 (input)

And this happens on bluealsa server:

bluealsa: ../../src/bluez.c:438: A2DP Sink (SBC) configured for device D8:C4:E9:B6:5C:80
bluealsa: ../../src/bluez.c:440: Configuration: channels: 2, sampling: 44100
bluealsa: ../../src/transport.c:601: State transition: 0 -> 0
bluealsa: ../../src/ctl.c:534: New client accepted: 11
bluealsa: ../../src/ctl.c:537: +-+-
bluealsa: ../../src/ctl.c:537: +-+-
bluealsa: ../../src/ctl.c:313: PCM requested for D8:C4:E9:B6:5C:80 type 1 stream 1
bluealsa: ../../src/ctl.c:537: +-+-
bluealsa: ../../src/ctl.c:537: +-+-
bluealsa: ../../src/io.c:1088: RFCOMM disconnected: Connection reset by peer
bluealsa: ../../src/transport.c:601: State transition: 2 -> 4
bluealsa: ../../src/transport.c:769: Closing RFCOMM: 8
bluealsa: ../../src/transport.c:324: Freeing transport: HFP Hands-Free
bluealsa: ../../src/transport.c:324: Freeing transport: HFP Hands-Free
bluealsa: ../../src/io.c:55: Exiting IO thread
bluealsa: ../../src/ctl.c:506: Client closed connection: 11
bluealsa: ../../src/transport.c:844: Cleaning PCM FIFO: /var/run/bluealsa/hci0-D8:C4:E9:B6:5C:80-                                                                                                    1-1
bluealsa: ../../src/ctl.c:537: +-+-

And thats the problem. Something what ever is going wrong with HFP. Seems to be a phone problem. Anyway, as soon as HFP gets disconnected, udev is seeing another "add" and calls the script again. And this causes the stream to stop.

Maybe there is another way to stop the second "add" event. Is there a way to read hci0 connection status as for example "connected" ? If yes, i could write another if condition to the script...

libortp

What is meant by a dependency on libortp for compilation only? I would like to use your package, and am using yocto-poky for the build system. But I don't want to bring in the entire linphone project to build this one piece. How to work around the libortp dependency? It also seems like libortp has a dependency for bctoolbox that is not by default met as well. As the dependency tree is growing, it seems more important to find a way to work around the libortp dependency.

fdk-aac compile problem

Starting with fdk-aac 0.1.4, AOT_MP2_AAC_LC was removed. This is preventing io.c line 789 from compiling. From what I can tell it simply maps to AOT_AAC_LC anyway.

Possible fix: line 788 of io.c

case AAC_OBJECT_TYPE_MPEG2_AAC_LC:
case AAC_OBJECT_TYPE_MPEG4_AAC_LC:
	aot = AOT_AAC_LC;
	break;

master: "error: 'AAC_PCM_OUTPUT_CHANNELS' undeclared"

This happens for me with version 0.1.4. With a bit of googling this seems to have been some changes in fdk-aac. At the bottom a probably incomplete diff but this made it compile for me.

gcc -DHAVE_CONFIG_H -I. -I..  -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -pthread -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include    -g -O2 -MT io.o -MD -MP -MF .deps/io.Tpo -c -o io.o io.c
io.c: In function 'io_thread_a2dp_sbc_forward':
io.c:256:2: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
  pthread_cleanup_push(io_thread_release_bt, t);
  ^
io.c:287:2: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
  pthread_cleanup_push(sbc_finish, &sbc);
  ^
io.c: In function 'io_thread_a2dp_sbc_backward':
io.c:390:2: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
  pthread_cleanup_push(io_thread_release_bt, t);
  ^
io.c:417:2: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
  pthread_cleanup_push(sbc_finish, &sbc);
  ^
io.c: In function 'io_thread_a2dp_aac_forward':
io.c:567:2: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
  pthread_cleanup_push(io_thread_release_bt, t);
  ^
io.c:586:2: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
  pthread_cleanup_push(aacDecoder_Close, handle);
  ^
io.c:589:41: error: 'AAC_PCM_OUTPUT_CHANNELS' undeclared (first use in this function)
  if ((err = aacDecoder_SetParam(handle, AAC_PCM_OUTPUT_CHANNELS, channels)) != AAC_DEC_OK) {
                                         ^
io.c:589:41: note: each undeclared identifier is reported only once for each function it appears in
io.c: In function 'io_thread_a2dp_aac_backward':
io.c:683:2: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
  pthread_cleanup_push(io_thread_release_bt, t);
  ^
io.c:696:2: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
  pthread_cleanup_push(aacEncClose, &handle);
  ^
make[3]: *** [Makefile:488: io.o] Error 1
make[3]: Leaving directory '/home/sander/repos/bluez-alsa/src'
make[2]: *** [Makefile:521: all-recursive] Error 1
make[2]: Leaving directory '/home/sander/repos/bluez-alsa/src'
make[1]: *** [Makefile:415: all-recursive] Error 1
make[1]: Leaving directory '/home/sander/repos/bluez-alsa'
make: *** [Makefile:347: all] Error 2
diff --git a/src/io.c b/src/io.c
index 93edbbf..10b98c5 100644
--- a/src/io.c
+++ b/src/io.c
@@ -25,6 +25,9 @@
 #if ENABLE_AAC
 # include <fdk-aac/aacdecoder_lib.h>
 # include <fdk-aac/aacenc_lib.h>
+# ifndef AACDECODER_LIB_VL0
+#  define AAC_PCM_MAX_OUTPUT_CHANNELS AAC_PCM_OUTPUT_CHANNELS
+# endif
 #endif

 #include "a2dp-codecs.h"
@@ -581,7 +584,7 @@ void *io_thread_a2dp_aac_forward(void *arg) {
    pthread_cleanup_push(aacDecoder_Close, handle);

    const unsigned int channels = transport_get_channels(t);
-   if ((err = aacDecoder_SetParam(handle, AAC_PCM_OUTPUT_CHANNELS, channels)) != AAC_DEC_OK) {
+   if ((err = aacDecoder_SetParam(handle, AAC_PCM_MAX_OUTPUT_CHANNELS, channels)) != AAC_DEC_OK) {
        error("Couldn't set output channels: %s", aacdec_strerror(err));
        goto fail_init;
    }

Cannot open shared library

After installing bluez-alsa, I encountered a weird error message when trying to play a sound.
(Like: aplay -D bluealsa:HCI=hci0,DEV=XX:XX:XX:XX:XX:XX,PROFILE=a2dp test.wav)
All i got was the message:

ALSA lib dlmisc.c:254:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/x86_64-linux-gnu/alsa-lib/libasound_module_pcm_bluealsa.so aplay: main:788: audio open error: No such device or address
Until now I have no clue why I get this error, since I also made sure that all packages are properly installed.
Many thanks in advance

Raspberry Pi

Any installation tutorial for compiling on raspberry pi for dependencies?

bluez-alsa as audio sink

Hello,

It's more a question than a real issue. I tried to configure my computer to work as audio sink. After having paired computer and mobile I could stream audio to the computer - great. It took a while until I simply tried the arecord ... |aplay construct because I was confused of not seeing the bluealsa device in a arecord -L. But it works anyway. So my question is: Alsatools not showing the device in their lists (tested aplay, arecord and alsamixer) is this an expected behavior of bluez-alsa?

Thanks and best regards
humarf

Unable to find definition 'defaults.bluealsa.interface'

I've followed the instructions in the readme. After connecting to my bluetooth device and running sudo bluealsa I'm unable to make aplay work:

Without sudo:

(ins)carlos@carlos ~$ aplay -D bluealsa test.wav 
ALSA lib bluealsa-pcm.c:701:(_snd_pcm_bluealsa_open) BlueALSA connection failed: Permission denied
aplay: main:788: audio open error: Permission denied

With sudo:

(ins)carlos@carlos ~$ sudo aplay -D bluealsa test.wav 
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.interface'
ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4996:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM bluealsa
aplay: main:788: audio open error: No such file or directory

My .asoundrc:

(ins)carlos@carlos ~$ cat ~/.asoundrc 
defaults.bluealsa.interface "hci0"
defaults.bluealsa.device "E0:D1:E6:0B:AF:F1"
defaults.bluealsa.profile "a2dp"

My device:

(ins)carlos@carlos ~$ hciconfig 
hci0:	Type: Primary  Bus: USB
	BD Address: 88:53:2E:39:25:B4  ACL MTU: 310:10  SCO MTU: 64:8
	UP RUNNING 
	RX bytes:24330708 acl:1250 sco:473901 events:17770 errors:0
	TX bytes:32573341 acl:30287 sco:473433 commands:768 errors:0
(ins)[MINIJAMBOX by Jawbone]# connect E0:D1:E6:0B:AF:F1
Attempting to connect to E0:D1:E6:0B:AF:F1
Connection successful

Dmix supported?

I got bluealsa running, but it can only play audio from a single application at a time. The rest of the apps complain that the device is busy. Does bluez-alsa support the dmix plugin?

How to handle mismatched formats

I'm trying to set up a raspberry pi as a bluetooth speaker, but ran into a problem. When running bluealsa-aplay --profile-a2dp 14:56:8E:3E:13:F2 --pcm=hw:1,0, I'm getting:

bluealsa-aplay: ../../utils/../src/shared/ctl-client.c:102: Connecting to socket: /var/run/bluealsa/hci0
bluealsa-aplay: ../../utils/../src/shared/ctl-client.c:213: Getting transport for 14:56:8E:3E:13:F2 type 1
bluealsa-aplay: Couldn't set HW parameters: Set format: Invalid argument: S16_LE

After some googling around, it turns out my sound card is a bit higher than that:

pi@raspberrypi:~/code/bluez-alsa/src $ cat /proc/asound/card1/stream0 
LH Labs Geek Out HD Audio 1V0 at usb-3f980000.usb-1.4, high speed : USB Audio

Playback:
  Status: Stop
  Interface 1
    Altset 1
    Format: S32_LE
    Channels: 2
    Endpoint: 1 OUT (ASYNC)
    Rates: 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000
    Data packet interval: 125 us
  Interface 1
    Altset 2
    Format: SPECIAL
    Channels: 2
    Endpoint: 1 OUT (ASYNC)
    Rates: 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000
    Data packet interval: 125 us

I think the key part there is Format: S32_LE, right? I'm new to alsa, is there a way to convert from one to the other, or is this just a limitation?

Transport not available during connection phase, but amixer shows device

Hi,

I seem to have some trouble getting my bluetooth headset fully connected. It shows an error "Transport not available" when I want to play a media file and also shows this error during the initial connection to the device. However, unlike issue #5 I am able to get the device shown in the output of `amixer -D bluealsa:

Simple mixer control 'PLT_Legend - HSP',0
  Capabilities: pvolume pvolume-joined cvolume cvolume-joined pswitch pswitch-joined cswitch cswitch-joined
  Playback channels: Mono
  Capture channels: Mono
  Limits: Playback 0 - 127 Capture 0 - 127
  Mono: Playback 82 [65%] [on] Capture 82 [65%] [on]

Beforehand I already got an error in the connection phase in the output of bluetooth (Transport not available).

I execute commands in this order:

  1. bluealsa as root
  2. bluetoothctl as root: power on and connect E4:22:A5:08:7B:FF (headset then tells me, it connected to PC)

When the command connect E4:22:A5:08:7B:FF executes, I get the error Transport not available: /org/bluez/hci0/dev_E4_22_A5_08_7B_FF/fd9 in the output of bluealsa (where the fd9 is a number increasing with each trial).

bluealsa: ctl.c:353: Starting controller loop
bluealsa: bluez.c:677: Registering endpoint: 0000110A-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DP_MPEG24_Source
bluealsa: bluez.c:677: Registering endpoint: 0000110A-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DPSource
bluealsa: bluez.c:677: Registering endpoint: 0000110B-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DP_MPEG24_Sink
bluealsa: bluez.c:677: Registering endpoint: 0000110B-0000-1000-8000-00805F9B34FB: /MediaEndpoint/A2DPSink
bluealsa: bluez.c:893: Registering profile: 00001108-0000-1000-8000-00805F9B34FB: /Profile/HSPHeadset
bluealsa: bluez.c:893: Registering profile: 00001112-0000-1000-8000-00805F9B34FB: /Profile/HSPAudioGateway
bluealsa: main.c:202: Starting main dispatching loop
bluealsa: bluez.c:846: Profile method call: org.bluez.Profile1.NewConnection()
bluealsa: bluez.c:778: HSP Audio Gateway configured for device E4:22:A5:08:7B:FF
bluealsa: transport.c:399: State transition: 0 -> 2
bluealsa: io.c:960: Starting IO loop: HSP Audio Gateway
bluealsa: transport.c:91: Created new IO thread: HSP Audio Gateway
bluealsa: io.c:994: AT command: +VGS=08
bluealsa: io.c:994: AT command: +VGM=15
bluealsa: Transport not available: /org/bluez/hci0/dev_E4_22_A5_08_7B_FF/fd9
bluealsa: Transport not available: /org/bluez/hci0/dev_E4_22_A5_08_7B_FF/fd9

That's also the error I then get, when I want to play a media file either by passing the device information via command line or using it from the asound.conf (like amixer does):

[root@pc folder]# aplay -D bluealsa:HCI=hci0,DEV=E4:22:A5:08:7B:FF,PROFILE=a2dp applause.wav 
bluealsa-pcm.c:101: Getting transport for E4:22:A5:08:7B:FF profile 1
ALSA lib bluealsa-pcm.c:619:(_snd_pcm_bluealsa_open) Couldn't get BlueALSA transport: No such device
aplay: main:786: audio open error: No such device
[root@pc folder]# aplay -D bluealsa applause.wav 
bluealsa-pcm.c:101: Getting transport for E4:22:A5:08:7B:FF profile 1
ALSA lib bluealsa-pcm.c:619:(_snd_pcm_bluealsa_open) Couldn't get BlueALSA transport: No such device
aplay: main:786: audio open error: No such device

I am executing all commands as root, to make sure it's not permission issues.

I also tried executing both aplay ... commands from above with a user who is part of group audio, but this leads to the same error.

I might also have to say that I have a PulseAudio running, but for a new project I needed bluetooth device input in ALSA. Might the PulseAudio "steal" the device from bluealsa? Don't know if bluez can only handle one handler at a time or so.

pactl also lists the device:

Card #13
	Name: bluez_card.E4_22_A5_08_7B_FF
	Driver: module-bluez5-device.c
	Owner Module: 35
	Properties:
		device.description = "PLT Legend"
		device.string = "E4:22:A5:08:7B:FF"
		device.api = "bluez"
		device.class = "sound"
		device.bus = "bluetooth"
		device.form_factor = "headset"
		bluez.path = "/org/bluez/hci0/dev_E4_22_A5_08_7B_FF"
		bluez.class = "0x240404"
		bluez.alias = "PLT_Legend"
		device.icon_name = "audio-headset-bluetooth"
		device.intended_roles = "phone"
	Profiles:
		headset_head_unit: Headset Head Unit (HSP/HFP) (sinks: 1, sources: 1, priority: 20, available: yes)
		a2dp_sink: High Fidelity Playback (A2DP Sink) (sinks: 1, sources: 0, priority: 10, available: yes)
		off: Off (sinks: 0, sources: 0, priority: 0, available: yes)
	Active Profile: headset_head_unit
	Ports:
		headset-output: Headset (priority: 0, latency offset: 0 usec)
			Part of profile(s): headset_head_unit, a2dp_sink
		headset-input: Headset (priority: 0, latency offset: 0 usec)
			Part of profile(s): headset_head_unit

How can we further investigate this? Am I missing some libraries for HSP? Transport not available sounds like it could be such an issue.

Music Player Daemon and bluealsa sink

Try to play music from my mobile to MPD. Sound is ok. But high load on a single cpu core. Debian Strech on x64, ALSA 1.1.3, MPD and bluealsa from git.

How to reproduce

bluealsa --a2dp-force-audio-cd
bluetoothctl connect 11:22:33:44:55:66
mpc add alsa://bluealsa:HCI=hci0,DEV=11:22:33:44:55:66,PROFILE=a2dp

Please note: https://forum.musicpd.org/viewtopic.php?f=7&t=4055#p6617

I traced the problem to the fact that the bluealsa PCM requires the client code to call snd_pcm_poll_descriptors_revents() after poll() in order to clear events from an internal file descriptor. Without this function, all subsequent calls to poll() return immediately resulting in a busy loop in the I/O thread. Unfortunately I find the alsa documentation ambiguous on whether snd_pcm_poll_descriptors_revents() is meant to be mandatory so it is arguable whether this is a bug in bluealsa or mpd.

Any help?

bluealsa-aplay not releasing hw audio card unless bluealsa-aplay killed

Phone connected and streams song - all works well. But if the phone stops streaming or the BT has been turned off on the phone ( i.e total BT disconnection ); unless I kill bluealsa-aplay xx.. I cannot use my sound card for any other purpose. This is an issue If I choose to stream via another phone app like dnla or airplay to my hardware.

Debug:
bluealsa-aplay E4:CE:8F:92:67:80
bluealsa-aplay: ../../utils/../src/shared/ctl-client.c:102: Connecting to socket: /var/run/bluealsa/hci0
bluealsa: ../../src/ctl.c:534: New client accepted: 10
bluealsa: ../../src/ctl.c:537: +-+-
bluealsa-aplay: ../../utils/../src/shared/ctl-client.c:197: Getting transport for E4:CE:8F:92:67:80 type 1
bluealsa: ../../src/ctl.c:537: +-+-
bluealsa-aplay: ../../utils/../src/shared/ctl-client.c:286: Requesting PCM open for E4:CE:8F:92:67:80
bluealsa: ../../src/ctl.c:313: PCM requested for E4:CE:8F:92:67:80 type 1 stream 1
bluealsa: ../../src/ctl.c:537: +-+-
bluealsa: ../../src/io.c:103: Opening FIFO for writing: /var/run/bluealsa/hci0-E4:CE:8F:92:67:80-1-1
bluealsa: ../../src/io.c:105: FIFO reading endpoint is not connected yet
bluealsa-aplay: ../../utils/../src/shared/ctl-client.c:305: Opening PCM FIFO (mode: RO): /var/run/bluealsa/hci0-E4:CE:8F:92:67:80-1-1
bluealsa: ../../src/ctl.c:537: +-+-
bluealsa-aplay: ../../utils/aplay.c:245: Starting main loop
bluealsa: ../../src/io.c:103: Opening FIFO for writing: /var/run/bluealsa/hci0-E4:CE:8F:92:67:80-1-1
bluealsa: ../../src/bluez.c:1039: Signal: PropertiesChanged: org.bluez.MediaTransport1
bluealsa: ../../src/transport.c:601: State transition: 2 -> 0
bluealsa: ../../src/transport.c:717: Releasing transport: A2DP Sink (SBC)
bluealsa: ../../src/transport.c:745: Closing BT: 9
bluealsa: ../../src/io.c:72: Exiting IO thread
bluealsa: ../../src/bluez.c:504: Endpoint method call: org.bluez.MediaEndpoint1.ClearConfiguration()
bluealsa: ../../src/transport.c:324: Freeing transport: A2DP Sink (SBC)
bluealsa: ../../src/transport.c:844: Cleaning PCM FIFO: /var/run/bluealsa/hci0-E4:CE:8F:92:67:80-1-1
bluealsa: ../../src/transport.c:851: Closing PCM: 11

At this point the streamed song has stopped and the phone has been switched off; bluealsa debug states its released / freed the sink. But as stated previously the hw:0,0 card is not released for use until bluealsa-aplay is killed. Help!

bluez-alsa with Volumio2

Hi Arkq
I'm not sure this is right place but I've not seen any other way for asking questions...
I've installed Volumio2 on Raspberry PI3 + Hifiberry.
I wanted to add the bluetooth renderer feature.
I've added bluetooth to the system and succeeded in connecting some bluetooth devices.
Then I've tried to installed bluez-alsa.
Configure told me which package weres still missing and I've added alsa-lib.
Now Configure tells me Bluez >= 5.0 is missing. But Bluez is installed (along with bluetooth), version 5.4 if I'm not mistaken... As a newbie, I'm stuck.
Do you know if bluez-alsa is compatible with Volumio 2 ? Could you indicate any stuff or information which could help me making progress ?
Thanks in advance
Philippe

configure error: checking for BLUEZ... no

When installing bluez-alsa, we came across the following error even though bluez was installed at version 5.43 (debian stretch):

checking for BLUEZ... no
configure: error: Package requirements (bluez >= 5.0) were not met:

No package 'bluez' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables BLUEZ_CFLAGS
and BLUEZ_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

After quiet a long search we found out that
libbluetooth-dev was the package that was missing. Mentioning this in the dependencies list would be great

Using A2DP Sink

I'm trying to set up my computer as a bluetooth speaker. I compiled & installed bluez-alsa and managed to connect my phone to it. Last three lines of bluealsa's output are:

bluealsa: ../../src/transport.c:548: State transition: 1 -> 2
bluealsa: ../../src/transport.c:94: Created new IO thread: A2DP Sink (SBC)
bluealsa: ../../src/io.c:330: Starting IO loop: A2DP Sink (SBC)`

Also hcitop shows constant flow of data - everything looks good.

The problem is that no sound is played back from the headphones connected to the computer (regular audio output e.g. with aplay or mpg123 works just fine).

What should I do to get the audio data from bluealsa played back via computer's sound card?

plug ALSA plugin cannot convert to bluealsa

I wanted to automatically convert to the sound format expected by my headset so added this lines to my asoundrc:

pcm.btspeaker {
 type plug
  slave {
    pcm {
      type bluealsa
      interface "hci0"
      device "20:74:CF:04:D6:52"
      profile "a2dp"
    }
    format "unchanged"
    channels "unchanged"
    rate "unchanged"
  }
  hint {
    show on
    description "BT Headset"
  }
}

I did not add the three lines "format, channels, rate" in the beginning, but without them programs crashes or fail cleanly. Still, if plug ALSA plugin cannot convert it is not very useful.

Example, the first execution works. The second crashes. The third freezes.
Disconnecting and connecting or restarting bluetoothd does not help at all, bluealsa appears frozen and reacts only to a kill -9 and when I restart bluealsa I get "Couldn't initialize controller thread: Address already in use." The only solution I found is a full reboot.

~ % aplay -D pcm.btspeaker ./Korg-TR-Rack-Standard-Kit-Crash-Cymbal.wav
bluealsa-pcm.c:102: Getting transport for 20:74:CF:04:D6:52 type 1
bluealsa-pcm.c:516: Setting constraints
Playing WAVE './Korg-TR-Rack-Standard-Kit-Crash-Cymbal.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
Warning: rate is not accurate (requested = 44100Hz, got = 48000Hz)
         please, try the plug plugin (-Dplug:pcm.btspeaker)
bluealsa-pcm.c:351: Initializing HW
bluealsa-pcm.c:139: Requesting PCM open for 20:74:CF:04:D6:52
bluealsa-pcm.c:156: Opening PCM FIFO (mode: WR): /var/run/bluealsa/hci0-20:74:CF:04:D6:52-1-0
bluealsa-pcm.c:368: FIFO buffer size: 4096
bluealsa-pcm.c:373: Selected HW buffer: 94208 ?= 23 periods x 4096 bytes
bluealsa-pcm.c:404: Prepared
bluealsa-pcm.c:310: Starting
bluealsa-pcm.c:241: Starting IO loop
bluealsa-pcm.c:325: Stopping
bluealsa-pcm.c:325: Stopping
bluealsa-pcm.c:380: Freeing HW
bluealsa-pcm.c:185: Closing PCM for 20:74:CF:04:D6:52
bluealsa-pcm.c:341: Closing plugin

~ % aplay -Dplug:pcm.btspeaker ./Korg-TR-Rack-Standard-Kit-Crash-Cymbal.wav
bluealsa-pcm.c:102: Getting transport for 20:74:CF:04:D6:52 type 1
bluealsa-pcm.c:516: Setting constraints
Playing WAVE './Korg-TR-Rack-Standard-Kit-Crash-Cymbal.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
bluealsa-pcm.c:351: Initializing HW
bluealsa-pcm.c:139: Requesting PCM open for 20:74:CF:04:D6:52
bluealsa-pcm.c:156: Opening PCM FIFO (mode: WR): /var/run/bluealsa/hci0-20:74:CF:04:D6:52-1-0
bluealsa-pcm.c:368: FIFO buffer size: 4096
bluealsa-pcm.c:373: Selected HW buffer: 94208 ?= 23 periods x 4096 bytes
bluealsa-pcm.c:404: Prepared
bluealsa-pcm.c:310: Starting
bluealsa-pcm.c:241: Starting IO loop
[1]    9830 segmentation fault (core dumped)  aplay -Dplug:pcm.btspeaker ./Korg-TR-Rack-Standard-Kit-Crash-Cymbal.wav
~ %
aplay -D pcm.btspeaker ./Korg-TR-Rack-Standard-Kit-Crash-Cymbal.wav
bluealsa-pcm.c:102: Getting transport for 20:74:CF:04:D6:52 type 1
^C

Still, thanks a lot for bluealsa. Even with its problems seems better than pulseaudio to me.

Bluealsa as parallel input

Hallo,

finally i managed to get your bluealsa working on my Pi3 with raspbian jessie.

Great program.

The reason why I installed it, on raspbian wheezy with bluez4 i was able to stream music from phone via BT to Pi and also to hear music same time in kodi mediacenter. Doesn't make sense, but so i had not not restart mediacnter or bluez all the time. I guess it was because of ALSA. Now the bluez5 is set to pulse i had the problem i described.

With your program i can use ALSA again. Also the mediacenter is working with ALSA (kodi 15.2).

But at the moment i got the same problem like with pulseaudio. Only one stream is possible. I know that it works somehow because with bluez4 and ALSA it was working too.

Is there a possibility to route the stream of bluealsa to an ALSA plugin like jack ? I'd like to send both streams to this plugin and this will send the combined stream to the output.

It reverses the bluetooth mac address from time to time

Hi

Thanks, it works! But sometimes it does not start, mplayer says:
../../../src/asound/bluealsa-pcm.c:96: Getting transport for B6:96:74:DB:A8:30 profile 1
[AO_ALSA] alsa-lib: ../../../src/asound/bluealsa-pcm.c:613:(_snd_pcm_bluealsa_open) Couldn't get BlueALSA transport: No such device

But my headset's mac is 30:A8:DB:74:96:B6.
Thus, it somehow reverses it, I do not understand the pattern.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.