2023-01-21 11:51 PM
project audio-player : sending data by DMA -> SPI/I2S to DAC :
at first i read from SDcard (void bytes) as it is, to playbuffer, send it by circular DMA ("halfword") on I2S (16 bit) to DAC (as standard I2S 2 x 16 bit frames); working perfect.
to use hi-res music (24...32 bit) then needing 32 bit data, so at first changed SPI to "16bit in 32bit frames" , works also fine.
then set SPI to 32 bit frames with 32bit data, DMA to "word" transfer (is 32 bit...?should be),
reading I2S data from file to a buffer and transfer 16->32 bit to (now) int32 playbuffer.
ok - no more music, just noise...scrambled data !
after hours...i just tried shifting the bytes totally "wrong" together - and music played.
my suspicion was: wrong endianess - and this seems to be the problem.
what i cannot understand here: same data played fine as int16 block, without any byte reorder: for int32 i shifted the int16<<16 , but this didnt work. it works with:
playbuf[a]=(inbuf[a*2]) + (inbuf[(a*2)+1]<<8);
this is bytes (1->0) in wrong order and on lower 16bits of the int32 - then it is little-endian right? but why did int16 transfer work without any byte reorder ??
and next problem: i make a digital filter before playback, calculation is in double ; switch on filter and no music, just noise - or nothing, silence.
because i had no idea, what happens now, just read int32 -> to double -> back to int32 destroys data totally. so i looked with DSO, what is on transfer now:
(reordered) source file:
but with filter :
obviously filter makes 32bit output -ok, but half-word shifted - wrong!
what happens here?? seems like upper and lower int16 are exchanged, after int_>float->int conversion. this is ...too much . last idea: i set DMA to transfer "half word" memory to "word" target - changed nothing, no exchange on 16bit int.
is there a way, to set the DMA -> I2S to really send I2S standard, as in 16bit mode also in 32 bit mode? (didnt see errata, that I2S 32bit not working)
and how to do simple (and fast) int32->float->int32 conversion /casting , to get endianess right ?
(assuming : i need big endian int32 data for DMA->I2S , but little endian for mathematics on H7 , like int32-> double conversion )
2023-01-28 03:39 AM
Oooo... never correct working with 32bit data. and even more: after some restarts sometimes (!) other timing...but also wrong. this is too much on wrong - i give up on this.
there is the SAI interface, can also work on I2S mode , so i try this.
hey, works (after some trouble, to get it working) with 16bit data AND with 32bit data also !!!!
and no endianess problem, just DMA transfers int32 to SAI (in slave mode), obviously correct: