Close

Bitcrushing.

A project log for Interdimensional Portal Gun

A 3D printed portal gun, which projects animated portals.

daren-schwenkeDaren Schwenke 03/31/2018 at 01:396 Comments

It just sounds cool... bitcrushing.

Bitcrushing takes an 8 bit audio sample and converts it to 1 bit.  The result is it can then be directly played simply by copying it to a PWM pin.  To do this though, the audio is re-sampled and the sample rate is multiplied by 8.

The main problem with this is that a split second of audio will consume all of the storage you have on an Atmel, so you have to get creative.  You do have control over the playback speed, direction, where you start/stop within the sample, and amplitude though just by how you iterate through your array of values and applying some simple bit shift math.  The end result is a very small sample can be manipulated to produce a wide variety of sounds, but it requires some work.

So one of the remaining outstanding tasks now, hopefully for someone else, is to get something like this playing on a Nano with enough memory and cycles left over to run 4 other channels of PWM too.

In the end, I could just cheat in that I have a couple sd card mp3 players for Arduino in my parts bin, but I'd rather not use them.

Discussions

Yann Guidon / YGDES wrote 03/31/2018 at 04:45 point

If you can afford an external SPI Flash chip, then you could do some fun hack...
With a cheap 4Mb / 512KBytes chip, just connect the Flash' MISO to the amp and let your MCU init the chip and then clock the circuit at a constant rate. The SPI Flash would contain a dithered, Delta-Sigma oversampled 1-bit stream (50KHz ? 100KHz ? ), no signal processing required during playback ! (just add a low-pass filter with a RC network)

  Are you sure? yes | no

Daren Schwenke wrote 03/31/2018 at 07:12 point

That is a really cool idea!  If I actually end up generating a PCB for this, that sounds like a good plan.

  Are you sure? yes | no

Yann Guidon / YGDES wrote 03/31/2018 at 11:03 point

And one more thing :
After a SPI Flash has serialised the end of its addressing space, it wraps around !
So as long as you keep clocking it, the sound will loop and you don't need a high capacity, just isolate a clean sound loop of a few seconds and you can stretch it ad vitam aeternam :-P

  Are you sure? yes | no

Yann Guidon / YGDES wrote 03/31/2018 at 11:04 point

Aaaaand.... you can fake frequency modulation effects by changing the clock frequency :-P

  Are you sure? yes | no

[deleted]

[this comment has been deleted]

Yann Guidon / YGDES wrote 03/31/2018 at 11:36 point

That's my idea :-D
I have used a similar principle to steam video clips to RGB LEDs strips :-)

  Are you sure? yes | no

[deleted]

[this comment has been deleted]

Daren Schwenke wrote 03/31/2018 at 04:19 point

The speaker plus amp I'm using here was $1, so I'm pretty sure that would qualify as low fidelity.  :)

I honestly haven't written a single line of code for this yet.  I'm still just collecting the bits I need and planning, and needed a break from OpenSCAD to stew on some design decisions.

8kb should work just fine with room to spare.  I have 30kb to work with and the libraries I need so far are only 3k.

Thank you for the link and advice.  I've never done this part before...

  Are you sure? yes | no