Skip to main content
RKhal.2
Associate III
September 17, 2020
Question

stm32l4 SAI code

  • September 17, 2020
  • 9 replies
  • 2185 views

Hi,

I am using STM32L476G-DISCO Board, I want to interface its mic and read audio , process it and transmit it on audio jack, to listen audio,

can any body help me or provide me code to do this.

Thanks

Regards

This topic has been closed for replies.

9 replies

waclawek.jan
Super User
September 17, 2020

Review Projects/Examples in CubeL4.

JW

RKhal.2
RKhal.2Author
Associate III
September 18, 2020

I got it, and it fulfill my requirement.

Thank you so much :)

RKhal.2
RKhal.2Author
Associate III
September 18, 2020

Mr. wclawek.jan now I want to encrypt audio stream, how I can do this...?

this is code main body code

int main(void)
{
 uint32_t i;
 /* STM32L4xx HAL library initialization:
 - Configure the Flash prefetch
 - Systick timer is configured by default as source of time base, but user 
 can eventually implement his proper time base source (a general purpose 
 timer for example or other time source), keeping in mind that Time base 
 duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
 handled in milliseconds basis.
 - Set NVIC Group Priority to 4
 - Low Level Initialization
 */
 HAL_Init();
 
 /* Configure the system clock to have a frequency of 80 MHz */
 SystemClock_Config();
 
 /* Configure LED4 */
 BSP_LED_Init(LED4);
 
 /* Initialize DFSDM channels and filter for record */
 DFSDM_Init();
 
 /* Initialize playback */
 Playback_Init();
 
 /* Start DFSDM conversions */
 if(HAL_OK != HAL_DFSDM_FilterRegularStart_DMA(&DfsdmFilterHandle, RecBuff, 2048))
 {
 Error_Handler();
 }
 
 /* Start loopback */
 while(1)
 {
 if(DmaRecHalfBuffCplt == 1)
 {
 /* Store values on Play buff */
 for(i = 0; i < 1024; i++)
 {
 PlayBuff[2*i] = SaturaLH((RecBuff[i] >> 8), -32768, 32767);
 PlayBuff[(2*i)+1] = PlayBuff[2*i];
 }
 if(PlaybackStarted == 0)
 {
 if(0 != audio_drv->Play(AUDIO_I2C_ADDRESS, (uint16_t *) &PlayBuff[0], 4096))
 {
 Error_Handler();
 }
 if(HAL_OK != HAL_SAI_Transmit_DMA(&SaiHandle, (uint8_t *) &PlayBuff[0], 4096))
 {
 Error_Handler();
 }
 PlaybackStarted = 1;
 } 
 DmaRecHalfBuffCplt = 0;
 }
 if(DmaRecBuffCplt == 1)
 {
 /* Store values on Play buff */
 for(i = 1024; i < 2048; i++)
 {
 PlayBuff[2*i] = SaturaLH((RecBuff[i] >> 8), -32768, 32767);
 PlayBuff[(2*i)+1] = PlayBuff[2*i];
 }
 DmaRecBuffCplt = 0;
 }
 }
}

waclawek.jan
Super User
September 18, 2020

This is where incoming samples are copied into the output buffer:

>        PlayBuff[2*i]    = SaturaLH((RecBuff[i] >> 8), -32768, 32767);

So, presumably, this is where you add your encryption, whatever it is

PlayBuff[2*i]    = YourEncryption(SaturaLH((RecBuff[i] >> 8), -32768, 32767));

I have no idea what do you expect from this - it will play back nothing but noise - but I also am not interested.

JW

RKhal.2
RKhal.2Author
Associate III
September 23, 2020

Dear JW,

I want to encrypt audio stream,

let me explain to you....!

let suppose I have two stm32l4-discovery board "a" and "b", board "a" get voice from its mic and send to controller, controller encrypt it and send to audio jack, this audio jack is connected to board "b" (instead of mic on board "b") , controller(of board "b") get this encrypted audio decrypt it and transmit to audio jack of of board "b", and here we can hear audio by using handsfree to this jack, I hope you have understand...!

Thanks

Regards

waclawek.jan
Super User
September 23, 2020

You can't encrypt the analog audio, encryption does not work in this way.

You would need to take the digital audio, encrypt it, then encode that digital signal into analog using something similar that the olde phone modems did (see V.23/V.22/V.32 etc.), convert into analog, on the other end convert back to digital and decode, then decrypt and convert into the analog audio signal. That requires nontrivial DSP processing and/or a significantly higher transfer bandwidth than you'd think.

JW

RKhal.2
RKhal.2Author
Associate III
September 24, 2020

ok thanks dear.

tell me this can be possible by using STM32L4-DISCO board????

waclawek.jan
Super User
September 24, 2020

I don't know.

JW

RKhal.2
RKhal.2Author
Associate III
September 24, 2020

Ok thank you so much ....!