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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

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

跳至解决方案
2,512 次查看
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

标记 (3)
0 项奖励
回复
1 解答
2,040 次查看
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

在原帖中查看解决方案

4 回复数
2,040 次查看
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 项奖励
回复
2,040 次查看
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 项奖励
回复
2,041 次查看
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,040 次查看
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 项奖励
回复