AM625: Audio not working for 8k sample rate in audio codec TLV320AIC32X4 interfaced with AM6252 via MCASP

Part Number: AM625
Other Parts Discussed in Thread: TLV320AIC3204,

Tool/software:

Hi TI team,

I'm working with the TLV320AIC3204 audio codec, which is interfaced with the AM6252 via McASP. In my setup, the codec operates as the master, with MCLK supplied through an external oscillator at 12.288 MHz. The BCLK and WCLK are also generated by the codec.

My requirement is to play audio using the codec at 8 kHz, 16 kHz, 32 kHz, and 48 kHz sample rates in different applications. One observation is that when I run a GStreamer pipeline with 48 kHz first, then stop and try running it with another sample rate, it throws an error: "unable to set hw_params."

With other NXP processors, I have not encountered such an issue.

Please find the dts modifications:

 codec_audio1: sound1 {
        compatible = "simple-audio-card";
        simple-audio-card,name = "AM625x-TLV320AIC3204";        
        simple-audio-card,widgets =
            //    "Microphone", "Mic Jack",
        //    "Headphone", "Headphone Jack";
            "Line", "Line In",
            "Line", "Line Out";
            simple-audio-card,routing =
                "Line Out", "HPL",
            "Line Out", "HPR",
            "IN1_L", "Line In",
            "IN1_R", "Line In";
        //    "IN1_L", "Mic Jack",
        //    "IN1_R", "Mic Jack",
        //    "Headphone Jack", "HPL",
        //    "Headphone Jack", "HPR";                
        simple-audio-card,format = "i2s";
        //simple-audio-card,mclk-fs = <256>;
        simple-audio-card,bitclock-master = <&sound_master1>;
        simple-audio-card,frame-master = <&sound_master1>;
        //simple-audio-card,bitclock-inversion;

        simple-audio-card,cpu {
            sound-dai = <&mcasp0>;
        };

        sound_master1: simple-audio-card,codec {
            sound-dai = <&tlv320aic3204>;
            clocks = <&tlv_mclk>;
        };
    };

    tlv_mclk: tlv-mclk {
        compatible = "fixed-clock";
        #clock-cells = <0>;
        clock-frequency = <12288000>;
    };

    tlv320aic3204: audio-codec@18 {
        compatible = "ti,tlv320aic32x4";
        reg = <0x18>;
        #sound-dai-cells = <0>;
        //aic3x-micbias-vg = <2>;
        ldoin-supply = <&vcc_3v3_sys>;
    iov-supply = <&vcc_3v3_sys>;
    dv-supply = <&vcc_1v8>;
    av-supply = <&vcc_1v8>;
    clocks = <&tlv_mclk>;
        clock-names = "mclk";
        status = "okay";    
      };

&mcasp0 {
    status = "okay";
    #sound-dai-cells = <0>;
    pinctrl-names = "default";
    pinctrl-0 = <&main_mcasp0_pins_default>;
    
    op-mode = <0>;          /* MCASP_IIS_MODE */
    tdm-slots = <2>;
    /* 16 serializers */
    serial-dir = <  /* 0: INACTIVE, 1: TX, 2: RX */
           1 2 0 0
           0 0 0 0
           0 0 0 0
           0 0 0 0
    >;
    tx-num-evt = <32>;
    rx-num-evt = <32>;
};

Please treat it on high priority .

Thanks & Regards

SHEKAR NUTHULA

    main_mcasp0_pins_default: main-mcasp0-pins-default {
        pinctrl-single,pins = <
            AM62X_IOPAD(0x01a4, PIN_INPUT, 0) /* (B20) MCASP0_ACLKX.MCASP0_ACLKX (BCLK)*/
            AM62X_IOPAD(0x01a8, PIN_INPUT, 0) /* (D20) MCASP0_AFSX.MCASP0_AFSX (WCLK) */
            AM62X_IOPAD(0x01a0, PIN_OUTPUT, 0) /* (E18) MCASP0_AXR0.MCASP0_AXR0 (Din) */
            AM62X_IOPAD(0x019c, PIN_INPUT, 0) /* (B18) MCASP0_AXR1.MCASP0_AXR1 (Dout) */    
        >;
    };

  • Hi Shekar,

    Are you trying to play different audio encoded at different sample rates?

    Please share the gstreamer commands you are trying to run?

    Are you able to play different audio files using aplay command?

    Best regards,

    Suren

  • Hi suren ,

    when device gets powered on , we played a .mp3 tone using gstreamer pipeline with 48Khz on self module . For full duplex audio streaming  between two different modules we use 8k sample rate .

    for Tone playing :

    gst-launch-1.0 filesrc location= *.mp3 ! decodebin ! audioconvert ! audioresample ! audio/x-raw,rate=48000,channels=2, format=S16LE ! alsasink device=hw:0,0

    for full duplex between two modules :

    GST_DEBUG=3 gst-launch-1.0 -v     alsasrc device=hw:0,0 !  audioconvert ! audioresample ! queue ! webrtcdsp experimental-agc=true compression-gain-db=90 echo-cancel=true echo-suppression-level=high target-level-dbfs=15 ! queue ! audioconvert ! audioresample ! queue ! audioconvert ! audioresample ! audio/x-raw,rate=8000,channels=1,format=S16LE ! audioconvert ! rtpL16pay ! udpsink host=10.32.1.65 port=8080 async=false     udpsrc uri=udp://10.32.1.46:8080 caps="application/x-rtp, media=audio, clock-rate=8000, encoding-name=L16, channels=1, payload=96" ! queue ! rtpL16depay ! audioconvert ! audioresample ! webrtcechoprobe  !  alsasink device=hw:0,0

  • Hi Shekar,

    Instead of using gstreamer, can you record using alsa arecord utility with 8KHz sample rate and dump into a file? Does that work fine?

    I see you are doing multiple audioconvert ! audio resample on your gstreamer pipeline, any reasons for multiple resampling ??

    Best Regards,

    Suren

  • Hi suren ,

    Using  aplay and arecord for 8khz sample rate  also we are getting noise in recorded file  .  Regarding 

    GST_DEBUG=3 gst-launch-1.0 -v     alsasrc device=hw:0,0 !  audioconvert ! audioresample ! queue ! webrtcdsp experimental-agc=true compression-gain-db=90 echo-cancel=true echo-suppression-level=high target-level-dbfs=15 ! queue ! audioconvert ! audioresample ! queue ! audioconvert ! audioresample ! audio/x-raw,rate=8000,channels=1,format=S16LE ! audioconvert ! rtpL16pay ! udpsink host=10.32.1.65 port=8080 async=false     udpsrc uri=udp://10.32.1.46:8080 caps="application/x-rtp, media=audio, clock-rate=8000, encoding-name=L16, channels=1, payload=96" ! queue ! rtpL16depay ! audioconvert ! audioresample ! webrtcechoprobe  !  alsasink device=hw:0,0

    The above pipeline consists of 4 audioconvert ! audioresample elements are used for the purpose of streaming of audio between two different modules over ethernet.

     Purposes:

    Sending or transmitting side:

    1.The audio data captured from alsasrc may have an arbitrary sampling rate. To make it compatible with the webrtcdsp element—which only supports sampling rates of 8000, 16000, 32000, and 48000 Hz—the sampling rate must be converted accordingly before processing for echo cancellation and noise suppression.

    2. For plugins compatibility of sampling rates and data we use this audioconvert and audioresample.

    3. After processing, the audio data needs to be transmitted over the network via UDP. To make the data compatible with network transmission, it must be converted to a format and sampling rate acceptable by the rtpL16pay element, which is used to packetize raw PCM audio.

    Receiving side:

     

    4. On the receiving side, audio data is received over UDP and must be decoded and converted to match the format supported by alsasink (e.g., number of channels, sampling rate, bit depth). The fourth capsfilter or conversion stage is used to ensure the received audio is compatible with the audio hardware for proper playback.

  • Hi Shekar,

    Thanks for the details.

    Can you provide the file that you dumped using arecord?

    arecord -D hw:0,0 -r 8000 -c 2 -f S16_LE -d 20 test.wav with your current setup? I assume the codec should be able to capture at 8KHz

    Are you saying the above test.wav file is noisy?

    I want to rule out whether its a kernel side or user-space side problem.

    Best Regards,

    Suren

  • Hi Suren ,

    Yeah sure , i will provide the recorded file . One thing i observed when try to loopback from mic to speaker using  8khz sample rate

    gst-launch-1.0 alsasrc device="hw:0,0" ! audioconvert ! audioresample ! audio/x-raw, rate=8000 ! alsasink device="hw:0,0"

    im getting clock as

    MCLK : 12.288Mhz from OSC to Codec

    BCLK : 242 khz ( expected 256khz)

    WCLK : 8KHz    

    There is mismatch in Bclk value which is  expected to get 256khz ( (sample rate * format *channels)=(8000*16*2)) .

    I assume noise might be due mismatch is BCLK .

    Where as im getting expected clocks for other sample rates of 16khz , 32 khz and 48khz . Please check from your side as well .

  • Hi Shekhar.

    So all other sampling rates apart from 8KHz are working fine? 

    We are trying to run some tests on our setup, will keep you posted on the results.

    Best Regards,

    Suren

  • Hi Suren ,

    Yeah, we didn't observe any issues with other sample rates like 16 kHz, 32 kHz, and 48 kHz. However, our application team is requesting support for 8 kHz so they can reduce the CPU utilization of the SoM compared to higher sample rates.

    Thanks & Regards

    SHEKAR NUTHULA

  • Hi Suren,

    Any timelines on the test results for 8KHz?

    Best Regards,

    Madhurya 

  • Hi Madhurya,

    We are working with the codec team to understand the difference in BCLK in a working and non-working scenario. 

    Best Regards,

    Suren

  • Hi Shekar,

    Can you also share us the codec register dump page 0 and page 1 in both working scenario(48KHz) and non-working case (8KHz)?

    page 0 has the clocking settings, page 1 has the volume and routing settings. 

    Best Regards,

    Suren

  • Hi Suren ,

    Please find the register dump of codec for page 0 and page 1

    in working case with 16khz

    root@myd-am62x:~# i2cset -f -y 1 0x18 0x00 0x00
    root@myd-am62x:~# i2cdump -f -y 1 0x18
    No size specified (using byte-data access)
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
    00: 00 00 60 00 03 91 08 1a 0a 00 00 9a 81 01 00 02    ..`.?????..???.?
    10: 00 08 9a 82 80 01 00 04 00 00 01 0c 00 01 88 00    .?????.?..??.??.
    20: 00 00 00 00 c4 a0 10 00 00 00 0a 00 00 00 00 00    ....???...?.....
    30: 00 00 00 00 00 12 02 02 02 00 00 00 01 01 00 94    .....????...??.?
    40: 00 d8 d8 00 6f 38 00 00 00 00 00 ee 10 d8 7e e3    .??.o8.....???~?
    50: 00 c0 00 00 00 00 00 00 7f 00 00 00 00 00 00 00    .?......?.......
    60: 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ?...............
    70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    root@myd-am62x:~# i2cset -f -y 1 0x18 0x00 0x01
    root@myd-am62x:~# i2cdump -f -y 1 0x18
    No size specified (using byte-data access)
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
    00: 01 00 00 04 00 00 00 00 00 20 00 10 08 00 00 00    ?..?..... .??...
    10: 02 02 40 40 00 00 00 00 00 00 00 00 00 00 00 00    ??@@............
    20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    30: 00 00 00 00 40 00 40 00 00 40 00 80 80 00 03 80    ....@.@..@.??.??
    40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    70: 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00    ...........?....
    80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    root@myd-am62x:~#

    IN NOT WORKING CASE WITH 8KHZ

    root@myd-am62x:~# i2cset -f -y 1 0x18 0x00 0x00
    root@myd-am62x:~# i2cdump -f -y 1 0x18
    No size specified (using byte-data access)
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
    00: 00 00 60 00 03 91 08 20 8d 00 00 a0 81 01 a8 02    ..`.??? ?..?????
    10: 00 08 b5 82 80 01 00 04 00 00 01 0c 00 01 8e 00    .?????.?..??.??.
    20: 00 00 00 00 c4 a0 10 00 00 00 0a 00 00 00 00 00    ....???...?.....
    30: 00 00 00 00 00 12 02 02 02 00 00 00 01 01 00 94    .....????...??.?
    40: 00 d8 d8 00 6f 38 00 00 00 00 00 ee 10 d8 7e e3    .??.o8.....???~?
    50: 00 c0 00 00 00 00 00 00 7f 00 00 00 00 00 00 00    .?......?.......
    60: 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ?...............
    70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    root@myd-am62x:~# i2cset -f -y 1 0x18 0x00 0x01
    root@myd-am62x:~# i2cdump -f -y 1 0x18
    No size specified (using byte-data access)
         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
    00: 01 00 00 04 00 00 00 00 00 20 00 10 08 00 00 00    ?..?..... .??...
    10: 02 02 40 40 00 00 00 00 00 00 00 00 00 00 00 00    ??@@............
    20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    30: 00 00 00 00 40 00 40 00 00 40 00 80 80 00 03 80    ....@.@..@.??.??
    40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    70: 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 00    ...........?....
    80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
    root@myd-am62x:~#

    Thanks & Regards

    SHEKAR N

  • Hi Shekar,

    I went through the register dump and found that the clock dividers are very strange - and yes, what you measured of ~242kHz as the BCLK is the expected output with these registers. If you are not providing the clock dividers, it looks like the driver does its own calculations (that are very off). I would recommend you manually set the clock divider registers after the driver runs, or in the driver itself.

    I would recommend instead of the current dividers for 8k, using these:

    # J.D = 8.0000
    # DOSR = 256
    # NDAC = 6
    # MDAC = 4
    # BCLK NDIV = 16
    I will attach my annotated notes on the reg dump so you can see what all the dividers are doing. The 16k case also has weird PLL/divider values, but the rounding error is a bit smaller so it is less noticeable. Still, the BCLK does not work out to be exactly what it should, so I would recommend again:
    # J.D = 8.0000
    # DOSR = 256 (already is)
    # NDAC = 6
    # MDAC = 8
    # BCLK NDIV = 8
    Let me know what you think here.
    Best,
    Mir