This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Audio Routing in ti sdk 7

Dear TI E2E Community,

I have stereo codec , where I have two MIC input channels to stereo codec & two output (ie., Left & right channels) of the stereo codec, performing the stereo operations where the same I have verified in ti sdk7 (ie., stereo operations)

Could you please let me know how the stereo channels can be converted to two different & independent Mono channels,

as am new to alsa, hope some configurations needs to be done in alsa or does it requires any changes in the codec driver please let me know

Could you please kindly let me know how this can be converted to two different Mono channels from stereo in ti sdk 7

As am trying this from many days couldn't able to succeed

Kindly do the needful as early as possible

Awaiting for your replies

Many Many Thanks in advance

  • Hi Srini,

    If I understand well you are want to split one stereo signal to two mono. This is made in many of audio/video programs, but I advice you to see convertion of ffmpeg program. The conversion is located in: ffmpeg-2.0.1/libavcodec/resample.c file in static void stereo_to_mono(short *output, short *input, int n1). The good here is that you can test how this is work with ffpmeg program and to compare with your results. Of course you have to modify code for your purpose. Also I post you some usefull site to see how this is made:
    www.dsprelated.com/.../1.php
    www.codeproject.com/.../How-to-convert-between-most-audio-formats-in-NET

    BR
    Ivan
  • Dear Ivan,

    Thanks a lot for your quick replies,

    As am new to ffmepg I feel it will be more compilicated rather than hope I I get in low level alsa driver only, could you please let me know whether this can be done in low level alsa driver only??

    As actually my requirement is I have to place a GSM call via stereo codec where FAR END & NEAR END communications (ie., FULL DUPLEX - FAR END MIC ---> NEAR END SPEAKER & NEAR END MIC ---> FAR END SPEAKER) needs to established

    1) Actually my query is related to I need to convert two ADC channels (of UDA1345TS , Could you please refer the block diagram of UDA1345TS datashee) ie., VINL & VINR as two different mic input channels & two DAC channels ie., VOUTL & VOUTR as two different mono output channels,

    As currently it is left & right channels (stereo) (ie., VOUTL & VOUTR as stereo), in my codec driver only ie., sound/soc/codecs/uda134x.c

    /* Common DAPM widgets */
    static const struct snd_soc_dapm_widget uda134x_dapm_widgets[] = {

    SND_SOC_DAPM_INPUT("VINL"),
    SND_SOC_DAPM_INPUT("VINR"),
    SND_SOC_DAPM_OUTPUT("VOUTL"),
    SND_SOC_DAPM_OUTPUT("VOUTR"),
    };

    static const struct snd_soc_dapm_route uda134x_dapm_routes[] = {


    { "ADC", NULL, "VINL" },
    { "ADC", NULL, "VINR" },
    { "VOUTL", NULL, "DAC" },
    { "VOUTR", NULL, "DAC" },
    };

    Is there any possibilities that above routing which is configured for stereo , how this can be changed to two different mono MIC input channels & two different mono output channels so that (ie., FULL DUPLEX - FAR END MIC ---> NEAR END SPEAKER & NEAR END MIC ---> FAR END SPEAKER) can be achieved??

    Could you please let me know how this can be done in low level driver itself ie., in ALSA in ti sdk 7 ie., in my codec driver only ie., sound/soc/codecs/uda134x.c ie., VINL & VINR as two different mic input channels & two DAC channels ie., VOUTL & VOUTR as two different mono output channels,

    Is there any thing other than that I need to take care in audio routing part of ALSA or any configuration needs to be done in etc/asound.conf

    2) OR am planning to use alsa loop back feature does this is going to resolve my requirement (ie., FULL DUPLEX), if so could you please suggest me how audio loop back can be tested as am not aware how to test this feature ?? I have configured the kernel as below

    │ Symbol: SND_ALOOP [=y] │
    │ Type : tristate │
    │ Prompt: Generic loopback driver (PCM) │
    │ Location: │
    │ -> Device Drivers │
    │ -> Sound card support (SOUND [=y]) │
    │ -> Advanced Linux Sound Architecture (SND [=y]) │
    │ -> Generic sound devices (SND_DRIVERS [=y]) │


    And in in etc/asound.conf

    # default device
    pcm.!default {
    type plug
    slave.pcm "loop"
    }

    Please correct me if my understanding ins wrong inorder to achieve my requirment (ie., FULL DUPLEX ) gsm call on audio

    Once again appreciate a lot for all your quick responses

    Kindly do the needful as early as possible

    Awaiting for your replies

    Many Many Thanks in advance again
  • Hello,

    You could try  to use gstreamer for example:

    Here is example pipeline which uses alsa for capture then split the two channels and save them  in different files:


    gst-launch -v alsasrc device="plughw:X,X" ! audio/x-raw-int, signed=true, width=32, depth=32, format=S32LE, rate=96000, channels=2
    ! deinterleave name=d d.src0 ! queue ! audioconvert ! audio/x-raw-int,channels=1,width=16,depth=16 ! filesink location=first.pcm d.src1 ! queue ! audioconvert ! audio/x-raw-int,channels=1,width=16,depth=16 ! audioresample ! 'audio/x-raw-int, endianness=(int)1234, signed=(boolean)true,rate=(int)44100' ! filesink location=second.pcm

    It also will convert the rate etc, which you could change. You shall change this as well: device="plughw:X,X".

    BR
    Margarita

  • Thanks a lot for your quick repsonses

    I am planning to verify this feature in low level alsa driver

    Could you please let me know with detailed procedure how "SND_ALOOP" feature can be tested & verified in ti sdk 7 ie., alsa loop back I have configured the driver in linux

    I have added in etc/asound.conf

    # default device
    pcm.!default {
    type plug
    slave.pcm "loop"
    }


    But am unable to verify this alsa loop back feature with my stereo codec i.e, am unable to record what ever am playing

    OR

    As I read  am going through ALSA loopback tutorial

    Could you please get me the full source code of the below explained link

    http://www.saunalahti.fi/~s7l/blog/2005/08/21/Full%20Duplex%20ALSA.html

    Could you please let me know how to make this code working ie., does this code requires any etc/asound.conf configurations please let me know


    Once again appreciate a lot for all your quick responses

    Kindly do the needful as early as possible

    Awaiting for your replies

    Many Many Thanks in advance again

  • 1) Could anybody please let me know how the above feature can be verified in alsa loop back feature in ti sdk 7 with detailed steps as early as possible


    2) I have a stereo codec with two mic inputs (MIC1 & MIC2) & two ouputs (left & right channels)
    Could you please confirm does this alsa loop back corresponds, MIC1 to left channel & MIC2 to right channel ie., Is it possible to feed the MIC1 input to left channel of stereo codec & MIC2 input to right channel of stereo codec using this alsa loop back feature???


    Once again Many Thanks & appreciate a lot for all your quick responses

    Kindly do the needful as early as possible

    Awaiting for your replies

    Many Many Thanks in advance again
  • Dear Technical Team,

    Please kindly ignore the answer for the above query w.r.t alsa loop back

    1) I prefer to take care in low level alsa driver only as am a platform guy & am not aware of gstreamer or ffmeg, could you please first confirm whether the GSM call via stereo codec ie., can it be handled & taken care in the routing part of alsa??

    2) I have modified the routing in sound/soc/codecs/uda134x.c  inorder to handle a GSM call via stereo codec, could anybody please confirm whether the following configurations are correct or not?? in ti sdk 7 or if this is not the correct link could you please let me know the respective link to be posted w.r.t the below query

    static const struct snd_kcontrol_new uda1345_snd_controls[] = {

    SOC_SINGLE("Master Playback Volume", UDA134X_DATA000, 0, 0x3F, 1),

    SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]),

    SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0),

    SOC_DAPM_PIN_SWITCH("GSM Line Out"),

    SOC_DAPM_PIN_SWITCH("GSM Line In"),

    SOC_DAPM_PIN_SWITCH("Headset Mic"),

    SOC_DAPM_PIN_SWITCH("Handset Mic"),

    };

    /* Common DAPM widgets */

    static const struct snd_soc_dapm_widget uda134x_dapm_widgets[] = {

    #if 0

    SND_SOC_DAPM_INPUT("VINL"),

    SND_SOC_DAPM_INPUT("VINR"),

    SND_SOC_DAPM_OUTPUT("VOUTL"),

    SND_SOC_DAPM_OUTPUT("VOUTR"),

    #endif

    SND_SOC_DAPM_LINE("GSM Line Out", NULL),

    SND_SOC_DAPM_LINE("GSM Line In", NULL),

    SND_SOC_DAPM_MIC("Headset Mic", NULL),

    SND_SOC_DAPM_MIC("Handset Mic", NULL),

    };

    static const struct snd_soc_dapm_route uda134x_dapm_routes[] = {

    #if 0

    { "ADC", NULL, "VINL" },

    { "ADC", NULL, "VINR" },

    { "VOUTL", NULL, "DAC" },

    { "VOUTR", NULL, "DAC" },

    #endif

    { "ADC", NULL, "VINL" },

    { "ADC", NULL, "VINR" },

    {"VINL", NULL, "GSM Line In"}, 

    {"VINR", NULL, "GSM Line In"}, 

    { "VOUTL", NULL, "DAC" },

    { "VOUTR", NULL, "DAC" },

    {"GSM Line Out", NULL, "VOUTL"},

    {"GSM Line Out", NULL, "VOUTR"},

    /* Connections to Headset */

    {"VINL", NULL, "Mic Bias"},    

    {"Mic Bias", NULL, "Headset Mic"},  

    /* Call Mic */

    {"VINR", NULL, "Mic Bias"},

    {"Mic Bias", NULL, "Handset Mic"}, 

    };


    Kindly do the needful as early as possible, as am stuck with this from many days

    Awaiting for your replies

    Many Many Thanks in advance again

  • could anybody please reply to my above queries w.r.t routing or loop back
  • Kinldy requesting any TI engineers, anybody please help me out w.r.t this thread as early as possible from two days there are no responses for this queries, Kindly do the needful as early as possible, because of which my release is getting blocked


    SND_ALOOP is not working, could you please let me know what is the problem am unable to playback & am unable to record as well

    am planning to use alsa loop back feature (ie., FULL DUPLEX), if so could you please suggest me how audio loop back can be tested as am not aware how to test this feature ?? I have configured the kernel as below in ti sdk 7

    │ Symbol: SND_ALOOP [=y] │
    │ Type : tristate │
    │ Prompt: Generic loopback driver (PCM) │
    │ Location: │
    │ -> Device Drivers │
    │ -> Sound card support (SOUND [=y]) │
    │ -> Advanced Linux Sound Architecture (SND [=y]) │
    │ -> Generic sound devices (SND_DRIVERS [=y]) │


    mcasp0_pins: mcasp0_pins {
    pinctrl-single,pins = <
    0x1ac (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_ahclkx - MCLK */
    0x190 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_aclkx - BCK */
    0x194 (PIN_INPUT_PULLDOWN| MUX_MODE0) /* mcasp0_fsx - WS */
    //0x198 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* mcasp0_axr0 - DATAO */
    //0x1a8 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_axr1 - DATAI */

    0x198 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_axr0 - DATAO */
    0x1a8 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* mcasp0_axr1 - DATAI */

    >;
    };


    &mcasp0 {
    pinctrl-names = "default", "sleep";
    pinctrl-0 = <&mcasp0_pins>;
    pinctrl-1 = <&mcasp0_sleep_pins>;

    status = "okay";

    op-mode = <0>; /* MCASP_IIS_MODE */
    tdm-slots = <2>;
    /* 16 serializer */
    serial-dir = < /* 0: INACTIVE, 1: TX, 2: RX */
    2 1 0 0 /*AXR1 --> DATA 0/P FROM PROCESSOR, AXR0 --> DATA I/P PROCESSOR */
    >;
    tx-num-evt = <1>;
    rx-num-evt = <1>;
    };


    # default Arago configuration
    # default device
    pcm.!default {
    type plug
    slave.pcm "loop"
    }

    # output device
    pcm.loopout {
    type dmix
    ipc_key 328211
    slave.pcm "hw:Loopback,0,0"
    }

    # input device
    pcm.loopin {
    type dsnoop
    ipc_key 686592
    slave.pcm "hw:Loopback,1,0"
    }

    # duplex plug device
    pcm.loop {
    type plug
    slave {
    pcm {
    type asym
    playback.pcm "loopout"
    capture.pcm "loopin"
    }
    }
    }


    root@am335x-evm:/# aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: 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 0: 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
    card 1: UDA1345TS [TI UDA1345TS], device 0: UDA134x uda134x-hifi-0 []
    Subdevices: 1/1
    Subdevice #0: subdevice #0
    root@am335x-evm:/# arecord -f dat -D loop | aplay -f dat -D hw:0,0
    Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
    Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
  • Kinldy requesting any TI engineers, anybody please help me out w.r.t this thread as early as possible from two days there are no responses for this queries, Kindly do the needful as early as possible, because of which my release is getting blocked


    SND_ALOOP is not working, could you please let me know what is the problem am unable to playback & am unable to record as well

    am planning to use alsa loop back feature (ie., FULL DUPLEX), if so could you please suggest me how audio loop back can be tested as am not aware how to test this feature ?? I have configured the kernel as below in ti sdk 7

    │ Symbol: SND_ALOOP [=y] │
    │ Type : tristate │
    │ Prompt: Generic loopback driver (PCM) │
    │ Location: │
    │ -> Device Drivers │
    │ -> Sound card support (SOUND [=y]) │
    │ -> Advanced Linux Sound Architecture (SND [=y]) │
    │ -> Generic sound devices (SND_DRIVERS [=y]) │


    mcasp0_pins: mcasp0_pins {
    pinctrl-single,pins = <
    0x1ac (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_ahclkx - MCLK */
    0x190 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_aclkx - BCK */
    0x194 (PIN_INPUT_PULLDOWN| MUX_MODE0) /* mcasp0_fsx - WS */
    //0x198 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* mcasp0_axr0 - DATAO */
    //0x1a8 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_axr1 - DATAI */

    0x198 (PIN_INPUT_PULLDOWN | MUX_MODE0) /* mcasp0_axr0 - DATAO */
    0x1a8 (PIN_OUTPUT_PULLDOWN | MUX_MODE0) /* mcasp0_axr1 - DATAI */

    >;
    };


    &mcasp0 {
    pinctrl-names = "default", "sleep";
    pinctrl-0 = <&mcasp0_pins>;
    pinctrl-1 = <&mcasp0_sleep_pins>;

    status = "okay";

    op-mode = <0>; /* MCASP_IIS_MODE */
    tdm-slots = <2>;
    /* 16 serializer */
    serial-dir = < /* 0: INACTIVE, 1: TX, 2: RX */
    2 1 0 0 /*AXR1 --> DATA 0/P FROM PROCESSOR, AXR0 --> DATA I/P PROCESSOR */
    >;
    tx-num-evt = <1>;
    rx-num-evt = <1>;
    };


    # default Arago configuration
    # default device
    pcm.!default {
    type plug
    slave.pcm "loop"
    }

    # output device
    pcm.loopout {
    type dmix
    ipc_key 328211
    slave.pcm "hw:Loopback,0,0"
    }

    # input device
    pcm.loopin {
    type dsnoop
    ipc_key 686592
    slave.pcm "hw:Loopback,1,0"
    }

    # duplex plug device
    pcm.loop {
    type plug
    slave {
    pcm {
    type asym
    playback.pcm "loopout"
    capture.pcm "loopin"
    }
    }
    }


    root@am335x-evm:/# aplay -l
    **** List of PLAYBACK Hardware Devices ****
    card 0: 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 0: 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
    card 1: UDA1345TS [TI UDA1345TS], device 0: UDA134x uda134x-hifi-0 []
    Subdevices: 1/1
    Subdevice #0: subdevice #0
    root@am335x-evm:/# arecord -f dat -D loop | aplay -f dat -D hw:0,0
    Recording WAVE 'stdin' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
    Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
  • Srini,

    This is the code to convert stereo to mono. Please see code and adapt to your case.

    /* n1: number of samples */
    static void stereo_to_mono(short *output, short *input, int n1)
    {
    short *p, *q;
    int n = n1;

    p = input;
    q = output;
    while (n >= 4) {
    q[0] = (p[0] + p[1]) >> 1;
    q[1] = (p[2] + p[3]) >> 1;
    q[2] = (p[4] + p[5]) >> 1;
    q[3] = (p[6] + p[7]) >> 1;
    q += 4;
    p += 8;
    n -= 4;
    }
    while (n > 0) {
    q[0] = (p[0] + p[1]) >> 1;
    q++;
    p += 2;
    n--;
    }
    }

    BR
    Ivan
  • Dear Ivan,

    Thanks a lot for your quick responses & for your prompt replies,

    As am new to ALSA, Could you please help me out how this can be achieved in ALSA, it is getting very difficult for me implement the above logic in ALSA,

    Could you please let me know is there any configuration that can be done in asound.conf file?? inorder to convert stereo to mono

    Basically I need to map VINL to VOUTL & VINR to VOUTR (please refer the block diagram of UDA1345TS datasheet page no .6, www.nxp.com/.../UDA1345TS.pdf) please let me know is this mappings can be done in asound.conf file


    Am extremely sorry to push you hard once again

    Kindly do the needful as early as possible, as am stuck with this from many days

    Awaiting for your replies

    Many Many Thanks in advance again
  • Dear Ivan,

    I did the following changes to separate out the stereo output (ie., downmixing stereo to mono) ie., left & right channels to two different mono's in the etc/asound.conf

    # default Arago configuration
    pcm.card0 {
    type hw
    card 0
    }

    ctl.card0 {
    type hw
    card 0
    }

    pcm.monocardright {
    slave.pcm card0
    slave.channels 2
    # type plug
    type route
    ttable {
    # Copy both input channels to output channel 0 (Left).
    0.0 1
    1.1 1
    # Send nothing to output channel 1 (Right).
    0.1 0
    1.1 0
    }
    }

    ctl.monocardright {
    type hw
    card 0
    }

    pcm.monocardleft {
    slave.pcm card0
    slave.channels 2
    # type plug
    type route
    ttable {
    # Copy both input channels to output channel 0 (Left).
    0.1 1
    0.1 1
    # Send nothing to output channel 1 (Right).
    0.0 0
    1.1 0
    }
    }

    ctl.monocardleft {
    type hw
    card 0
    }

    pcm.!default monocardright
    pcm.!default monocardleft

    Now I have two mic inputs, ie., VINL & VINR , if possible could you please let me know how VINL can be mapped to monocardleft & VINR can be mapped to monocardright , I hope this changes can also be done in asound.conf only, could you please help me out in mapping this

    sorry to push you hard once again

    Kindly do the needful as early as possible, as am stuck with this from many days

    Awaiting for your replies

    Many Many Thanks in advance again

  • Dear TI E2E Community

    Now am able to map mic 1 input i.e, VINL to VOUTL & mic 2 input to VINR to VOUTR with the attached asound.conf & after this mapping & I tested one by one VINL to VOUTL path & then I tested VINR to VOUTR path I was able to get working independently

    For my GSM two way call to work I used an application as shown in the attachment which uses both VINL to VOUTL & VINR to VOUTR (for two way call) it opens successfully for playback_handle_right & capture_handle_right but it throws device resource busy when it attempts to open

    ////LEFT CHANNEL
        if ((err = snd_pcm_open (&playback_handle_left, pldevice, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
        fprintf (stderr, "cannot open playback left audio device %s (%s)\n", pldevice, snd_strerror (err)); exit (1);
        }

    Could you please let me know how this issue can be resolved , I understand since both the mono's is mapped to one sound card when it is trying to reopen again (ie., playback_handle_left is trying to open again since because playback_handle_right is already opened) it might be throwing device resource busy error

    Could you please let me know how this issue ie., device resource busy can be resolved ??

    4834.asound_conf.txt6735.alsa_loopback_min.c

    Kindly do the needful as early as possible

    Awaiting for your replies,