cancel
Showing results for 
Search instead for 
Did you mean: 

Playing Audio clips over I2S, array of samples are stored in flash memory?

mani s
Associate III

@

Hi Team,

I want to play audio clips over I2S like  short audio clips - Connected to device , Disconnected etc, so. I converted .wav file to C- code (Im using WAVtoC software to convert C-code)and stored in flash memory. Below I attached the .wav to c code file.

I'm using DA7212 Codec to play these audio clips over I2S.

 These Audio clips has 8k sampling rate, 16bit bits per sample. Total number of samples around 3500.

I tried with interrupt method to transmit data of 512bytes each, pls check below code

  1. Number of elements are defined 3500 samples  
  2.  uint16_t *firstarray=STEREO_AUD_DATA;  // data is stored Stereo format 
  3. unsigned short   STEREO_AUD_DATA[2*NUM_ELEMENTS];

void ConncetAUD(){

int i=0;

// store data in stereo format

for(int i=0;i<NUM_ELEMENTS;i++){

STEREO_AUD_DATA[(i*2)] = PowerOndata[i];        //left

STEREO_AUD_DATA[(i*2)+1] = PowerOndata[i];        //right

}

firstarray=STEREO_AUD_DATA;

while(i < 15){

if(HAL_I2S_GetState(&CODEC_I2S) == HAL_I2S_STATE_READY){

HAL_I2SEx_TransmitReceive_IT(&CODEC_I2S,firstarray,rxBuffer, 512);  // will get callback event here-HAL_I2SEx_TxRxCpltCallback

Display(("voice prompt :%d\n",*firstarray));        

i++;                

osDelay(200);

}

}

}

3. update data in call back function.

void HAL_I2SEx_TxRxCpltCallback(I2S_HandleTypeDef *hi2s){

firstarray += 512;

}

 I'm sure that I configured codec registers properly, I can able to play music and all, which is connected to BT. I'm using stm32f4 series microcontroller, the DA7212 is connected to this controller.

/**********************************************************************
* Written by WAVToCode
* Date:				Fri Jun 21 03:32:38 PM
* FileName:			Sine_500Hz.C
* Interleaved:		Yes
* Signed:			No
* No. of channels:	1
* No. of samples:	226400
* Bits/Sample:		16
**********************************************************************/
 
#define NUM_ELEMENTS 226400
 
BYTE data[NUM_ELEMENTS] = {
32767, 33236, 33698, 34157, 34613, 35049, 35489, 35899, // 0-7
36306, 36687, 37052, 37394, 37712, 38006, 38274, 38511, // 8-15
38724, 38900, 39052, 39167, 39252, 39303, 39322, 39307, // 16-23
39257, 39179, 39062, 38921, 38739, 38537, 38297, 38034, // 24-31
37744, 37425, 37089, 36724, 36344, 35942, 35528, 35096, // 32-39
34657, 34201, 33748, 33277, 32818, 32347, 31883, 31425, // 40-47
30969, 30527, 30095, 29673, 29273, 28884, 28522, 28173, // 48-55
27857, 27555, 27290, 27047, 26831, 26654, 26496, 26379, // 56-63
26293, 26234, 26216, 26227, 26270, 26350, 26459, 26601, // 64-71
26777, 26978, 27214, 27472, 27765, 28075, 28415, 28773, // 72-79
29155, 29551, 29966, 30397, 30834, 31290, 31743, 32209, // 80-87
32674, 33142, 33605, 34068, 34520, 34964, 35402, 35817, // 88-95
36229, 36608, 36984, 37325, 37653, 37947, 38225, 38463, // 96-103
38687, 38865, 39026, 39145, 39239, 39294, 39323, 39310, // 104-111
39272, 39195, 39090, 38950, 38779, 38579, 38347, 38090, // 112-119
37803, 37492, 37157, 36798, 36423, 36023, 35612, 35185, // 120-127
34741, 34299, 33832, 33379, 32904, 32444, 31974, 31517, // 128-135
31059, 30617, 30176, 29760, 29350, 28960, 28594, 28240, // 136-143
27917, 27617, 27337, 27096, 26870, 26687, 26526, 26400, // 144-151
26306, 26245, 26216, 26222, 26259, 26331, 26434, 26573, // 152-159
26735, 26939, 27161, 27422, 27702, 28011, 28347, 28697, // 160-167
29079, 29469, 29884, 30307, 30750, 31192, 31657, 32112, // 168-175
32584, 33046, 33515, 33973, 34433, 34874, 35317, 35734, // 176-183
36148, 36534, 36911, 37257, 37592, 37887, 38174, 38416, // 184-191
38646, 38831, 38996, 39125, 39221, 39288, 39318, 39316, // 192-199
39281, 39216, 39111, 38982, 38815, 38621, 38396, 38145, // 200-207
37860, 37558, 37225, 36872, 36499, 36105, 35694, 35273, // 208-215
34831, 34386, 33929, 33467, 33001, 32536, 32067, 31608, // 216-223
3115,............}

0 REPLIES 0