Audio output via onboard DAC's
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-07 1:42 PM
Hi guys, I've never done this before but has anyone used the onboard DACS to produce sound?
Playing a .wav file.
I know the dacs are only 12bit and it should play 8bit wave samples fine but what about 16bit samples?
I'll be receiving my MCU's next week so I can't run a test.
If anyone has done it please let me know if 12bit audio is close to 16bit audio.
Thanks guys, hope to hear from you soon.
Pete. ​
- Labels:
-
STM32H7 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-07 3:42 PM
You'll need to move the 16-bit signed samples in the .WAV into the 12-bit unsigned range of DAC, obviously you'll truncate the low order precision you were holding, but the wave form will be the same, just rougher.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-07 4:43 PM
Thanks Clive. I knew I had to mask out the upper 4 bits.
Now I cant wait for my MCU's​ to arrive next week. Lol.
​Pete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-07 5:11 PM
Not upper but lower 4 bits.
int16_t sample;
uint32_t dac = ((sample >> 4) + 0x800) & 0xFFF;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-07 5:36 PM
The DAC has left and right aligned registers to pull the top or bottom 12-bits, what's more important is the number space conversion, and the fact the output on the DAC will have a DC offset because all the outputs will be between 0 and 3V, not +/-1.5V
From 16-bit you want to use the TOP 12 most significant bits, and lose the 4 least significant bits
if (x < -32767) x = -32767; or if (x == 0x8000) x = 0x8001; // keep within +/-32767
RIGHT ALIGNED: y = (((x + 0x8000) >> 4) & 0xFFF) or
LEFT ALIGNED: y = ((x + 0x8000) & 0xFFF0)
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-07 7:39 PM
Oops, so its the lower 4 bits I have to mask out.
So I just do this ROR R0, R1​, #4 /* R1 has the 16bit sample */
Unless its negative then ROL instead.​
​
I'm an assembler guy, C wastes to many cycles for me.
​
Thank you guys for the help. I'll do a test next week when my hardware arrives.
Pete.
​
​
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-07 8:33 PM
Not exactly, the samples are 16-bit signed, you need to adjust the zero point to get to a 12-bit unsigned range.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-07 9:49 PM
Also remember you may need an audio amplifier to produce sound: The DAC strength even with buffer might be limited.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-08 12:57 AM
Hi, Yep I 'll be using a 5v USB powered external PC Speakers. I think they're 5watts per channel.
Pete
