Audio Streaming and Signal Processing using DMA

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
shRe_2888731
Level 3
Level 3
5 likes given First like received First like given

Hi,

I modified the example project "CE220762_PDM_I2S" so that it would continuously stream sound instead of allowing for recording and then playing the sound. Now I want to do some audio signal processing before playing it. After every time the DMA has completed transferring the N_Samples (256 in the attached project), an interrupt is generated. From my understanding, this should be triggered every 256 * (1/(sampling rate of PDM)). So with sampling rate of 8 Ksps as set in the attached project, the interrupt should be generated every 32 ms. Hence I should have about 32 ms for audio signal processing. However, when I put a delay ( just for testing purpose ) of anything more than about 125 us, I start hearing a noise in the audio streaming indicating that the interrupt is generating about every 125 us. Is my understanding incorrect or have I not implemented the DMA and the PDM/PCM block correctly ?

Kind regards,

Shams

0 Likes
1 Solution
MeenakshiR_71
Employee
Employee
100 likes received 50 likes received 25 likes received

Hello Shams,

I did not test the code but looking at the interrupt handler and the Topdesign configuration, I see that you are introducing the delay before you pull the data out of the "recorded_data" array. What that means is while you are waiting in the delay, the DMA_Record starts transferring PDM samples to the recorded_data array as you have not disabled the channel on completion. This might result in some corruption of the recorded_data array before it gets transferred to the playback array.

Can you try the below items?

1. Move the delay after you enable the DMA_Buffer - it is recommended to do any processing outside the interrupt. So I would recommend you setting a flag and processing the data in the main loop (i.e. move the delay to main loop based on a flag).

2. Change the "channel state on completion" setting of the descriptor to "disable" for DMA_Record and enable the channel after the delay in the interrupt.

I believe this should help. If not, let me know I will try out the project.

Regards,

Meenakshi Sundaram R

View solution in original post

5 Replies
MeenakshiR_71
Employee
Employee
100 likes received 50 likes received 25 likes received

Hello Shams,

I did not test the code but looking at the interrupt handler and the Topdesign configuration, I see that you are introducing the delay before you pull the data out of the "recorded_data" array. What that means is while you are waiting in the delay, the DMA_Record starts transferring PDM samples to the recorded_data array as you have not disabled the channel on completion. This might result in some corruption of the recorded_data array before it gets transferred to the playback array.

Can you try the below items?

1. Move the delay after you enable the DMA_Buffer - it is recommended to do any processing outside the interrupt. So I would recommend you setting a flag and processing the data in the main loop (i.e. move the delay to main loop based on a flag).

2. Change the "channel state on completion" setting of the descriptor to "disable" for DMA_Record and enable the channel after the delay in the interrupt.

I believe this should help. If not, let me know I will try out the project.

Regards,

Meenakshi Sundaram R

Dear Meenakshi Sundaram R,

Yes it works now. Thank you very much.

I also had a couple of other questions just to get a better understanding.

1- Is it also better to move the descriptor settings for buffer DMA from the interrupt to the main loop ? 

2- Is there a better way of using DMA to stream audio than what I am doing ?

Kind regards,

Shams

0 Likes

Shams,

To your questions -

1. If the playback DMA needs to transfer the processed data, then you should do it after you process the data. So it should be in main loop.

2. If the requirement involves - record data, process it and then playback. Then the method you are using is good enough. I would recommend you to have two buffers for the PDM data (make the No. of X loops = 2). So that you don't hold the PDM recording while you are processing the data in one buffer. Make sure the processing is done within one buffer fill duration. Otherwise you will need bigger buffer size.

Regards,

Meenakshi Sundaram R

Dear Meenakshi Sundaram R,

Yes my requirement involves record data, process it and then playback. In order to have two buffers (i.e a 2D DMA), the only setting I have to change is the No. of X loops to 2 ? Because when I do that the audio is corrupted.  Is there any settings that I also have to change for other DMAs ?

Kind regards,

Shams

0 Likes
AnkitaS_51
Employee
Employee
100 likes received 50 likes received 25 likes received

Hi Shams,

Please create another thread for any new query.

Thanks,

Ankita

0 Likes