Dependencies:   MIDISongPlayer mbed

Files at this revision

API Documentation at this revision

Comitter:
vart
Date:
Mon Nov 02 10:42:41 2015 +0000
Commit message:
initial

Changed in this revision

MIDISongPlayer.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
sound.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MIDISongPlayer.lib	Mon Nov 02 10:42:41 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/vart/code/MIDISongPlayer/#d7b1cc3cb0b6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Nov 02 10:42:41 2015 +0000
@@ -0,0 +1,30 @@
+#include "mbed.h"
+#include "SongPlayer.h"
+#include "sound.h" // test sound
+
+// Song test program - plays a MIDI song using PWM and timer interrupts
+// based on http://mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/
+// can be used to play a song, if you have the MIDI notes sequence
+
+
+
+                    
+DigitalOut led1(LED1);
+
+int main()
+{
+
+// setup instance of new SongPlayer class, mySpeaker using pin D9
+// the pin must be a PWM output pin
+    SongPlayer mySpeaker(D9);
+// Start song and return once playing starts
+    mySpeaker.PlaySong(score3);
+    // loops forever while song continues to play to end using interrupts
+    int cnt=0;
+    while(1) {
+        led1 = !led1;
+        wait(.1);
+        cnt++;
+        if (cnt>100) mySpeaker.StopPlay(); // play 10 second, then stop
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Nov 02 10:42:41 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sound.h	Mon Nov 02 10:42:41 2015 +0000
@@ -0,0 +1,49 @@
+// test MIDI sequence
+// use MIDITONES (https://github.com/LenShustek/miditones)
+// to converts a MIDI music file into a much simplified stream of commands (notes)
+// miditones -t1 <midifile>
+const uint8_t score3 [] = {
+2,138, 0x90,0x3E, 0,100, 0x80, 0,62, 0x90,0x3E, 0,75, 0x80, 0,87, 0x90,0x26, 0,162, 0,100, 
+0,62, 0,50, 0,112, 0,137, 0,25, 0,162, 0,62, 0,100, 0,100, 0,62, 0,37, 
+0,125, 0,37, 0,125, 0,162, 0,175, 0,37, 0,125, 0x80, 0x90,0x3C, 0,37, 0x80, 0,125, 
+0x90,0x3E, 0,75, 0x80, 0,87, 0x90,0x3E, 0,75, 0,25, 0x80, 0,62, 0x90,0x26, 0,62, 0x80, 
+0,12, 0,87, 0x90,0x26, 0,100, 0x80, 0,62, 0x90,0x26, 0,75, 0x80, 0,25, 0,62, 0x90,0x26, 
+0,50, 0,37, 0x80, 0,75, 0x90,0x3E, 0,75, 0,62, 0x80, 0,25, 0x90,0x26, 0,75, 0x80, 
+0,87, 0x90,0x3E, 0,62, 0x80, 0,25, 0,75, 0x90,0x3E, 0,100, 0x80, 0,62, 0x90,0x26, 0,37, 
+0,50, 0x80, 0,75, 0x90,0x3E, 0,37, 0x80, 0,62, 0,62, 0x90,0x3C, 0,87, 0,75, 0,100, 
+0,75, 0x80, 0x90,0x26, 0,37, 0,37, 0x80, 0,87, 0x90,0x3C, 0,37, 0x80, 0,25, 0,100, 
+0x90,0x3E, 0,62, 0,12, 0x80, 0,87, 0x90,0x26, 0,75, 0x80, 0,25, 0,62, 0x90,0x26, 0,62, 
+0x80, 0,12, 0,87, 0x90,0x26, 0,100, 0x80, 0,62, 0x90,0x26, 0,75, 0x80, 0,25, 0,62, 
+0x90,0x26, 0,50, 0,37, 0x80, 0,75, 0x90,0x3E, 0,75, 0,62, 0x80, 0,25, 0x90,0x26, 0,75, 
+0x80, 0,87, 0x90,0x3E, 0,62, 0x80, 0,25, 0,75, 0x90,0x3E, 0,100, 0x80, 0,62, 0x90,0x26, 
+0,37, 0,50, 0x80, 0,75, 0x90,0x3E, 0,37, 0x80, 0,62, 0,62, 0x90,0x3C, 0,87, 0,75, 
+0,100, 0,75, 0x80, 0x90,0x26, 0,37, 0,37, 0x80, 0,87, 0x90,0x3C, 0,37, 0x80, 0,25, 
+0,100, 0x90,0x3E, 0,62, 0,12, 0x80, 0,87, 0x90,0x26, 0,75, 0x80, 0,87, 0x90,0x26, 0,62, 
+0x80, 0,12, 0,87, 0x90,0x34, 0,162, 0,25, 0,137, 0x80, 0x90,0x3C, 0,162, 0,162, 0,112, 
+0x80, 0,50, 0x90,0x39, 0,162, 0,162, 0,162, 0,162, 0,162, 0x80, 0x90,0x4A, 0,162, 0x80, 
+0x90,0x51, 0,175, 0x80, 0x90,0x45, 0,162, 0x80, 0x90,0x4A, 0,162, 0x80, 0x90,0x3E, 0,75, 0,87, 
+0,62, 0,100, 0,100, 0,62, 0,75, 0,87, 0,87, 0,75, 0,75, 0,87, 0,75, 
+0,87, 0,87, 0,75, 0,100, 0,62, 0,87, 0,75, 0,100, 0,62, 0,25, 0,62, 
+0,25, 0,50, 0,12, 0,87, 0,62, 0,25, 0,62, 0,37, 0,50, 0,62, 0,100, 
+0,62, 0,100, 0,62, 0,100, 0,87, 0,75, 0,62, 0,100, 0,62, 0,100, 0,75, 
+0,87, 0,62, 0,100, 0,75, 0,87, 0,75, 0,87, 0,75, 0,87, 0,75, 0,87, 
+0,100, 0,62, 0,50, 0,25, 0,12, 0,12, 0,62, 0,12, 0,75, 0,75, 0,62, 
+0,25, 0,12, 0,75, 0,37, 0,75, 0,50, 0,162, 0x80, 0x90,0x3E, 0,37, 0,37, 
+0,87, 0,100, 0,62, 0,87, 0,75, 0,100, 0,12, 0,50, 0,12, 0,37, 0,50, 
+0,37, 0,25, 0,87, 0,12, 0,62, 0,12, 0,37, 0,75, 0,12, 0,12, 0,12, 
+0,162, 0x80, 0x90,0x3C, 0,87, 0,62, 0,12, 0,112, 0,50, 0,12, 0,125, 0,25, 
+0,12, 0,150, 0,12, 0,25, 0,87, 0,37, 0,12, 0,112, 0,37, 0,175, 0,162, 
+0x80, 0x90,0x3E, 0,50, 0,12, 0,100, 0,62, 0,100, 0,87, 0,75, 0,87, 0,75, 
+0,87, 0,75, 0,75, 0,87, 0,62, 0,100, 0,75, 0,87, 0,62, 0,100, 0,87, 
+0,75, 0,62, 0,12, 0,37, 0,50, 0,87, 0,50, 0,25, 0,62, 0,100, 0,75, 
+0,75, 0,12, 0,125, 0,25, 0,25, 0,12, 0,62, 0x80, 0,87, 0x90,0x4C, 0,75, 
+0,87, 0x80, 0x90,0x22, 0,12, 0,87, 0x80, 0,62, 0x90,0x2E, 0,87, 0x80, 0,75, 0x90,0x22, 
+0,25, 0,75, 0,12, 0x80, 0,50, 0x90,0x2E, 0,25, 0,25, 0,75, 0,12, 0x80, 0,25, 
+0x90,0x29, 0,25, 0,62, 0,25, 0,50, 0,12, 0x80, 0,12, 0x90,0x46, 0,25, 0,62, 
+0,12, 0,12, 0,25, 0,162, 0,87, 0,62, 0x80, 0,12, 0x90,0x24, 0,112, 0x80, 0,50, 
+0x90,0x30, 0,12, 0,125, 0x80, 0,25, 0x90,0x43, 0,12, 0,150, 0,12, 0,25, 0,87, 
+0,37, 0x80, 0x90,0x4A, 0,12, 0,112, 0,37, 0,175, 0x80, 0x90,0x4A, 0,162, 0,50, 0,12, 
+0,100, 0,62, 0,100, 0,87, 0,75, 0,87, 0,75, 0,87, 0,75, 0,75, 0,87, 
+0,62, 0,100, 0,75, 0,87, 0,62, 0,100, 0,87, 0,75, 0,75, 0,75, 0,12, 
+0,75, 0,62, 0,25, 0,62, 0,100, 0,137, 0,25, 0,75, 0,87, 0x80, 0x90,0x26, 
+0,175, 0,12, 0,150, 0x80, 0xf0};
\ No newline at end of file