Playing audio from the 12bit DAC vs. 8bit PWM (for Halloween project)

Hey, all.

So, I’m wanting to build a photon-based halloween prop that can play some quick sound effects. I’ve got an Adafruit VS1053 board, but as I was assembling stuff, I wondered about just using the DAC and an amp.

I haven’t yet tried this approach, but I plan on working on it this week some evening. I wanted to get early feedback to see if was even worth chasing.

The idea is to take a very short, mono, 22khz (or 11khz), 8bit PCM .wav (u-law) file and write a script that could turn it into C code directly as an array of 12bit integers. (This also makes it easy to flash)

Then, I’d run use an interrupt timer every 22khz (or 11Khz) to write the next value from the array out to the DAC line. I’d run it through an audio amplifier like Adafruit’s Mono amp to a speaker.

Does that ‘sound’ feasible?

From a hardware perspective, would that approach be better than just using the un- u-lawed 8 bit integer and doing PWM out on a non-DAC pin?

I’m gonna have to re-read specs on .wav files and u-law companding. It’s been a while since I did audio file processing.

Some of my assumptions and/or other areas where I could use a gut check and advice:

  1. Are there any 12 bit audio codecs that are worth looking at? I’m familiar with ffmpeg and sox to convert audio, but I didn’t see any commonly-used 12bit ‘raw’ audio formats. Sox wouldn’t let me convert 16 or 8 bit to 12 bit wav since it’s not a standard.
  2. Assuming the 12bit DAC isn’t going to de-compand u-law, so I have to do it first. Once I have the decompanded 8bit value, I can map it to 12 bit space. I know I’ll lose some quality.
  3. I’m familiar with audio files, but not much with audio electronics and hardware. Will the above amp work ok? I probably have all the parts to build an op-amp -based amplifier, but I have no idea how good they are. I’ve seen some schematics online.

Any input would be awesome!!

Since your quality demands don’t seem too high I’d say you should be OK with the DAC (once its function got restored after some regression with 0.4.6 update).
But as you said you’ll need an amp, the Adafruit should do.

For the 8, 12, 16 bit issue, if you got enough space or if you decide to go with an SD card you could just map a raw 16bit into the 12 bit of the DAC.

But you might also like to look into these topics
Spark Core + Shield Shield + Seeedstudio Music Shield V2.0
Adafruit VS1053 (mp3) library for music maker shield ported?

And this port by the awesome @peekay123

1 Like

@jtzemp, how’d your project turn out? What did you end up using?

Hey, @tjp.

I just stuck with the Adafruit VS1053 board and plugged in a speaker with a built-in amp. The halloween deadline made it more urgent, so I just went for just what works.

“Some day”* I’d like to try to use the DAC and map the values, but I just needed to get it working, so I punted. I’m pretty sure it would work.

* In the immortal words of CCR

1 Like