-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sound delay in raspberry pi midi keyboard project #178
Comments
Since I reported my issue here, I've managed to compile the latest git version of bluealsa to try again. I think the following messages may hold some clues, especially that bit about fluidsynth requesting a different amount and size of periods (don't know what they are, but I reckon that they determine buffer size, and I imagine that buffer size is related to delay...?):
Any suggestions? |
Also, if perhaps I'm under the wrong impression that bluetooth audio will be an option for my usecase at all, please let me know as well. At my fastest, I can now play an entire scale on my electric piano before hearing it on my bluetooth speaker. Also, I worry a bit about this comment:
|
Hi PJBrs, |
Also, if perhaps I'm under the wrong impression that bluetooth audio will
be an option for my usecase at all, please let me know as well.
It might be impossible to reduce delay to 50ms (as Steven has mentioned,
that such a delay is an upper acceptable limit) with bluealsa. In general
it should be possible to go to something around 25-50 ms with Bluetooth
technology, however it would require special software dedicated for low
latency. Bluetooth specification for HFP says that audio delay should not
exceed 50ms (if I remember correctly), because higher delay might be
inconvenient for online gaming when two ppl are seating in the same room.
This specification does not say anything about software which produces
sound, it only states that the communication delay and encoding/decoding
should be within 50ms. BUT this is for HFP/HSP. The problem with A2DP (if
you require better audio quality) is that it encodes bigger chunks of data
at once and decodes it. This process alone adds significant amount of
delay. There is a codec for A2DP which should produce low delay - AptX Low
Latency. Unfortunately, bluealsa does not support such a codec - there is
no much online info how it works. Anyway, it might be possible to reduce
the delay for standard SBC codec and for AptX. The trick is, that one could
send data earlier, without waiting for full MTU. With AptX it is possible
to transfer 4 PCM frames - AptX encoder encodes 4 frames (4 samples for
right channel and 4 samples for left channel) at once. For SBC the number
is around 200 frames.
See this:
https://github.com/Arkq/bluez-alsa/blob/master/src/io.c#L498
https://github.com/Arkq/bluez-alsa/blob/master/src/io.c#L1202
|
Okay, thanks @nekarkedoc and @arkq for your reactions! As far as I now understand, it should be able to get lower latencies if I try HSP and HFP protocols instead of A2DP, so that's the first thing I'll try. The other thing that I understand is that the best option would be the A2DP profile with the aptx(ll) (ll for low latency) codec, which has (way) better latency than normal aptx and aptx(hd), but that current bluez-alsa doesn't support that codec. Is there any bluez command that can show me which A2DP codecs are supported? But then, for this option to be useful it should first be supported in bluez-alsa. Finally, I could start tinkering myself and reduce the number of frames sent each time to reduce latency with the SBC codec... That might not be too much beyond my capabilities ;-) I did notice that the latest pulseaudio might support aptx, but not the ll version. Also, when I tried pulseaudio, that alone took about 25% cpu. If I hit many many notes I only get very rare garbling using bluez-alsa, so that should be usable on the Pi zero. With pulseaudio, I might try again later. Thanks for now, I'll let you know about any progress! |
For supported codecs, run:
|
Hi, I'm trying to build a raspberrypi project where I play may midi keyboard and listen to the sound via bluetooth. Main reason for this: my children keep destroying my headphones by tripping over the wires.
I've tried various combinations now of fluidsynth, timidity, bluealsa, and jackd, but I haven't found any way to reduce the delay between striking a key on my keyboard and hearing sound via bluealsa. I estimate the delay to be about 250ms, which unfortunately is way too long for playing the piano. I hope you can help me get rid of that delay!
First, I did notice quite some open issues on github that mention delays with bluealsa:
#15
#124
#156
However, I don't understand if, and how I can reduce it. I have the following questions:
Are there tunables in the latest bluealsa code that I should try? Have any solutions been found already? I'm currently on raspbian stretch with bluealsa 1.3.0. Incidentally, I couldn't figure out what the "defaults.bluealsa.delay" setting was about, but it didn't seem to affect the delay... Really hope that I can get some advice!
Kind regards,
PJBrs
The text was updated successfully, but these errors were encountered: