Data overflow in shift float to int32

Hi,

I use 21571 to process audio datas, the datas format are float. But when I submit audio datas to SPORT to send datas out using  adi_sport_SubmitBuffer() function, the datas need to be int32, I have some questions now.

1) Assum that I use 32bits i2s to transfer datas, what's the format in i2s data line, is it 1.31?

2) It seems like there is auto convert in SHARC cores, after I receive 1.31 datas, I just save datas in int32 buffer and then assign buffers to float variables without any function to convert 1.31 to float. Also when I transmit datas, I only submit int32 datas which is shifted from float without convert int32 to 1.31.

3) If it's 1.31 format, datas range from -1.0 to 1.0 - 2^-31, I find that when float datas out of range, it will overflow to zero rather than clip. How to avoid overflow when shift float datas to int32. Or can I directly submit float datas to SPORT?

Thanks.

  • 0
    •  Analog Employees 
    on Jun 11, 2021 3:26 PM

    Hi,

    We are looking into this query and we will get back to you as early next week.

    Regards,
    Santhakumari.K

  • 0
    •  Analog Employees 
    on Jun 17, 2021 8:41 AM

    Hi Foster,

    Data that is received or transmitted in the SPORT will be a binary, 2's complement format. The DSP interprets the data in fractional format, where all numbers are between -1 and 0.9999999.

    While using the data length as 32, you can assume that the data will be 1.31 fixed point value. You can use the conv_float_by built-in function to convert the fixed point value to floating point value (received from ADC). After processing the float data convert it again to the fixed point data using the conv_fix_by built-in function before sending to DAC.

    You can refer the attached example, there we have used the above built-in functions for the conversions.

    5123.ADC DAC Audio Playback (SC589 SHARC).zip

    Regards,
    Santhakumari.K

  • Hi santha,

    I tested the conv_float_by built-in and conv_fix_by built-in function, but it still can't solve my problem when datas out of range.

    Assume that I receive a data and it's 0.8 in float, of course the data is in range. Then I multiply it by 2, so it's 1.6 now which is out of range.  If I use  conv_fix_by built-in function and send it out to DAC, the result is not what I want. 

    I mean that I need the data 1.6 be cliped to 0.999 rather than rather the data overflow and accidently change the sige bit which make it to a negative, such as -0.5. I just give an example and don't mean 1.6 will be change to -0.5 since I don't know what data it will be exactly. I want to know is there any solution to make 1.6 clip to 0.999 and -1.6 clip to -1.

  • +1
    •  Analog Employees 
    on Sep 29, 2021 1:04 PM in reply to Foster

    Hi Foster,

    In saturation mode (the REGF_MODE1.ALUSAT bit is set) positive overflows and +infinity return the maximum positive number (0x7FFF FFFF), and negative overflows and infinity return the minimum negative number (0x8000 0000).

    Please try to set ALUSAT bit before converting float to fix as below:
    sysreg_bit_set(sysreg_MODE1,0x2000 );

    Regards,
    Santhakumari.K