YMZ294 Player. modified from "Yamaguchi's YMZ294 Library" for LPC1114.

Dependencies:   mbed

Revision:
0:7a56bf0441ea
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Player/Layer.cpp	Wed Dec 09 01:38:08 2015 +0000
@@ -0,0 +1,46 @@
+#include "Layer.h"
+
+Layer::Layer() {}
+
+Layer::Layer(MusicString& ms) : ms(ms), note(), tick(0) {}
+
+int Layer::play(YMZ294& soundGen, Ch channel, int tick, bool attenuate) {
+    note.dur -= tick - this->tick;
+    this->tick = tick;
+
+    if (note.dur == 0) {
+        if (ms.hasMoreNote()) {
+            note = ms.getNextNote();
+            while (note.tie && ms.hasMoreNote()) {
+                Note note2 = ms.getNextNote();
+                note.dur += note2.dur;
+                note.tie = note2.tie;
+            }
+
+            if (note.pitch != 0) {
+                float freq = 30.8677 * pow(1.059463, note.pitch - 23);
+                soundGen.setVolume(channel, 16);
+                soundGen.setTone(channel, freq);
+            } else {
+                if (attenuate)
+                    soundGen.setVolume(channel, 0);
+            }
+        }
+    } else {
+        soundGen.setVolume(channel, 0);
+    }
+
+    return note.dur;
+}
+
+void Layer::rewind() {
+    ms.rewind();
+    note.pitch = 0;
+    note.dur = 0;
+    note.tie = false;
+    tick = 0;
+}
+
+bool Layer::isNull() {
+    return ms.isNull();
+}
\ No newline at end of file