3

I am newly into ALSA and linux,

How to do mixing of X channels into a single channel using ALSA plugins on record path?

and

How to control volume using alsamixer for each channel?

I am looking into http://www.alsa-project.org/alsa-doc/alsa-lib APIs but didnt find anything suitable, hence asked here. Please guide me to proper direction, sample code or tutorial. I too have looked on SO but i get info on play path.

JRC
  • 808
  • 1
  • 11
  • 26

2 Answers2

1

You need dmix plugin. It is quiet easy to use. In /etc/asound.conf

pcm.<device_name> {
   type dmix        # plugin type
   ipc_key 321456   # any unique value through /etc/asound.conf
   slave {
      pcm "hw:0,0"  # Sound card name
      format S32_LE # That is you format
      rate 44100    # Sampling rate
      channels 2    # You channels count 
   }
}

After restart you should be able open device from different locations and alsa will mix their output. Here some docs about it: http://www.alsa-project.org/alsa-doc/alsa-lib/pcm_plugins.html

0

First, start with a device that allows multiple recording clients:

pcm.snooped {
    type dsnoop
    slave.pcm "hw:0"  # or whatever
}

Then extract single channels:

pcm.channel1 {
    type route
    slave {
        pcm snooped
        channels 2
    }
    ttable [ [ 1 0 ] ]
}

pcm.channel2 {
    type route
    slave {
        pcm snooped
        channels 2
    }
    ttable [ [ 0 1 ] ]
}

Then put a softvol on each of them:

pcm.channel1_softvol {
    type softvol
    slave.pcm channel1
    control.name "Channel 1 Capture Volume"
}
pcm.channel2_softvol {
    type softvol
    slave.pcm channel2
    control.name "Channel 2 Capture Volume"
}

Then merge them into a single device:

pcm.mixed_with_volumes {
    type multi
    slaves {
        a { pcm channel1_softvol channels 1 }
        b { pcm channel2_softvol channels 1 }
    }
    bindings [
        { slave a channel 0 }
        { slave b channel 0 }
    ]
}

... and use a plug plugin to mix the channels together:

pcm.my_device {
    type plug
    slave.pcm mixed_with_volumes
    ttable [ [ 0.5 0.5 ] ]
}
CL.
  • 173,858
  • 17
  • 217
  • 259