GithubHelp home page GithubHelp logo

Bluealsa as parallel input about bluez-alsa HOT 22 CLOSED

arkq avatar arkq commented on May 23, 2024
Bluealsa as parallel input

from bluez-alsa.

Comments (22)

Vitalic66 avatar Vitalic66 commented on May 23, 2024 1

After nice conversation via IRC here is the solution to make it work as suggested. Configure the .asoundrc like this:

pcm.!default {
  type plug
  slave.pcm "dmix"
}

or another actual config for sound tests:

pcm.!default {
  pcm "dmix"
 }
 pcm.plugdmix {
  type plug
  slave.pcm "dmix"
}

My aplay -L now looks like that

pi@raspberrypi:~ $ aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
pulse
    PulseAudio Sound Server
plugdmix
sysdefault:CARD=sndrpihifiberry
    snd_rpi_hifiberry_dac,
    Default Audio Device
dmix:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dac,
    Direct sample mixing device
dsnoop:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dac,
    Direct sample snooping device
hw:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dac,
    Direct hardware device without any conversions
plughw:CARD=sndrpihifiberry,DEV=0
    snd_rpi_hifiberry_dac,
    Hardware device with all software conversions

In case someone else will stumble over this by searching the net :) THX @arkq

from bluez-alsa.

xavi-b avatar xavi-b commented on May 23, 2024 1

Hi,

I was looking at a similar problem to play both bluetooth sound from my phone and sound from other applications on my RPI4.

I solved it using the following .asoundrc:

pcm.!default {
	type asym
	playback.pcm {
		type plug
		slave.pcm "dmixer"
	}
	capture.pcm {
		type plug
		slave.pcm "input"
	}
}

pcm.bluealsadmix {
    type plug
    slave.pcm "dmixer"
}

pcm.dmixer {
    type dmix
    ipc_key 1024
    slave.pcm "output"
}

pcm.output {
	type hw
	card 0
}

ctl.!default {
	type hw
	card 0
}

using the following link to configure bluealsa-play as a A2DP Sink:
https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=247892&p=1513571
and changing the aplay.service file to:

[Unit]
Description=BlueALSA aplay service
After=bluealsa.service
Requires=bluealsa.service

[Service]
Type=simple
User=pi
ExecStartPre=/bin/sleep 20
ExecStart=/usr/bin/bluealsa-aplay -vv -d bluealsadmix 00:00:00:00:00:00

[Install]
WantedBy=multi-user.target

from bluez-alsa.

arkq avatar arkq commented on May 23, 2024

Hi,

Right now it is not possible to connect more than one app to the bluealsa ALSA plugin. See #48. I haven't experimented with JACK, though. If JACK supports audio mixing, it might be possible to use it instead of ALSA interface. However, I've got no experience with JACK, and I do not know how it works (on a connection level).

from bluez-alsa.

Vitalic66 avatar Vitalic66 commented on May 23, 2024

No sorry that's not what i meant:

phone (BT) stream -->bluealsa pcm --> alsa loopback--> real soundcard --> speaker

musicplayer e.g. Kodi audio CD-->alsa loopback -->real soundcard-->speaker

This is what i'm trying. Creating 2 virtual soundcards to stream the music to and both can use the hardware device same time.

from bluez-alsa.

arkq avatar arkq commented on May 23, 2024

Hmm... I do not quite understand why you need two separate ALSA devices for real soundcard. If real soundcard (hw in the ALSA nomenclature) does not support mixing, you can use dmix plugin. So, you can connect (to the hw) as many apps as you want. Or I'm missing something from the picture...

from bluez-alsa.

Vitalic66 avatar Vitalic66 commented on May 23, 2024

So maybe i did something wrong with my setup for bluealsa and asound.conf.
Kodi is using pcm.!default .

bluealsa-aplay: Couldn't open PCM: Device or resource busy
This happens when music plays in Kodi. Cant even play a test.wav with aplay as soon as pcm.!default is in use.
Thats why I want to stream BT to a virtual card.

from bluez-alsa.

arkq avatar arkq commented on May 23, 2024

OK, so it is definitely something wrong with your ALSA configuration. Make sure, that this overwritten default PCM uses dmix (or that dmix is somewhere in the plugin chain). Not all soundcards support mixing internally, so software mixer (dmix) is required. By default, such a sane configuration is delivered by the ALSA itself. However, if you make something like this (as an example):

pcm.!default {
	type plug
	slave.pcm "hw:0"
}

all ALSA magic is gone. Now you are using bare metal (not quite bare metal, because format conversion is supported via the plug plugin, however it's just an example) hardware, which might lack audio mixing.

from bluez-alsa.

Vitalic66 avatar Vitalic66 commented on May 23, 2024

Call me noob but I don't understand that :/

I create via modprobe snd_aloop 2 virtual soundcards. The hardware card is a Hifiberry-DAC.

card 0: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi pcm5102a-hifi-0 []
  Subdevices: 0/1
  Subdevice #0: subdevice #0
card 1: Loopback [Loopback], device 0: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: Loopback [Loopback], device 1: Loopback PCM [Loopback PCM]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7

How can i link the Kodi stream to virtual device and also the bluealsa stream to the other virtual device and mix both and then link this on to default (real sound card).

In dmix i can only set one slave or can i also set two slaves ?

Like so ?

pcm.!default {
	type plug
	slave.pcm "hw:0"
}

pcm.mixed {
        type dmix
        ipc_key 321456
        slave {
                pcm "hw:Loopback,0,0"
                format S16_LE
                rate 44100
        }
        slave {
                pcm "hw:Loopback,1,0"
                format S16_LE
                rate 44100
        }

}

I guess not. How should i link the pcm.mixed to the pcm.!default ?

Can't find a tutorial for that.

Sorry for that foolish question, but i don't get it...

from bluez-alsa.

Vitalic66 avatar Vitalic66 commented on May 23, 2024

And how and where can I tell bluealsa to use virtual device 1 or 2. In Kodi I can set it up under audio setting.

from bluez-alsa.

arkq avatar arkq commented on May 23, 2024

If my understanding of the problem is correct:

  • you want to play music from kodi and from bluealsa
  • you've got one soundcard and want to use it

Then, what I'd have done would be setting up default PCM to use this soundcard (if it's not done already by the ALSA), e.g.:

pcm.!default {
        type dmix
        ipc_key 321456
        slave.pcm "hw:0"
}

However, firstly check if it's not done already by the ALSA. Just remove your ALSA configuration (comment it out) and see the output from the aplay -L command. If there is a default PCM and it uses the right hardware, then everything is done already. If not, use the configuration I've posted above.

If you are using bluealsa-aplay, you can use -d option to specify which PCM it should use. By default it uses "default" PCM.

from bluez-alsa.

Vitalic66 avatar Vitalic66 commented on May 23, 2024

The right hw soundcard is found by ALSA. Also without extra config. The problem is, like I said, when playing music in Kodi, bluealsa-aplay complains about device in use.

So starting bluealsa-play -d bluealsa for example might fix the start problem. But how should the config look like for pcm.bluealsa ? It has to run into the dmix ?

from bluez-alsa.

arkq avatar arkq commented on May 23, 2024

OK, so try something like this:

pcm.default-mix {
        type dmix
        ipc_key 321456
        slave.pcm "default"
}

Then, use default-mix in the kodi and use -d default-mix for the bluealsa-aplay.

from bluez-alsa.

Vitalic66 avatar Vitalic66 commented on May 23, 2024

pi@raspberrypi:~ $ sudo bluealsa-aplay -d default-mix D8:C4:E9:B6:5C:80 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default-mix bluealsa-aplay: Couldn't open PCM: No such file or directory

Content of .asoundrc is only your code
pcm.default-mix { type dmix ipc_key 321456 slave.pcm "default" }

from bluez-alsa.

Vitalic66 avatar Vitalic66 commented on May 23, 2024

with config like this:

`
pcm.default-mix {
type dmix
ipc_key 321456
slave.pcm "default"
}

pcm.default {
type hw card 0
}
`
i get this:

pi@raspberrypi:~ $ sudo bluealsa-aplay -d default-mix D8:C4:E9:B6:5C:80 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default-mix

from bluez-alsa.

arkq avatar arkq commented on May 23, 2024

If you're using sudo, the config needs to be in the /root directory or in the /etc as a global configuration. However, you should be able to use bluealsa-aplay as a normal user (sudo is not required).

from bluez-alsa.

Vitalic66 avatar Vitalic66 commented on May 23, 2024

guess something must be wrong... sorry for that

pi@raspberrypi:~ $ bluealsa-aplay -d default-mix D8:C4:E9:B6:5C:80 ALSA lib conf.c:1231:(parse_def) default is not a compound ALSA lib conf.c:1697:(snd_config_load1) _toplevel_:17:13:Invalid argument ALSA lib conf.c:3417:(config_file_open) /home/pi/.asoundrc may be old or corrupted: consider to remove or fix it ALSA lib conf.c:3339:(snd_config_hooks_call) function snd_config_hook_load returned error: Invalid argument ALSA lib conf.c:3788:(snd_config_update_r) hooks failed, removing configuration bluealsa-aplay: Couldn't open PCM: Invalid argument

also without sudo many errors. aplay -L also not working

pi@raspberrypi:~ $ aplay -L ALSA lib conf.c:1231:(parse_def) default is not a compound ALSA lib conf.c:1697:(snd_config_load1) _toplevel_:17:13:Invalid argument ALSA lib conf.c:3417:(config_file_open) /home/pi/.asoundrc may be old or corrupted: consider to remove or fix it ALSA lib conf.c:3339:(snd_config_hooks_call) function snd_config_hook_load returned error: Invalid argument ALSA lib conf.c:3788:(snd_config_update_r) hooks failed, removing configuration

from bluez-alsa.

arkq avatar arkq commented on May 23, 2024

Yeah, something is wrong :D

Remove pcm.default entry from the confing. It's not allowed.

from bluez-alsa.

Vitalic66 avatar Vitalic66 commented on May 23, 2024

But that brings me back to the error

pi@raspberrypi:~ $ bluealsa-aplay -d default-mix D8:C4:E9:B6:5C:80 ALSA lib pcm_dmix.c:1027:(snd_pcm_dmix_open) dmix plugin can be only connected to hw plugin bluealsa-aplay: Couldn't open PCM: Invalid argument

now I'm confused....

but when i do something like that:

pcm.default-mix {
        type dmix
        ipc_key 321456
        slave.pcm "test"
}

pcm.test {
        type hw card 0
}

i get a new error type. at least not complaining about pcm:

pi@raspberrypi:~ $ bluealsa-aplay -d default-mix D8:C4:E9:B6:5C:80 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 D8:C4:E9:B6:5C:80 type 1 bluealsa-aplay: Couldn't set HW parameters: Invalid argument

from bluez-alsa.

arkq avatar arkq commented on May 23, 2024

It would be much easer to communicate without delay. IRC: #bluealsa @freenode.org

from bluez-alsa.

Vitalic66 avatar Vitalic66 commented on May 23, 2024

I forgot to mention how to use it:

ofcause bluealsa must be startet in backround via rc.local for example.

bluealsa-aplay -d plugdmix XX:XX:XX:XX:XX:XX

from bluez-alsa.

Vitalic66 avatar Vitalic66 commented on May 23, 2024

Somehow it's not working with compiled master version. It's working with downloaded not self-compiled version.

Did you change something?

When using config with plugdmix, kodi can't find default pcm but bluealsa-aplay works. When using pcm dmix, kodi is finding default and plays sound, but bluealsa-aplay says pcm open error, already in use.

Also aplay -L doesn't show PCM from .asoundrc. That might be the problem, why kodi can't find plugdmix.

Update:

As long as i dont update the alsa-lib (1.0.28 to match alsa-utils) i can find new pcm from .asoundrc.
But i need to install alsa-lib for compiling. So what is the mistake i make ?

Update:

Error was caused by compiling alsa-lib. After that aplay -L wasn't able to show PCM from .asoundrc . So you should not compile alsa-lib by yourself. I installed it now via sudo apt-get install libasound2*.

Now compiling bluealsa works and aplay -L still shows PCM from .asoundrc

from bluez-alsa.

roizcorp avatar roizcorp commented on May 23, 2024

Hi,

Looping back to this, I cannot get this dmix in my configuration at all, meaning I do put it as stated above but aplay -L does not show anything remotely to the output shown above,

Does it work still?

from bluez-alsa.

Related Issues (20)

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.