Close

Arduino example source code

A project log for Beverly-Crusher: bit crushing toy for 1-bit audio.

I had been looking for a tool to convert audio down to 1-bit depth but gave up and wrote my own. Supports export for Arduino sketch.

electronoobElectronoob 10/06/2014 at 15:480 Comments
/*

  beverly-crusher (build 82) [http://electronoob.com]

  Released under the terms of the MIT license.
  Copyright (c) 2014 electronoob.
  All rights reserved.

*/

#include <avr/pgmspace.h>

/* truncated example sample see github for working and complete example */
prog_uchar onebitraw[] PROGMEM = {
  0XFF, 0XFF, 0XEF, 0XFF, 0XFB, 0XFF,...
}

#define BC_BIT_COUNT 23040
#define BC_BYTE_COUNT 2880
#define SPK_PIN 5

void setup(){ pinMode(SPK_PIN, OUTPUT); }

void loop(){
	unsigned char bite;
        int col; col = 0;
        int i;
        for(i=0;i<BC_BYTE_COUNT;i++){
	  bite = pgm_read_byte_near(onebitraw + i);
          /* let's break up our byte into it's constituent parts. */
          unsigned char mask = 1;
          unsigned char copy = bite;
          int z;
          for (z=0;z<8;z++) {
            digitalWrite(SPK_PIN, copy & mask);
            copy = copy >> 1;
            delayMicroseconds(227);
          }
        }
}

https://github.com/electronoob/beverly-crusher/blob/master/arduino/example/example.ino

Discussions