Alsa Config: multi / route - can duplicate sound and send to card, but cannot send to plug?

Moderator: Forum moderators

Post Reply
miltonx
Posts: 160
Joined: Sat Nov 28, 2020 12:04 am
Has thanked: 13 times
Been thanked: 6 times

Alsa Config: multi / route - can duplicate sound and send to card, but cannot send to plug?

Post by miltonx »

The aim is to set asound.conf so that audio file being played can be heard from the speaker while being recorded via 'arecord -D plughw:2,1 -f cd recording.wav'.

The idea is to duplicate the sound being played and send it to the loopback card (plughw:2,0), so that the audio can be recorded from plughw:2,1. ('plughw:2,1' is a loopback card.)

My system utilizes dmix and equal like this:
audio player ---> plug equal ---> dmix ---> sound card

The catch is, when I send the duplicate sound to 'dmix:1,0', audio plays and can be recorded. But if the duplicate sound is sent to 'plugequal', audio fails to play with error:

Code: Select all

SDL_OpenAudio (2 channels, 44100 Hz): ALSA: Couldn't get hardware config: Invalid argument
ALSA lib pcm_params.c:2226:(snd1_pcm_hw_refine_slave) Slave PCM not usable
SDL_OpenAudio (1 channels, 44100 Hz): ALSA: Couldn't get hardware config: Invalid argument

This is the alsa config file:

Code: Select all

defaults.pcm.card 1
defaults.ctl.card 1
defaults.pcm.device 0
ctl.equal { type equal; }
pcm.plugequal { type equal; slave.pcm 'plug:dmix' }
pcm.!default
{
	type asym
	playback.pcm { type plug; slave.pcm 'router_1to2' }
	capture.pcm { type plug; slave.pcm 'plughw:1,0' }
}

pcm.quad {
	type multi
	slaves.a.pcm 'dmix:1,0'  ###  'dmix:1,0' works fine. But if it is changed to 'plugequal', audio fails to play.
	slaves.a.channels 2
	slaves.b.pcm 'plughw:2,0'
	slaves.b.channels 2
	bindings.0 { slave a; channel 0; }
	bindings.1 { slave a; channel 1; }
	bindings.2 { slave b; channel 0; }
	bindings.3 { slave b; channel 1; }
}
pcm.router_1to2 {
	type route
	slave.pcm 'quad'
	ttable.0.0 1
	ttable.1.1 1
	ttable.0.2 1
	ttable.1.3 1
}

I hope to keep using pure alsa, without pulseaudio, pipewire, etc.

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1983 times

Re: Alsa Config: multi / route - can duplicate sound and send to card, but cannot send to plug?

Post by mikewalsh »

@miltonx :-

I think we've already got this one covered. I'm also assuming that you - like I - have a machine where the usual 'dmix'/loopback device in Retrovol doesn't in fact function, even though it's showing as 'active'..?

Take a look here:- viewtopic.php?p=101185#p101185

.....here:- viewtopic.php?p=101484

.....and here:- viewtopic.php?t=6083 This is quite a long thread, but it's the original one that eventually spawned the other two.

May help, may not. See what ya think.

Mike. ;)

User avatar
fredx181
Posts: 3085
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 375 times
Been thanked: 1314 times
Contact:

Re: Alsa Config: multi / route - can duplicate sound and send to card, but cannot send to plug?

Post by fredx181 »

mikewalsh wrote: Mon Nov 04, 2024 3:07 pm

@miltonx :-

I think we've already got this one covered. I'm also assuming that you - like I - have a machine where the usual 'dmix'/loopback device in Retrovol doesn't in fact function, even though it's showing as 'active'..?

Take a look here:- viewtopic.php?p=101185#p101185

.....here:- viewtopic.php?p=101484

.....and here:- viewtopic.php?t=6083 This is quite a long thread, but it's the original one that eventually spawned the other two.

May help, may not. See what ya think.

Mike. ;)

miltonx wrote:

audio player ---> plug equal ---> dmix ---> sound card

With including plugequal (as the OP asked about) for recording with loopback device it was never discussed in those threads AFAIK.
Don't really know, but I wouldn't be surprised if such a construction is not possible :?:

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1983 times

Re: Alsa Config: multi / route - can duplicate sound and send to card, but cannot send to plug?

Post by mikewalsh »

@fredx181 :-

Aye, you're right, Fred; it wasn't. But as far as I'm aware, we DID get this working.....using both Bill's method, AND jamesbond's. To my way of thinking, attempting to include equalisation as well is adding yet another layer of complexity to the mix.

Doubtless, it can be done. But it's definitely beyond MY paygrade...

Wouldn't opening pEqualiser prior to starting the recorders have the same effect? I use your DogRadio quite a bit - in fact, I'm listening to it right now on the 'new' Latitude (brilliant piece of kit!) - and if I open pEqualiser before I launch it, the sound quality is transformed out of all recognition. Doesn't sound like the same audio system at all.

Just a thought...

Mike. ;)

User avatar
fredx181
Posts: 3085
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 375 times
Been thanked: 1314 times
Contact:

Re: Alsa Config: multi / route - can duplicate sound and send to card, but cannot send to plug?

Post by fredx181 »

mikewalsh wrote: Mon Nov 04, 2024 5:28 pm

@fredx181 :-
Wouldn't opening pEqualiser prior to starting the recorders have the same effect? ...
...
Just a thought...

Mike. ;)

No, because pEqualiser does create a ~/.asoundrc for the equalizer to work and recording from soundcard requires also creating a special ~/.asoundrc .

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1983 times

Re: Alsa Config: multi / route - can duplicate sound and send to card, but cannot send to plug?

Post by mikewalsh »

@fredx181 :-

Ah; okay. Best I withdraw my advice then, since it would be appear to be misleading..! :D

Mike. ;)

User avatar
wiak
Posts: 4082
Joined: Tue Dec 03, 2019 6:10 am
Location: Packing - big job
Has thanked: 65 times
Been thanked: 1208 times
Contact:

Re: Alsa Config: multi / route - can duplicate sound and send to card, but cannot send to plug?

Post by wiak »

fredx181 wrote: Mon Nov 04, 2024 5:45 pm
mikewalsh wrote: Mon Nov 04, 2024 5:28 pm

@fredx181 :-
Wouldn't opening pEqualiser prior to starting the recorders have the same effect? ...
...
Just a thought...

Mike. ;)

No, because pEqualiser does create a ~/.asoundrc for the equalizer to work and recording from soundcard requires also creating a special ~/.asoundrc .

Sounds like these utilities should backup and restore configs after use.

https://www.tinylinux.info/
DOWNLOAD wd_multi for hundreds of 'distros' at your fingertips: viewtopic.php?p=99154#p99154
Αξίζει να μεταφραστεί;

jamesbond
Posts: 717
Joined: Tue Aug 11, 2020 3:02 pm
Location: The Pale Blue Dot
Has thanked: 124 times
Been thanked: 402 times

Re: Alsa Config: multi / route - can duplicate sound and send to card, but cannot send to plug?

Post by jamesbond »

miltonx wrote: Mon Nov 04, 2024 8:07 am

But if the duplicate sound is sent to 'plugequal', audio fails to play with error:

The "equal" alsa plugin has very peculiar requirements, and its implementation of "get hardware parameters" is incomplete, making it difficult to work with anything other than what it was originally designed to do: a plugin in-between alsa applications, and the hardware. In fact it is a miracle that it works with dmix at all.

The chain that will work is as follows:

Code: Select all

alsa audio-player -> dmix -> alsa loopback -> dsnoop --> alsaloop -> plugequal -> hw
                                                 |
                                                 ------> alsa audio recorder

But instead of the above, I recommend using JACK server and calf-studio instead, which providers much better quality than plugequal (because in addition to equaliser, you can also put in limiter, attenuator, and other stuff as needed)

Code: Select all

alsa audio-player -> dmix -> alsa-loopback -> aloopd-in -> jack server -> calf-studio -> hw
                                                               |
                                                              --------> jack audio recorder
miltonx
Posts: 160
Joined: Sat Nov 28, 2020 12:04 am
Has thanked: 13 times
Been thanked: 6 times

Re: Alsa Config: multi / route - can duplicate sound and send to card, but cannot send to plug?

Post by miltonx »

jamesbond wrote: Tue Nov 05, 2024 6:53 am

The "equal" alsa plugin has very peculiar requirements, and its implementation of "get hardware parameters" is incomplete, making it difficult to work with anything other than what it was originally designed to do: a plugin in-between alsa applications, and the hardware. In fact it is a miracle that it works with dmix at all.

My worst suspection is confirmed. Anyway, at least the dmix miracle is something to celebrate.

Thank you for the suggestion, though at this moment I prefer to stay with pure alsa instead of adding Jack. Maybe I could try bringing in another looppack subdevice via the 'alsaloop -C hw:2,1,1 -P plug:plugequal' workaround.

Post Reply

Return to “Sounds”