8bit Mix Tape

From SGMK-SSAM-WIKI

Jump to: navigation, search

Contents

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

8bit mixedTapev01.jpg

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

v0.2

8bit mixedTapev02.jpg

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


What needs to be done

Schematics

see Babygnusbuino for the USB / attiny85 stuff

New pin definitions file: File:Pins arduino.h.zip put in ./sketchbook/hardware/Gnusbuino/variants/attiny85

// ATMEL ATTINY85 / BABYGNUSBUINO
//
//                        +---\/---+
//   !RESET (AD 0) PB5   1|        |8  VCC
//     (D3/A3)PWM? PB3   2|        |7  PB2 / USB+	
//     (D4/A2)PWM? PB4   3|        |6  PB1 / USB- / PWM?
//                  GND  4|        |5  PB0 / D0 / PWM
//                        +--------+
//

Parts

8bit MixTape parts.jpg

Babygnusbuino Parts:

8bit MixTape:

Links

http://youtube.com/watch?v=GtQdIYUtAHg

http://wurstcaptures.untergrund.net/music/

http://wiki.sgmk-ssam.ch/index.php/Babygnusbuino

Code

Basic

/* PCrazy shit 8-bit symphony generator                   
 
   inspired by:
   http://countercomplex.blogspot.com/2011/10/algorithmic-symphonies-from-one-line-of.html
 */
 
int speakerPin = 0;
int potiPin3 = A3;
int potiPin4 = A2;
 
long t = 0; 
int v = 0; 
int c3 = 0;
int c4 = 0;
 
void setup () {
 
  TCCR0B = TCCR0B & 0b11111001; //no timer pre-scaler, fast PWM
 
  pinMode (speakerPin, OUTPUT);
  pinMode (potiPin3, INPUT);
  pinMode (potiPin4, INPUT);
 
}
 
 
void loop ()
{
  c4 = ((analogRead(potiPin4)>>5) + 0); 
  c3 = (analogRead(potiPin3)>>0);
  v = (t*(t>>8|t>>4))>>(t>>c4);
  analogWrite (speakerPin, v);
  delayMicroseconds(c3>>3);
  t++;
}

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;
 }
 
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox