2023-01-03 04:47 PM
I am using a SAI device on a SMT32WB55. Using it as a wavetable synth that produces a triangle wave.
I am able to play my triangle wave for x amount of time with
HAL_SAI_Transmit_DMA(&hsai_BlockA1, (uint8_t*)data, size);
And later stop it with a timer using :
HAL_StatusTypeDef status = HAL_SAI_DMAStop(&hsai_BlockA1);
Whichever frequency I use for my triangle wave, the sound is fine. However, if I play another note after the first one, I can ear so pop/clicks/tearing that gets worst after each note. If I play diferent notes, I can still hear a trail of the previous note before the right frequency kicks in.
Everything is reset in the triangle wave generator after each note and the array assigned to the dma circular buffer in the transmit function is memset to 0 just in case.
After inspecting the HAL code for the HAL_SAI_DMAStop function, I can see that the dma requests are stopped and the fifo is cleared. So there should be no residual data when DMAStop is called.
Is there something I am missing?
Thank you.
2023-01-04 04:33 AM
Don't you rewrite the table while DMA is still running?
Observe the analog output using oscilloscope, perhaps post waveform.
JW
2023-01-12 05:11 PM
I am rewriting the table using tx complete and tx half complete interrupts so I can keep generating the sound from my waveform continuously. I just tried to set the buffer to 0 and keep the SAI dma playing and the result is what I would like to have. No glitching in the sound.
However, I suspect that using HAL_SAI_DMAStop would be a wiser choice energy wise.
I do not have a scope, but I do have a logic analyzer. I am not sure how to interpret what I see on the bus and cannot trigger and log enough samples to get the whole sequence.
Thank you.
2023-01-12 06:47 PM
Here are some logic analyzer captures that highlights a clear behaviour change.
Notice that the Left and Right channels are getting the same value when I am letting the sai device roll on dma and just setting the buffer to 0 to stop playing (sound is being played during the capture):
And when I am simply adding the HAL_SAI_DMAStop function call, things get weird, there seems to be some mismatch between right and left channel values (I am using I2S in mono mode):
Here is my SAI device configuration: