Go Down

Topic: Translating notes to RTTTL (Read 2563 times) previous topic - next topic

Linkaan

Apr 13, 2016, 05:42 pm Last Edit: Apr 13, 2016, 06:24 pm by Linkaan
Hello,

I play the Super Mario Bros level clear sfx on my arduino with this code:

Code: [Select]

unsigned int C6 = 1047;
unsigned int Ab5 = 831;
unsigned int Bb5 = 932;
unsigned int G5 = 784;
unsigned int F5 = 698;
unsigned int E5 = 659;
unsigned int Eb5 = 622;
unsigned int D5 = 587;
unsigned int Db5 = 554;
unsigned int C5 = 523;
unsigned int B4 = 494;
unsigned int Bb4 = 466;
unsigned int nA4 = 440;
unsigned int Ab4 = 415;
unsigned int G4 = 392;
unsigned int Gb4 = 370;
unsigned int F4 = 349;
unsigned int E4 = 330;
unsigned int Eb4 = 311;
unsigned int D4 = 294;
unsigned int Db4 = 277;
unsigned int C4 = 262;
unsigned int B3 = 247;
unsigned int Bb3 = 233;
unsigned int nA3 = 220;
unsigned int GS3 = 208;
unsigned int G3 = 196;
unsigned int Gb3 = 185;
unsigned int F3 = 175;
unsigned int E3 = 165;

#define speakerPin 11

void setup() {
  pinMode(speakerPin, OUTPUT);
  buzz(speakerPin,G3,166);
  buzz(speakerPin,C4,166);
  buzz(speakerPin,E4,166);
  buzz(speakerPin,G4,166);
  buzz(speakerPin,C5,166);
  buzz(speakerPin,E5,166);
  buzz(speakerPin,G5,500);
  buzz(speakerPin,E5,500);
  buzz(speakerPin,E3,166);
  buzz(speakerPin,C4,166);
  buzz(speakerPin,Eb4,166);
  buzz(speakerPin,Ab4,166);
  buzz(speakerPin,C5,166);
  buzz(speakerPin,Eb5,166);
  buzz(speakerPin,Ab5,500);
  buzz(speakerPin,Eb5,500);
  buzz(speakerPin,Bb3,166);
  buzz(speakerPin,D4,166);
  buzz(speakerPin,F4,166);
  buzz(speakerPin,Bb4,166);
  buzz(speakerPin,D5,166);
  buzz(speakerPin,F5,166);
  buzz(speakerPin,Bb5,500);
  delay(50);
  buzz(speakerPin,Bb5,166);
  delay(50);
  buzz(speakerPin,Bb5,166);
  delay(50);
  buzz(speakerPin,Bb5,166);
  buzz(speakerPin,C6,2000);
}

void loop() {
  // nope!
}

void buzz(int targetPin, long frequency, long length) {
  long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  //// there are two phases to each cycle
  long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
  //// multiply frequency, which is really cycles per second, by the number of seconds to
  //// get the total number of cycles to produce
  for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
    digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait again or the calculated delay value
  }
}


However, I would like to convert it to RTTTL format. Here is an example for Super Mario World Stage Clear:
Code: [Select]
char *song = "smw_clear:d=4,o=5,b=70:8g6,8g6,16e6,8g6,16e6,16g6,16e6,16d6,8g.6,16p,32d6,16d7,16e7,16d7,16e7,16d.7,32d6,32c7,32b6,16a6,8g.6,16p,8g7";


Can someone help me do the same for Super Mario Bros Level Clear?

jurs

Hello,

I play the SMB level clear sfx on my arduino with this code:
I don't think that this code will play anything on your Arduino. You did NOT POST A COMPLETE SKETCH, but only some lines of code fragments, which will not compile error-free.

I neither understand the term " SMB level" and what this might mean, nor do I see any declaration for used constants in your code fragment like the constants (or variables), C4, E4, G4, C5, E5, G5 and so on.

Linkaan

I don't think that this code will play anything on your Arduino. You did NOT POST A COMPLETE SKETCH, but only some lines of code fragments, which will not compile error-free.

I neither understand the term " SMB level" and what this might mean, nor do I see any declaration for used constants in your code fragment like the constants (or variables), C4, E4, G4, C5, E5, G5 and so on.

Sorry this was my first post, I removed those abbreviations and included the complete code.

jremington

Quote
However, I would like to convert it to RTTTL format.
You will have to do that by hand.

jurs

Sorry this was my first post, I removed those abbreviations and included the complete code.
So now I guess that SMB is a three-letter-abbreviation for Super Mario Brothers.

On this page you can find several SMB themes in RTTTL ringtone format, named:


Super Mario Brothers Main Theme
Super Mario Brothers Underground Theme
Super Mario Brothers Death Theme

I don't know if one of them is your melody. Should be easy to find out.

Do you have an RTTTL ringtone player for Arduino to play such melodies?

Linkaan

So now I guess that SMB is a three-letter-abbreviation for Super Mario Brothers.

On this page you can find several SMB themes in RTTTL ringtone format, named:


Super Mario Brothers Main Theme
Super Mario Brothers Underground Theme
Super Mario Brothers Death Theme

I don't know if one of them is your melody. Should be easy to find out.

Do you have an RTTTL ringtone player for Arduino to play such melodies?

Yes, I found those but I can't find the level clear sound (https://www.youtube.com/watch?v=FxjT1RvGnhU), I thought I could get some help translating it, because I don't understand the RTTTL format.

jremington

Quote
I don't understand the RTTTL format.
Neither does the Arduino.

Linkaan

Neither does the Arduino.
Not natively, however I found this simple sketch to play a RTTTL song (too large to include here, so it is an attachment).

That will play Super Mario World stage clear, however I'm just asking for help how I can translate the Super Mario Bros level clear sound effect to RTTTL (not necessarily for someone to do it for me). The song string contains the RTTTL formatted Super Mario World stage clear sound effect.

jurs

Yes, I found those but I can't find the level clear sound (https://www.youtube.com/watch?v=FxjT1RvGnhU), I thought I could get some help translating it, because I don't understand the RTTTL format.
The full technical specification of RTTTL ringtones is explained in Wikipedia:
https://en.wikipedia.org/wiki/Ring_Tone_Transfer_Language

Should be easy to understand. And if you already have a RTTTL decoder/player for Arduino and you have the melody and notes/duration and pause/duration, it should be easy to encode some RTTTL melody string.

Perhaps I can give it a try if I find some time to do the next weekend.

Linkaan

Thanks, I don't understand how I can convert the duration of the notes (the parameter length passed to buzz) to note durations (whole note, half note etc.)

Linkaan

Here is my attempt:
Code: [Select]
char *song = "smb_clear:d=4,o=5,b=180:8g3,8c4,8e4,8g4,8c,8e,3g,3e,8e3,8c4,8e#4,8A#4,8c,8e#,3a#,3e#,8b#3,8d4,8f4,8b#4,8d,8f,3b#,32p,8b#,32p,8b#,32p,8b#,1c6";

The problem is that it doesn't sound correct. Is 3a# equal to buzz(speakerPin,Ab5,500); ??

MalharD

That SOUNDS great.
Thanks for sharing it.
+1 Karma to you

-Malhar
Murphy always gets me ...

jurs

The problem is that it doesn't sound correct. Is 3a# equal to buzz(speakerPin,Ab5,500); ??
One problem with direct translation of note durations is, that normal music can be played faster (more BPM "Beats per Minute!) or slower (less BPM "beats Per Minute"), and the BPM value also has influence on the length of full, half, quarter or eigth notes. Normal note writings are not in milliseconds, but in BPM tempo and half, quarter or eigth notes (which may be prolonged as "dotted notes").

Please watch the RTTTL prefix information:
HauntHouse: d=4,o=5,b=108: 2a4 ...
is meaning: default note length is quarter note, default octave is 5, default BPM ist 108 beats per minute.

So if you want to play the same notes faster, just set a faster default BPM like
HauntHouse: d=4,o=5,b=200: 2a4
With 200 BPM each note becomes shorter, the melody plays faster than played with 108 BPM

Linkaan

One problem with direct translation of note durations is, that normal music can be played faster (more BPM "Beats per Minute!) or slower (less BPM "beats Per Minute"), and the BPM value also has influence on the length of full, half, quarter or eigth notes. Normal note writings are not in milliseconds, but in BPM tempo and half, quarter or eigth notes (which may be prolonged as "dotted notes").

Please watch the RTTTL prefix information:
HauntHouse: d=4,o=5,b=108: 2a4 ...
is meaning: default note length is quarter note, default octave is 5, default BPM ist 108 beats per minute.

So if you want to play the same notes faster, just set a faster default BPM like
HauntHouse: d=4,o=5,b=200: 2a4
With 200 BPM each note becomes shorter, the melody plays faster than played with 108 BPM
Thanks a ton for the help, I got it working after experimenting with it for some time. Here is the final result:
Code: [Select]

smb_clear:d=4,o=5,b=180:8g3,8c4,8e4,8g4,8c,8e,4g.,4e.,8e3,8c4,8d#4,8g#4,8c,8d#,4g#.,4d#.,8a#3,8d4,8f4,8a#4,8d,8f,4a#.,32p,8a#,32p,8a#,32p,8a#,1c6.

Go Up