Select channels with alsa_out

Optimize your system for ultimate performance.

Moderators: MattKingUSA, khz

Post Reply
User avatar
RowdyVoyeur
Established Member
Posts: 9
Joined: Mon May 27, 2024 1:44 pm
Location: Portugal
Been thanked: 1 time
Contact:

Select channels with alsa_out

Post by RowdyVoyeur »

Is it possible to set create ports with specific channels using alsa_out?

If a audio card has more than 2 channels, I'm able to create ports with the other channels using the -c option of alsa_out. For example:

Code: Select all

alsa_out -j "MC101_out" -d hw:MC101,DEV=0 -r 44100 -p 64 -n 4 &

Will create the following ports:

Code: Select all

jack_connect system:capture_1 MC101_out:playback_1
jack_connect system:capture_2 MC101_out:playback_2

If I want to create ports with channels 3 and 4, which is the case, I just need to do the following:

Code: Select all

alsa_out -j "MC101_out" -d hw:MC101,DEV=0 -r 44100 -p 64 -n 4 -c 4 &

This will create the following ports:

Code: Select all

MC101_out:playback_1
MC101_out:playback_2
MC101_out:playback_3
MC101_out:playback_4

I can then use jack_connect to connect only MC101_out:playback_3 and MC101_out:playback_4. However, I would like to create only the ports with channels 3 and 4, leaving channels 1 and 2 alone.

Would this be possible?

User avatar
bluebell
Established Member
Posts: 1972
Joined: Sat Sep 15, 2012 11:44 am
Location: Saarland, Germany
Has thanked: 127 times
Been thanked: 131 times

Re: Select channels with alsa_out

Post by bluebell »

I use some kind of virtual jack nodes, created with

Code: Select all

jack_thru mynodename

(e.g."jack_thru main", "jack_thru vocmic" …)

These nodes have always 2 inputs and 2 outputs but that's ok for me.

I connect them with jack-plumbing, but any other method works.

Bildschirmfoto_2024-05-28_12-01-16.jpg
Bildschirmfoto_2024-05-28_12-01-16.jpg (90.92 KiB) Viewed 657 times

Linux – MOTU UltraLite AVB – Qtractor – http://suedwestlicht.saar.de/

tavasti
Established Member
Posts: 2101
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Has thanked: 396 times
Been thanked: 213 times
Contact:

Re: Select channels with alsa_out

Post by tavasti »

RowdyVoyeur wrote: Tue May 28, 2024 9:24 am

Is it possible to set create ports with specific channels using alsa_out?
...
If I want to create ports with channels 3 and 4, which is the case, I just need to do the following:

Code: Select all

alsa_out -j "MC101_out" -d hw:MC101,DEV=0 -r 44100 -p 64 -n 4 -c 4 &

This will create the following ports:

Code: Select all

MC101_out:playback_1
MC101_out:playback_2
MC101_out:playback_3
MC101_out:playback_4

I can then use jack_connect to connect only MC101_out:playback_3 and MC101_out:playback_4. However, I would like to create only the ports with channels 3 and 4, leaving channels 1 and 2 alone.

Would this be possible?

Just use those ports 3+4 if you don't need 2 first ones.

Linux veteran & Novice musician

Latest track: https://www.youtube.com/watch?v=ycVrgGtrBmM

User avatar
RowdyVoyeur
Established Member
Posts: 9
Joined: Mon May 27, 2024 1:44 pm
Location: Portugal
Been thanked: 1 time
Contact:

Re: Select channels with alsa_out

Post by RowdyVoyeur »

bluebell wrote: Tue May 28, 2024 10:01 am

I use some kind of virtual jack nodes, created with

Code: Select all

jack_thru mynodename

(e.g."jack_thru main", "jack_thru vocmic" …)
These nodes have always 2 inputs and 2 outputs but that's ok for me. I connect them with jack-plumbing, but any other method works.

tavasti wrote: Tue May 28, 2024 10:19 am

Just use those ports 3+4 if you don't need 2 first ones.

Thanks for both your suggestions. The issue is not so much the extra two ports with channels 1 and 2 being there. I could just sort of bypass them by not connecting them with jack_connect.

The issue is that when I create all those 4 ports with channels 1 to 4, then I cannot use alsa_in with the same audio card again.

If I run alsa_in:

Code: Select all

alsa_in -j "MC101_in" -d hw:CARD=MC101,DEV=0 -r 44100 -p 64 -n 4 -c 2 &

After running:

Code: Select all

alsa_out -j "MC101_out" -d hw:CARD=MC101,DEV=0 -r 44100 -p 64 -n 4 -c 4 &

I get this error:

Code: Select all

Unable to set hw params for playback: Invalid argument Setting of hwparams failed: Invalid argument

If I run alsa_in:

Code: Select all

alsa_in -j "MC101_in" -d hw:CARD=MC101,DEV=0 -r 44100 -p 64 -n 4 -c 2 &

After running:

Code: Select all

alsa_out -j "MC101_out" -d hw:CARD=MC101,DEV=0 -r 44100 -p 64 -n 4 -c 2 &

Then everything gets properly connected with jack_connect, but I cannot hear the audio input.

Therefore, I'm assuming those 2 extra ports are somehow preventing alsa_out to connect to the same device.

tavasti
Established Member
Posts: 2101
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Has thanked: 396 times
Been thanked: 213 times
Contact:

Re: Select channels with alsa_out

Post by tavasti »

RowdyVoyeur wrote: Wed May 29, 2024 8:32 am

Thanks for both your suggestions. The issue is not so much the extra two ports with channels 1 and 2 being there. I could just sort of bypass them by not connecting them with jack_connect.

The issue is that when I create all those 4 ports with channels 1 to 4, then I cannot use alsa_in with the same audio card again.
...
Therefore, I'm assuming those 2 extra ports are somehow preventing alsa_out to connect to the same device.

Device is locked with that one alsa_in, but that is not really any problem: you have all the ports visible, so you just make jack connections you need.

Linux veteran & Novice musician

Latest track: https://www.youtube.com/watch?v=ycVrgGtrBmM

User avatar
RowdyVoyeur
Established Member
Posts: 9
Joined: Mon May 27, 2024 1:44 pm
Location: Portugal
Been thanked: 1 time
Contact:

Re: Select channels with alsa_out

Post by RowdyVoyeur »

tavasti wrote: Wed May 29, 2024 8:52 am

Device is locked with that one alsa_in, but that is not really any problem: you have all the ports visible, so you just make jack connections you need.

I don't have all the ports visible, only the playback ports created with alsa_out.

Unless, of course, I use alsa_out -j "MC101_out" -d hw:CARD=MC101,DEV=0 -r 44100 -p 64 -n 4 -c 2, instead of alsa_out -j "MC101_out" -d hw:CARD=MC101,DEV=0 -r 44100 -p 64 -n 4 -c 4. But then, I can't get audio into the MC-101, because I need MC101_out:playback_3 and MC101_out:playback_4 to bring the audio into the MC-101.

Hence, I'm trying to create only ports with channels 3 and 4, so I leave channels 1 and 2 alone for alsa_in. Even then I'm not sure I'll not be presented with the same error

Code: Select all

Unable to set hw params for playback: Invalid argument Setting of hwparams failed: Invalid argument
tavasti
Established Member
Posts: 2101
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Has thanked: 396 times
Been thanked: 213 times
Contact:

Re: Select channels with alsa_out

Post by tavasti »

RowdyVoyeur wrote: Wed May 29, 2024 10:18 am
tavasti wrote: Wed May 29, 2024 8:52 am

Device is locked with that one alsa_in, but that is not really any problem: you have all the ports visible, so you just make jack connections you need.

I don't have all the ports visible, only the playback ports created with alsa_out.

Ports in and out are not dependent of each other. If your interface has 4 channels in and 4 channels out, you can use 4 channels in and 4 channels out.

Earlier it was impossible to use both alsa_in and alsa_out for same interface, because which ever you start running first will occupy whole interface. If that is your case, you need jack modules zalsa_in and zalsa_out.

Linux veteran & Novice musician

Latest track: https://www.youtube.com/watch?v=ycVrgGtrBmM

User avatar
RowdyVoyeur
Established Member
Posts: 9
Joined: Mon May 27, 2024 1:44 pm
Location: Portugal
Been thanked: 1 time
Contact:

Re: Select channels with alsa_out

Post by RowdyVoyeur »

tavasti wrote: Wed May 29, 2024 10:49 am

Earlier it was impossible to use both alsa_in and alsa_out for same interface, because which ever you start running first will occupy whole interface. If that is your case, you need jack modules zalsa_in and zalsa_out.

Thanks! That's not entirely the case.

In generic mode, the MC-101 has 2 ins and 2 outs via USB. If I use generic mode, I can create capture and playback ports with alsa_in, alsa_out or jack_load and connect everything with jack_connect. However, I get some occasional audio artefacts.

In vendor mode - which should require a driver but apparently it doesn't - it has 4 ins and 2 outs. If I use vendor mode, I need to use input channels 3 and 4 in order to hear the audio in.

Given that in generic mode I can easily create capture and playback ports with alsa_in, alsa_out or jack_load, I thought than in vendor mode I should be able to to the same. However, if I use alsa_out to create ports for all the 4 input channels, then I'm presented with the following message when I run alsa_in to create the capture ports:

Code: Select all

Unable to set hw params for playback: Invalid argument Setting of hwparams failed: Invalid argument

I'm assuming this happens because I create ports with all the 4 channels. If I only use 2 channels in alsa_out, using the parameter -c 2 instead of -c 4, then I can use alsa_in without any errors. The downside is that, because I need to use channels 3 and 4 for audio in, then I won't be able to hear the audio in.

Thank you very much for your help. I hope this makes sense. I'm trying my best to explain everything, but sometimes I'm not sure this is clear.

tavasti
Established Member
Posts: 2101
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Has thanked: 396 times
Been thanked: 213 times
Contact:

Re: Select channels with alsa_out

Post by tavasti »

RowdyVoyeur wrote: Wed May 29, 2024 1:27 pm

Thanks! That's not entirely the case.

In generic mode, the MC-101 has 2 ins and 2 outs via USB. If I use generic mode, I can create capture and playback ports with alsa_in, alsa_out or jack_load and connect everything with jack_connect. However, I get some occasional audio artefacts.

In vendor mode - which should require a driver but apparently it doesn't - it has 4 ins and 2 outs. If I use vendor mode, I need to use input channels 3 and 4 in order to hear the audio in.
...
Thank you very much for your help. I hope this makes sense. I'm trying my best to explain everything, but sometimes I'm not sure this is clear.

Ok, now it makes more sense what you are asking. And have to say I cannot help. It might be that code just does not suport such use case, and possibly you need to code something by yourself or ask if for example falktx would be willing to write needed code.

Linux veteran & Novice musician

Latest track: https://www.youtube.com/watch?v=ycVrgGtrBmM

User avatar
RowdyVoyeur
Established Member
Posts: 9
Joined: Mon May 27, 2024 1:44 pm
Location: Portugal
Been thanked: 1 time
Contact:

Re: Select channels with alsa_out

Post by RowdyVoyeur »

tavasti wrote: Wed May 29, 2024 1:41 pm

Ok, now it makes more sense what you are asking. And have to say I cannot help. It might be that code just does not suport such use case, and possibly you need to code something by yourself or ask if for example falktx would be willing to write needed code.

Thank you very much for your time!

tavasti
Established Member
Posts: 2101
Joined: Tue Feb 16, 2016 6:56 am
Location: Kangasala, Finland
Has thanked: 396 times
Been thanked: 213 times
Contact:

Re: Select channels with alsa_out

Post by tavasti »

tavasti wrote: Wed May 29, 2024 1:41 pm

Ok, now it makes more sense what you are asking. And have to say I cannot help. It might be that code just does not suport such use case, and possibly you need to code something by yourself or ask if for example falktx would be willing to write needed code.

I took a look in code: alsa_in/alsa_out code change is not sufficient, would need to make some modification/addition to alsalib, and did not check alsalib sources & syscalls, would it need also modification in kernel...

Linux veteran & Novice musician

Latest track: https://www.youtube.com/watch?v=ycVrgGtrBmM

User avatar
RowdyVoyeur
Established Member
Posts: 9
Joined: Mon May 27, 2024 1:44 pm
Location: Portugal
Been thanked: 1 time
Contact:

Re: Select channels with alsa_out

Post by RowdyVoyeur »

tavasti wrote: Fri May 31, 2024 1:52 pm

I took a look in code: alsa_in/alsa_out code change is not sufficient, would need to make some modification/addition to alsalib, and did not check alsalib sources & syscalls, would it need also modification in kernel...

Thank you very much, once again!

A suggestion someone made on a different thread helped me finding the solution.

Apparently the MC-101 has 10 outs and 4 ins in Vendor mode and I need to create ports for all out and in channels to avoid error.

I'll just leave it here if anyone needs to use the MC-101 in Vendor mode on a Raspberry Pi 4 running Patchbox OS 2024-04-04 (without installing any drivers, given there are no drivers for Debian):

Code: Select all

alsa_in -j "MC101_in" -d hw:MC101,DEV=0 -r 44100 -p 64 -n 4 -c 10 &

alsa_out -j "MC101_out" -d hw:MC101,DEV=0 -r 44100 -p 64 -n 4 -c 4 &

This creates ports for the following channels:

  • 10 Channels Out:1+2 for Master Out; 3+4 for Track 1; 5+6 for Track 2; 7+8 for Track 3; 9+10 for Track 4

  • 4 Channels In: 1+2 for Master In (which bypasses controls, i.e. always on regardless of the settings); 3+4 for PC In (which allows controls, i.e. you can pick only L or R channels and route them as you wish)

Which then can be, for example, connected like this:

Code: Select all

jack_connect MC101_in:capture_1 system:playback_1

jack_connect MC101_in:capture_2 system:playback_2

jack_connect system:capture_1 MC101_out:playback_3

jack_connect system:capture_2 MC101_out:playback_4
Post Reply