Pages: [1]   Go Down
Author Topic: Play Taps (Musical Piece Played at Military Funerals) on 8ohm Speaker!  (Read 1358 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 1
Posts: 282
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd like to play Taps (Musical Piece Played at Military Funerals) on a 8ohm Speaker!  Could someone help me understand the notes of this riveting melody better?  Thanks!

http://en.wikipedia.org/wiki/Taps


* 700px-Taps_music_notation.svg.png (9.86 KB, 700x69 - viewed 29 times.)
« Last Edit: January 19, 2013, 04:41:44 pm by encryptor » Logged

peace*&^

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Notes of the scale are:

F ------------
E
D-------------
C
B--------------
A
G--------------
F
E---------------
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 If you play the song using the wiki site, you can watch the "seconds" counter to approximate the duration of the notes.

My guitar tuner says that the notes are in the range of 347 to 700Hz.....not sure if the frequency readings are correct.
Logged


Offline Offline
Sr. Member
****
Karma: 1
Posts: 282
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that is a great idea!  I have one of those, but did not think of using it until now. smiley-eek
Logged

peace*&^

Offline Offline
Sr. Member
****
Karma: 1
Posts: 282
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Using flat on my guitar tuner I got my frequency readings as 3G, 7B, 2B, 4D.  I understand Middle C is 440Hz for B flat, however I don't know where to go from here.  I want to translate my notes into integer frequencies.  I tried understanding it thru google, but am still lost.  Any help please? smiley-mr-green
Logged

peace*&^

Offline Offline
Newbie
*
Karma: 1
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I was looking at something similar today... You could try modifying the tone example with the following.. The notes are correct, but the timings are rough.

Code:
/*
  Melody
 
 Plays a melody
 
 circuit:
 * 8-ohm speaker on digital pin 8
 
 created 21 Jan 2010
 modified 30 Aug 2011
 by Tom Igoe

This example code is in the public domain.
 
 http://arduino.cc/en/Tutorial/Tone
 
 */
 #include "pitches.h"

// notes in the melody:
int melody[] = {
  NOTE_G4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5, NOTE_E5, NOTE_G4, NOTE_C5, NOTE_E5, NOTE_G4, NOTE_C5, NOTE_E5, NOTE_G4, NOTE_C5, NOTE_E5, NOTE_C5, NOTE_E5, NOTE_G5, NOTE_E5, NOTE_C5, NOTE_G4, NOTE_G4, NOTE_G4, NOTE_C5};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  2,2,1,2,2,1,2,2,2,2,2,2,2,2,1,2,2,1,2,2,1,2,2,1};

void setup() {
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 24; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
  }
}

void loop() {
  // no need to repeat the melody.
}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The third-party polytonal Tone library has a list of frequencies you can use:
Code:
#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Musical Note Frequencies -
Guitar and Piano

http://www.vaughns-1-pagers.com/music/musical-note-frequencies.htm
Logged


Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Reading across the music:
Quote
G
G
C
G
C
E
G
C
E
G
C
E
G
C
E
C
E
G+
E
C
G
G
G
E
Note:  G+ is an octave higher than the other Gs

Then you can convert those to pitch names:
Quote
NOTE_G4
NOTE_G4
NOTE_C4
NOTE_G4
NOTE_C4
NOTE_E4
NOTE_G4
NOTE_C4
NOTE_E4
NOTE_G4
NOTE_C4
NOTE_E4
NOTE_G4
NOTE_C4
NOTE_E4
NOTE_C4
NOTE_E4
NOTE_G5
NOTE_E4
NOTE_C4
NOTE_G4
NOTE_G4
NOTE_G4
NOTE_E4

You can put those in an array, make another array of note durations, and play them in a loop.

Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Sr. Member
****
Karma: 1
Posts: 282
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is what I came up with!  Please like on YouTube!  Let me know if you see any room for improvement in the code.  Thanks!

http://youtu.be/jfFyKfDBaWE

Code Used:
Code:
/*
  Melody
 
 Plays a melody
 
 circuit:
 * 8-ohm speaker on digital pin 8
 
 created 21 Jan 2010
 modified 30 Aug 2011
 by Tom Igoe
 modified by Evan Johnson Jan 2013 "Taps" melody and 3 fading leds.

This example code is in the public domain.
 http://arduino.cc/en/Tutorial/Tone
 */
 
 #include "pitches.h"

// notes in the melody:
int melody[] = {NOTE_G4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5, NOTE_E5, NOTE_G4,
                NOTE_C5, NOTE_E5, NOTE_G4, NOTE_C5, NOTE_E5, NOTE_G4, NOTE_C5,
                NOTE_E5, NOTE_C5, NOTE_E5, NOTE_G5, NOTE_E5, NOTE_C5, NOTE_G4,
                NOTE_G4, NOTE_G4, NOTE_C5};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {2,4,1, 2,4,1, 4,4,2, 4,4,2, 4,4,1, 2,4,1, 2,2,1, 2,4,1};

int redLedPin = 3;    // red LED connected to digital pin 3
int whiteLedPin = 5;  // white LED connected to digital pin 5
int blueLedPin = 6;   // blue LED connected to digital pin 6

void setup() {
 
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5)
  {
    // sets the value (range from 0 to 255):
    analogWrite(redLedPin, fadeValue);
    analogWrite(whiteLedPin, fadeValue);
    analogWrite(blueLedPin, fadeValue);     
    // wait for 30 milliseconds to see the dimming effect   
    delay(40);                           
  }
 
  // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 24; thisNote++) {

    // to calculate the note duration, take one second
    // divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 2500/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.05;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
  }


  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5)
  {
    // sets the value (range from 0 to 255):
    analogWrite(redLedPin, fadeValue);
    analogWrite(whiteLedPin, fadeValue);
    analogWrite(blueLedPin, fadeValue);   
    // wait for 30 milliseconds to see the dimming effect   
    delay(40);                           
  }
}

void loop()
{

}
Logged

peace*&^

Connecticut, USA
Offline Offline
Full Member
***
Karma: 8
Posts: 224
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's pretty cool.  smiley-cool
Great job, thanks for sharing.
Logged

It's all about the skills

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The note timings need some work.  The dotted half note should be the same length as three quarter notes (the dot means 'half again as long".  But to get that you would need a divisor of 4/3 which is not an integer.

Perhaps you could store the note durations as number of 16th notes:

Code:
int noteDuration = (2500 * noteDurations[thisNote]) / 16;

Then the durations would be:
Code:
// Number of 16th notes per note:
int noteDurations[] = {3,1, 12,3,1,  12,2,2,  4,2,2,4,2,2,  12,2,2,  8,4,4,  12,3,1, 12};

It may be my imagination but some of the early notes seemed an octave high.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: