How to read audio data in SAI example SDK for i.MXRT1050-EVKB

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to read audio data in SAI example SDK for i.MXRT1050-EVKB

Jump to solution
2,969 Views
marcus_masca
Contributor I

Hi all,

I am trying to read the audio data from the sai_edma_record_playback example where the program records and plays back audio data from the on-board MIC and process 16 bit samples of the data at 8khz (30 millisecond audio frames).

I have looked at the xfer.data buffer however it doesn't seem to contain the correct data.

Could anyone help me with this? (attached is the code, sourced from the SDK)

Many thanks

Tags (3)
0 Kudos
Reply
1 Solution
2,497 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Hello Marcus,

1. your No.1 reply: It means captured data via MIC is no problem.
2. your No.2 reply:
---Audio format
(1) you may know ADC bit number(8bit or 16bit) by codec driver.
(2) Audio format: It is original captured data, not encoded(mp3,etc), just like .wav file in windows.
---8bit to 16bit opreations
you can get some similar method from internet, see the link, and compare it, please!
https://stackoverflow.com/questions/28655211/how-to-convert-8bit-sound-to-16bit

Have a nice day!
Best Regards,
TIC weidong sun

View solution in original post

4 Replies
2,497 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Hello Marcus,

     I wants to know below information, could you provide it to me?

(1) Record voice via MIC, and playback it.  Audio you hear is OK?

(2) How do you know data in buffer is not correct ?

Thanks!

Best regards,

Weidong Sun

0 Kudos
Reply
2,497 Views
marcus_masca
Contributor I

Hello Weidong Sun,

1. Yes, demo application records and plays back the audio perfectly. I connect a speaker to the jack and can hear the audio from the Mic.

2. To be specific, I read the data from (Buffer + tx_index*BUFFER_SIZE) where 'Buffer' is (supposedly) a uint8_t array containing the audio data. I then encode it using an encoder. When I decode the encoded data and play it, the the audio is scrambled and I cannot identify any of the microphone data. It is not a problem with the encoding/decoding of the data since I have successfully decoded sample data (in format 16-bit sample) and played it through the speakers fine.

Are you able to confirm where exactly the microphone audio data is stored and in which format? Furthermore, how I can convert it to 16 bit samples? I require the audio data to be in a 16bit array of size 240 (for compatibility with my encoder)

I would be grateful for your help.

Marcus

My code that converts the microphone audio data to an array of 16 bit samples is as follows:

/* Create 16 bit array */

uint16_t * Mic16[240];

/* Capture audio data in 8 bit array */

uint8_t * Mic8= (Buffer + tx_index*BUFFER_SIZE);

/* Copy data from 8 bit array to 16 bit array (note: different endianness for platform) */

for (int i = 0; i < 240; i++)

{

      Mic16[i] = ((uint16_t * Mic8++ << 8 );

      Mic16[i] |= (uint16_t * Mic8++;

}

/* Encode Mic16*/

/* Decode Mic16*/

0 Kudos
Reply
2,498 Views
weidong_sun
NXP TechSupport
NXP TechSupport

Hello Marcus,

1. your No.1 reply: It means captured data via MIC is no problem.
2. your No.2 reply:
---Audio format
(1) you may know ADC bit number(8bit or 16bit) by codec driver.
(2) Audio format: It is original captured data, not encoded(mp3,etc), just like .wav file in windows.
---8bit to 16bit opreations
you can get some similar method from internet, see the link, and compare it, please!
https://stackoverflow.com/questions/28655211/how-to-convert-8bit-sound-to-16bit

Have a nice day!
Best Regards,
TIC weidong sun

2,497 Views
marcus_masca
Contributor I

Hello Weidong Sun,

Thank you for your reply. I have managed to convert the 8 bit samples into 16 bit samples correctly. I think that was my problem. Also I am using an external mic connected to the audio jack and have set the stereo format to kSAI_MonoLeft. This seems to have solved the problem!

Many thanks,

Marcus

0 Kudos
Reply