Categorieën bekijken

Audio device via Bluetooth (linux)

In this example we are using a S10 bluetooth speaker to connect it with bluetooth and play music on it.

Install software #

Install nessesary software: Fluidsynth, Alsa en Pulse audio

sudo apt install -y alsa-utils pulseaudio-module-bluetooth pavucontrol fluidsynth fluid-soundfont-gm

Start pulseaudio before connecting:

pulseaudio --start

Connect bluetooth speaker #

To connect via bluetooth enter the bluetooth commandline:

bluetoothctl

Start the scan:

[bluetooth]# power on
[bluetooth]# agent on
[bluetooth]# scan on
Discovery started

Power on the MIDI Pad, eventuelly it will be discovered and you will see something like:

[NEW] Device B4:3A:3F:F6:09:CC S10 Bluetooth Speaker

Turn scan off:

[bluetooth]# scan off

Trust the device by entering it’s MAC address:

[bluetooth]# trust B4:3A:3F:F6:09:CC

Output:

[CHG] Device B4:3A:3F:F6:09:CC Trusted: yes
Changing B4:3A:3F:F6:09:CC trust succeeded

Pair with the Bluetooth speaker:

[bluetooth]# pair <a href="B4:3A:3F:F6:09:CC">25:4E:5A:66:94:BC</a>

Output:

Attempting to pair with B4:3A:3F:F6:09:CC
[CHG] Device B4:3A:3F:F6:09:CC Connected: yes
[CHG] Device B4:3A:3F:F6:09:CC Alias: B4-3A-3F-F6-09-CC
[CHG] Device B4:3A:3F:F6:09:CC Name is nil
[CHG] Device B4:3A:3F:F6:09:CC Bonded: yes
[CHG] Device B4:3A:3F:F6:09:CC Paired: yes
Pairing successful
[CHG] Device B4:3A:3F:F6:09:CC Connected: no

Connect to the bluetooth speaker:

[bluetooth]# connect B4:3A:3F:F6:09:CC

Output:

Attempting to connect to B4:3A:3F:F6:09:CC
[CHG] Device B4:3A:3F:F6:09:CC Connected: yes
[NEW] Endpoint /org/bluez/hci0/dev_B4_3A_3F_F6_09_CC/sep1
[NEW] Endpoint /org/bluez/hci0/dev_B4_3A_3F_F6_09_CC/sep2
[NEW] Transport /org/bluez/hci0/dev_B4_3A_3F_F6_09_CC/sep1/fd0
Connection successful
[CHG] Transport /org/bluez/hci0/dev_B4_3A_3F_F6_09_CC/sep1/fd0 State: active
[CHG] Device B4:3A:3F:F6:09:CC ServicesResolved: yes

The device is now connected to the system, you can exit the bluetooth terminal.

Set default audio output to bluetooth device #

To play trough the bluetooth device you need to set it to default output first:

List devices:

pactl list short sinks

1       bluez_sink.B4_3A_3F_F6_09_CC.a2dp_sink  module-bluez5-device.c  s16le 2ch 44100Hz       SUSPENDED

Set device to default audio output:

pactl set-default-sink bluez_sink.B4_3A_3F_F6_09_CC.a2dp_sink

MP3 testing #

play a mp3 file with:

ffplay test.mp3

MIDI testing #

Please note: Bluetooth speakers are mostly using pulseaudio

Test NOTE

test notes on fluidsynth

fluidsynth -a pulseaudio -m alsa_seq /usr/share/sounds/sf2/FluidR3_GM.sf2

in the console of fluidsynth type

noteon 1 60 100

You should here a note play

Test MIDI file

Download a midi file

wget https://files.khinsider.com/midifiles/snes/super-mario-world/overworld.mid -O test.mid

Check if the file is a midi file:

file test.mid

test.mid: Standard MIDI data (format 1) using 19 tracks at 1/120

Play the midi file:

fluidsynth -a pulseaudio -m alsa_seq -i /usr/share/sounds/sf2/default-GM.sf2 test.mid

or

fluidsynth -a pulseaudio -m alsa_seq -i /usr/share/sounds/sf2/FluidR3_GM.sf2 test.mid