cancel
Showing results for 
Search instead for 
Did you mean: 

Speech input & output

ssena.1514
Associate III

Hi,

I want to implement a speech IO using stm32f401 discovery board.

In this case I am using the onboard digital microphone to acquire the PDM samples using spi2(I2S) interface. After that I am using the PDM filter to convert the PDM samples to PCM

samples .The respective code(code reused) snippet is given below.

void AUDIO_REC_SPI_IRQHANDLER(void)

{  

 uint16_t volume;

 uint16_t app;

 /* Check if data are available in SPI Data register */

 if (SPI_GetITStatus(SPI2, SPI_I2S_IT_RXNE) != RESET)

 {

  app = SPI_I2S_ReceiveData(SPI2);

   

  In_Buf[InternalBufferSize++] = HTONS(app);

  /* Check to prevent overflow condition */

  if (InternalBufferSize >= INTERNAL_BUFF_SIZE)

  {

   InternalBufferSize = 0;

   

   volume = 10;

PDM_Filter_64_LSB((uint8_t *)In_Buf, (uint16_t *)Out_Buf, volume ,(PDMFilter_InitStruct *)&Filter_var);

Data_Status = 1;

}

}

}

where

uint16_t In_Buf[INTERNAL_BUFF_SIZE];//PDM sample buffer 

uint16_t Out_Buf[OUT_BUFF_SIZE];//PCM sample buffer 

&

#define INTERNAL_BUFF_SIZE 128 //PDM in_buffer size

#define OUT_BUFF_SIZE   16 //PCM out_buffer size

In this way I am collecting the PCM samples in Out_Buf.

So my question here is how to send the mono speech pcm samples from Out_Buf to audio codec so that I will get perfect output without distortion.

As per my understanding I have done the coding like this(descrided below).

while(1)

{

if(Data_Status)

{

  GPIO_SetBits(GPIOD,GPIO_Pin_13);//orange led = PCM data available indicator

   if (SPI_I2S_GetFlagStatus(CODEC_I2S, SPI_I2S_FLAG_TXE))

   {

   SPI_I2S_SendData(CODEC_I2S, sample);

   //update only on every second sample to insure that L & R ch. have the same sample value

   if (sampleCounter & 0x00000001)

   {

  

     sample = Out_Buf[sample_index++];

//f_sample = fir_filter(sample);//filter the samples & send to codec 

     if(sample_index>=OUT_BUFF_SIZE) sample_index=0;

  

   }

   sampleCounter++;

   }///if end for data transmission 

   if (sampleCounter==16000)

   {

   GPIO_SetBits(GPIOD,GPIO_Pin_15);//blue=sample counter indicator

   }

   else if (sampleCounter == 32000)

   {

   GPIO_ResetBits(GPIOD,GPIO_Pin_15);

   sampleCounter = 0;

   }

}//if end for PCM data available

 }//while end

The problem is that I am not getting the correct output.

So kindly explain me where is the problem & how to solve this.

Tools - KEIL IDE

Board - STM32F401 DISCO

Thanks & Regards

Satyabrata Senapati

0 REPLIES 0