Retro Game Sounds with the Arduino

Hi,

I did some retro sounds with the arduino:

(AlienBird, AlienUfo, AlterMotor, Laser1, TimeUp, IntoWarp)

Hardware was just a simple 1bit to Lineout RC, then recorded with Audacity.

I cant give you the exact code, as it evolved over time and some effects I was never able to reproduce (also used some modulation with 2 potis). Here is a code which uses some LFO modulation:

/*

 Verrückte Töne kontrolliert von zwei Potis (oder Kreuzknüppel)
 
 April 2009 Carsten Wartmann 
 cw (*) blenderbuch.de 
 
 */

#define BEEP 12   // Ausgangspin im einfachsten Fall direkt an einen Piezo-Schallwandler
#define POTX 4    // Analog 4
#define POTY 5    // Analog 5

// Das Lesen der Potis geschieht in einem Interrupt
#include <MsTimer2.h>
volatile long  pitchval = 1;
volatile long  delayval = 1;
volatile int LFO=1;
volatile int LFOD = 3;

void setup()
{
  pinMode(BEEP,OUTPUT);
  // Init und Start der Interrupt-Routine  
  MsTimer2::set(2, getPots);   // Alle 5ms  
  MsTimer2::start();

}


// freqout code by Paul Badger 
// freq - frequency value
// t - time duration of tone
// Angepasst für "lustige Töne"...
void freqout(int freq, int t) 
{ 
  long hperiod;     //calculate 1/2 period in us 
  long cycles, i; 

  // subtract 7 us to make up for digitalWrite overhead - determined empirically 
  hperiod = (50130000 / ((freq - 7) * pitchval));             

  // calculate cycles 
  cycles = ((long)freq * (long)t) / 1000;    // calculate cycles 

  for (i=0; i<= cycles; i++)
  {              // play note for t ms  
    digitalWrite(BEEP, HIGH);  
    delayMicroseconds(hperiod*LFO/10); 
    digitalWrite(BEEP, LOW);  
    delayMicroseconds((hperiod - 1)*LFO/10);     // - 1 to make up for fractional microsecond in digitaWrite overhead 
  } 
}

// Interrupt Routine
void getPots()
{
  pitchval = analogRead(POTX); 
  delayval = analogRead(POTY)-250;  // Y Poti ist leider defekt...
  LFO=LFO+LFOD;
  /*
  // Triangle
  if (LFO>100 || LFO<1)
  {
    LFOD=LFOD*-1;
    }
    */
  // Sägezahn
  if (LFO>100)
  {
    LFO=1;
    }
}


void loop()
{
  int ran = 150;
  freqout(440+random(ran),delayval);
//  delay(delayval/2);
  freqout(340+random(ran),delayval);
//  delay(delayval/2);
  freqout(240+random(ran),delayval);
  delay(delayval/2);
}

Best regards,
Carsten

wow that sounds really cool :smiley:

Awesome. Could you make sounds from super Mario bros?
Then you could hook up an accelerometer and make the sounds when it senses motion, so when you jump, it makes the noises!

Awesome. Could you make sounds from super Mario bros?
Then you could hook up an accelerometer and make the sounds when it senses motion, so when you jump, it makes the noises!

i agree :slight_smile: tahat would be so cool. then get a super mario costume to go with it :sunglasses:

Super Mario... Don't know its a while since I played it (or any other game).

However I doubt it because I did aproach it from the practical side (read: playing/hacking until something interesting happens) so no guaratie I will ever be able to copy a sound :wink:

However I achieved some nice sounds for a game that I have in the pipeline (yes I don't play games but make some ;-)):

Carsten