I am trying to adapt a 16bit audio recorder application for stm32fxxx to 24bit and I have stumbled across a #define
that is confusing me.
I have changed 16bit DMA to 32bit DMA along with some buffers uint16_t
to uint32_t
etc.. no idea why uint32_t
and not signed int but I will look at that later. There's no way to pass 24bits through the DMA so I will send 32bits and drop one byte later.
The 3rd input of HAL_SAI_Transmit_DMA()
actually expects a size value in uint16_t
.
#define AUDIO_OUT_BUFFER_SIZE 16384
#define AUDIODATA_SIZE 2
#define DMA_MAX_SZE 0xFFFF
#define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint16_t Size)
{
// send audio samples over DMA from buffer to audio port
HAL_SAI_Transmit_DMA(&haudio_out_sai, (uint8_t*) pBuffer,
DMA_MAX(AUDIO_OUT_BUFFER_SIZE / AUDIODATA_SIZE));
return AUDIO_OK;
}
I'm guessing i need to change to
AUDIODATA_SIZE 4
#define DMA_MAX_SZE 0xFFFFFFFF // 32bit
But I'd like to know what #define DMA_MAX(x) (((x) <= DMA_MAX_SZE)? (x):DMA_MAX_SZE)
is supposed to be doing and how it even works! its almost written as if its a function? where x
is an IO value?
AUDIODATA_SIZE
is the number of bytes in each sample:
I apologize for being a beginner at C but I never saw anything like this and can only assume its masking the size of the buffer. But why?
pBuffer
is the pointer to the uint16_t*
pointer passed into the function and is cast to (uint8_t*)pBuffer
for the HAL_SAI_Transmit_DMA
as it requires it.
I've never seen pointers cast like that either but it works.