-
Notifications
You must be signed in to change notification settings - Fork 188
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
Dmix supported? #48
Comments
Unfortunately not. Dmix requires hardware PCM (hw). It is hardcoded in
the plugin. Once, I've tried to tinker a little bit with the dmix code,
however without any promising results. Anyway, I will try to make it
work... someday :)
|
Is there any progress with this issue? |
Unfortunately, it's not as easy as I previously thought. Making a patch for dmix plugin might be impossible after all (it uses internal timer from audio card). There is no roadmap for bluez-alsa, however this issue might be on my working bench in a month or two. I have to finish my struggle with the HFP support. So, stay tuned :). |
Just a thought about the dmix support. I think it's highly desirable to be able to use bluetooth headphones as normal headphones but without being physically connected to a computer. That is what makes bluetooth devices so attractive. But if they work worse (OK, significantly worse :-) ) or cannot be used the same way, then it just makes no sense. One, I believe, pretty common case is using bluetooth headphones in meetings. Skype works only with PA, that was one of the reasons (among others) why many people were looking for alternative conferencing software like ZoomUs, TeamViewer, Google Hangouts and others. Google Hangouts themselves do not depend on a sound subsystem. You just need to use your favourite browser which doesn't need PA. Chromium was a solution for me, I built it without PA support and it worked (not fine, but it worked). Unfortunately Chromium starts several processes and this is where dmix becomes very important. It's even worse, because, as far as I understand, even though you start only one Google Hangout session, Chromium starts several processes where it plays sound and without dmix we've done. Randomly you may hear ring sounds and do not hear incoming voice or vice versa depending on what process gains a sound device first. This works with PA, so BluezAlsa just cannot be an alternative solution here. To my mind, it may be crucial if there is a goal to make BluezAlsa a competitive software, a good alternative to PA. I wish could help, but I am just a Java software developer. Not sure how I could be useful here, but if you think I could help, please let me know. |
Hi @keyoffecka, You are right, that dmix-like support is required for this project to be an alternative for PA. After some investigation, I know that this mixer functionality has to be incorporated in the bluealsa code (not in the ALSA PCM plug-in). However, it is rather hard to develop few things simultaneously. Right now, I'm focused on playback as it is. When the playback functionality will be good enough (e.g. mSBC support will be merged in to the master branch), I will try to make parallel playback possible. If someone wants to help, there is a short overview how I think this feature should be implemented: It is required to make some middle layer between PCM FIFO and (source) IO thread. This layer has to read PCM samples from multiple FIFOs and mix them together, than feed it into the IO thread via e.g. internal PIPE. One might also look at the dmix code (in the ALSA repository) and see how it is implemented (mixing algorithm). Of course some other design might be good as well. |
+1, would love to get this implemented someday! Many thanks for your hard work @arkq, keep up with the good job! |
+1 for dmix |
+1000 for dmix... how do we combine multiple bluetooth speakers to play at the same time? I have searched high and low, and jackd is my next attempt. |
Here is a workaround for dmix. How it worksThe idea here is to use the snd-aloop module. This is a simple alsa module that creates a card with 2 hw devices, what goes in one device goes out the other. Because those are HW devices they can be slaves of a dmix pluging. So the main idea is to do the following chain: You need alsaloop that will polls Loopback,1 and write everything to bluealsa PCM. It's part of alsa-utils. How to configure itFirst load snd-aloop module Now with "aplay -l" you should see one new card called "Loopback" mine is card number 1. Create the following ~/.asoundrc
With defaults.pcm.card being the Loopback card number. I have taken a brief look at bluealsa. But, if I am correct here, bluealsa PCM's io_thread() seems to transfer frames by period_size chunk no matter what size has been transfered with snd_pcm_write*() functions. This is a problem with alsaloop if we want to have reasonable latency. To fix that you have to apply the following patch, and rebuild bluealsa (this is a quick kludge that has not been tested enough):
Now run And now you should be able to play multiple streams through bluealsa. The downsides are that this adds some extra latency and cpu consumption. Keep in mind that I have only tested this very lightly, so you should expect some issues. Some Random questionsI have some questions for @arkq. Is there any reason that bluealsa is an alsa PCM io plugin besides being a deamon that polls a Loopback device for reading directly ? Am I right saying that io_thread() forwards the io_ptr by period_size chunk no matter how snd_pcm_write*() is used ? If so, can we fix it with a transfer() callback to synchronize the io_thread() each time snd_pcm_write*() is called ? Thanks |
Thank you!! This is what I was looking for. I’ll test it out! |
@repk there was a code change since your patch, I'm not sure how this has any affect or not, but here's an updated diff:
As far as this goes, yes, I was able to get audio through alsaloop but it did have static. @arkq - Thank you for this project. My questions are:
I am also trying to do this on on a headless raspberry pi with Stretch, but also at the same time, I am building a newer implementation of Bluealsa Bluetooth for Volumio that can route to mutiple groups of speakers.
Thanks! |
Hmm, I've based this design by following examples found in the
Yes, that's right because (as far as I know) transferring less then period_size does not make any sense (from the point of view of PCM ring buffer). I might be mistaken, though.
At first I was using transfer() callback, however at some point I was forced to write a separate thread for transferring data. The reason for this was that writing data to bluealsa PCM PIPE blocks - and transfer() callback shall not block. But right now (my knowledge abut ALSA has grown significantly) I think you might be right, that using transfer() callback for data synchronization might be a good idea.
This application is a helper which simplifies BT speaker configuration. It is used to read data from bluealsa server directly and then transfer it to the PCM device (just like
In its simple design, bluealsa should be a PCM device (or devices). Then, you can use any ALSA configuration you want (except
I've never done that. You will have to search this topic by yourself. I'm not a |
@arkq thanks! I actually just got this all working wonderfully using MPD. I went down the wrong rabbit hole and chose to try and do this with ALSA, which I may do later, but MPD which is where I'm trying to stream from and to the speaker group just happens to have multiple alsa definition feature so it'll stream out to the speakers. Just define a new one for each speaker, after setting up a basic asound.conf. I also compiled straight from source without the patch from @repk above, I am unsure what that is about, so straight from source, streaming to multiple speakers from MPD just defining standard bluealsa pcm's. Thanks again, I'll keep link back when I publish my project to git. It's working great! |
Did anyone succeed in using alsaloop? I got to the point where:
My headset is JBL E55BT. Logs and important snippets (I redacted only address of my headphones):
And from bluealsa program itself:
Edit: I figured out that playing a WAV file with sample rate 44100 Hz (directly on bluealsa device, without alsaloop) works, but trying to play file with sample rate 48000 Hz hangs.
Maybe this is relevant? Unfortunately, adding --rate=44100 to alsaloop didn't help... Anyone? |
It seems that I was finally able to make dmix work. My setup is far from perfect (I wasn't able to avoid using soundserver, but ESD seems most clean from all of them... and a hack with esdcat is ugly, but there's no support for ESD in Alsa shipped with Debian), but works. Audio path is: dmix -> loopback -> rate conversion -> esd -> bluealsa. I had to find and compile esound-0.2.41 from sources, as it seems it has been superseded by pulseaudio (which I don't want to use – for many reasons). One big drawback is the sound latency – trying to watch online videos sucks as audio is out of sync with video. But I'm able to listen to music, at least that's good... ESD configure command:
ESD run command:
snd-aloop load line in /etc/modules:
Alsaloop run command:
And finally .asoundrc:
|
+dmix 👍 |
I tried the alsaloop method. Here are the problem:
alsaloop application running:
The asound.conf:
sound card:
The test result. when execute the 1st aplay, I can hear sound from BT speaker, but when execute the 2nd aplay, it report error. Looks like 2nd aplay will open the slave device as well.
|
aplay is complaining about an "Invalid argument" and not about "Device or resource busy". I am not sure here be maybe it is due to the fact that you do not use a soft resampler (type plug). Could you try the following :
Also please keep in mind that this solution is a workaround and will introduce huge delay. I personally use "alsaloop -C "hw:Loopback,1,0" -P "bluealsa" -U -l 1000 --period 200 -S 0". It's a bit cpu intensive but it works most of the time ok and make videos viewable. |
Regardless of whether alsaloop alone method works or not (I couldn't get it to work), there's one more problem with this method. When reconnecting headphones (I need to restart bluealsa for that, it's probably a bug in bluealsa) you need to exit applications that have open streams (including web browser). My working setup (a terrible workaround, but at least usable) is having four terminal windows open on a separate workspace.
When connecting headphones:
This is a terrible workaround (compare it to my Android phone, where I just turn headphones on, everything pairs automatically and I can play music almost instantly), but I don't think we have any better alternative for now. dmix support will be the greatest feature to be added to bluealsa. The good thing is that once it works, it's quite stable. I never experienced disconnects. Sound hiccupped from time to time, but it stopped after wrapping |
this change make it possible to use dmix indirectly with bluealsa as described in issue arkq#48
this change makes it possible to use dmix indirectly with bluealsa as described in issue arkq#48
Direct integration with |
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?
The text was updated successfully, but these errors were encountered: