8bit Mix Tape

From SGMK-SSAM-WIKI
Revision as of 06:38, 4 February 2013 by Dusjagr (talk | contribs) (→‎Code)
Jump to navigation Jump to search

Overview

The 8bit MixTape is an arduino compatible sound gadget, based on the BabyGnusbuino (anyma) and Viznut's "Algorithmic symphonies from one line of code", put together by dusjagr, ucok and iyok...


Prototypes

v0.1

{{#widget:Vimeo|id=58727965}}

First version using a BabyGnusbuino attached to a card-board tape dummy

v0.2

{{#widget:Vimeo|id=58831051}}

New version, v0.2, nicely fits into a tape, with battery, USB programming interface, LEDs and a button to choose different codes.


Code

8bit MixTape with button selector

/* Crazy shit 8-bit symphony generator                   */
/*     */
 
/*
 * inspired by:
 *  http://countercomplex.blogspot.com/2011/10/algorithmic-symphonies-from-one-line-of.html
 */
 
int speakerPin = 0;
int buttonPin = 2;
int potiPin3 = A3;
int potiPin4 = A2;
 
int buttonState = 0; 
int lastButtonState = 0;
int count = 0;

unsigned long int pulseWidthOFF = 0;
unsigned long int pulseWidthON = 0;
unsigned long int pulseWidthPart = 0;

int samplingDelay;
unsigned long int reg;

long t = 0; 
int v = 0; 
unsigned int c3 = 0;
unsigned int c4 = 0;

unsigned int analogValue;
 
void setup () {
  
  TCCR0B = TCCR0B & 0b11111001;
  
  pinMode (speakerPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  pinMode (potiPin3, INPUT);
  pinMode (potiPin4, INPUT);

  reg = 0x551155aaL;
 
}
 
 
void loop () {
  // read the state of the switch into a local variable:
  buttonState = digitalRead(buttonPin);
  
  if (buttonState != lastButtonState && buttonState == HIGH) {
    // if the state has changed, increment the counter
      count++;
      t = 0; 
      delay(10000); 
      if (count > 5) {
        count = 0;
      } 
    
  } 
  
  lastButtonState = buttonState;
 

 switch(count) {
   
 case 0: // a classic
     c4 = ((analogRead(potiPin4)>>6) + 1); 
     c3 = (analogRead(potiPin3)>>0);
     v = (t*(t>>8|t>>4))>>(t>>c4);
    analogWrite (speakerPin, v);
    delayMicroseconds(c3>>2);
    t++;
 
    break;
    
 case 1: // ding dong
 
     c4 = ((1023-(analogRead(potiPin4))>>6) + 1); 
     c3 = (analogRead(potiPin3)>>0);
     v = t * ((t>>15|t>>c4)&83&t>>(c4>>3));
     digitalWrite (speakerPin, v);
     delayMicroseconds(c3<<2);
     t++;
 
    break;
    
 case 2: // experimental 8 bit
 
     c4 = ((1023-(analogRead(potiPin4))>>6) + 1); 
     c3 = (analogRead(potiPin3)>>0);
     v = t * ((t>>15|t>>c4)&83&t>>(c4>>3));
     analogWrite (speakerPin, v);
     delayMicroseconds(c3);
     t++;
 
    break;
  
  
 case 3: // PWM modulation
 
     c3 = (analogRead(potiPin3));
     c4 = (analogRead(potiPin4) + 1);


     pulseWidthPart++;
     
     pulseWidthON = (c3 * pulseWidthPart / 255);
     pulseWidthOFF = (c3 - pulseWidthON);
          
     digitalWrite(speakerPin, HIGH);
     delay(pulseWidthOFF);
     digitalWrite(speakerPin, LOW);  
     delay(pulseWidthON); 

    if (pulseWidthPart == 255) {
      pulseWidthPart = 254 - (c4>>3);
    }
     break;
    
 case 4: //white noise
 
     unsigned long int newr;
     unsigned char lobit;
     unsigned char b31, b29, b25, b24;
 
     b31 = (reg & (1L << 31)) >> 31;
     b29 = (reg & (1L << 29)) >> 29;
     b25 = (reg & (1L << 25)) >> 25;
     b24 = (reg & (1L << 24)) >> 24;
 
    lobit = b31 ^ b29 ^ b25 ^ b24;
 
    newr = (reg << 1) | lobit;
   
    reg = newr;
  
    digitalWrite (speakerPin, reg & 1);
    samplingDelay = 1 + (2*(analogRead(potiPin3)>>0));
 
    delayMicroseconds (samplingDelay);
    
    break;
 }

}

Schematics

Links

http://youtube.com/watch?v=GtQdIYUtAHg http://wurstcaptures.untergrund.net/music/ http://wiki.sgmk-ssam.ch/index.php/Babygnusbuino