Hirotaka Yoneda / beep_sound

Dependents:   kiokuryoku_game escapeFromYou junirobo_sample001 ROBOX_Sample_IRcon ... more

Revision:
8:26cb94806201
Parent:
7:5f1b0adb25ec
Child:
9:d899b134f9bb
--- a/beep_sound.cpp	Sat Oct 08 17:05:44 2016 +0000
+++ b/beep_sound.cpp	Sat Oct 08 18:30:00 2016 +0000
@@ -7,6 +7,7 @@
 {
     frequency = 0;
     playing = false;
+    teishi = false;
     m_pwm = new PwmOut(pwm);
     m_pwm->write(0.0f);
 }
@@ -19,9 +20,12 @@
 void beep_sound::stop(){
     m_pwm->write(0.0f);
     // キューが空でなければ次の音へ
-    if(otoQue.empty() != 1){
+    if(otoQue.front().time_s != -1){
         playing = true;
-        beep_sound::playGakuhu();
+        beep_sound::playContinue();
+    }else if(otoQue.front().time_s == -1){
+        otoQue.pop();
+        playing = false;
     }else{
         playing = false;
     }
@@ -59,12 +63,28 @@
 // thisを引数にしないとコンパイルエラーになるので注意
 void beep_sound::playGakuhu()
 {
-    //if(playing == false){
+    if(playing == true){
+        while(otoQue.front().time_s != -1) {otoQue.pop();}
+        otoQue.pop(); //最後のフラグを削除
+            // 最後のフラグを挿入
+            bufG.time_s = -1;
+            otoQue.push(bufG);
+        beep_sound::stop();
+    }else{
+            // 最後のフラグを挿入
+            bufG.time_s = -1;
+            otoQue.push(bufG);
         playing = true;
         beep_sound::NoteOn(otoQue.front().octave, otoQue.front().note);
         interruptStop.attach(this, &beep_sound::stop, otoQue.front().time_s);
         otoQue.pop();
-    //}
+    }
+}
+void beep_sound::playContinue()
+{
+    beep_sound::NoteOn(otoQue.front().octave, otoQue.front().note);
+    interruptStop.attach(this, &beep_sound::stop, otoQue.front().time_s);
+    otoQue.pop();
 }
 
 void beep_sound::SetFrequency(int octave, int note, bool on_off)
@@ -85,7 +105,7 @@
 void beep_sound::onpu(int octave, int note, float time_s)
 {
     playing = true;
-    beep_sound::SetFrequency(octave, note, true);
+    beep_sound::NoteOn(octave, note);
     interruptStop.attach(this, &beep_sound::stop, time_s);
 }
 void beep_sound::sinwave(float center,int speed,int width)
@@ -103,6 +123,9 @@
     m_pwm->write(duty);
     wait_ms(wait);
 }
+
+
+//以下サンプル音集
 //引数の回数だけ鳴らす
 void beep_sound::beep_right(int nTimes)
 {
@@ -111,7 +134,7 @@
         beep_sound::setGakuhu(3,7,0.35);
         beep_sound::setKyuhu(0.1);
     }
-    if(playing == false)beep_sound::playGakuhu();
+    beep_sound::playGakuhu();
 }
 void beep_sound::beep_wrong(int nTimes)
 {
@@ -121,7 +144,7 @@
         beep_sound::setGakuhu(0, 12, 0.35);
         beep_sound::setKyuhu(0.1);
     }
-    if(playing == false)beep_sound::playGakuhu();
+    beep_sound::playGakuhu();
 }
 void beep_sound::beep_1up(int nTimes)
 {
@@ -133,7 +156,7 @@
         beep_sound::setGakuhu(4,2,0.1);
         beep_sound::setGakuhu(4,7,0.1);
     }
-    if(playing == false)beep_sound::playGakuhu();
+    beep_sound::playGakuhu();
 }
 void beep_sound::beep_konbini(int nTimes)
 {
@@ -151,19 +174,20 @@
         beep_sound::setGakuhu(1,9,0.2);
         beep_sound::setGakuhu(2,2,0.6);
     }
-    if(playing == false)beep_sound::playGakuhu();
+    beep_sound::playGakuhu();
 }
 void beep_sound::beep_readyGo(int nTimes)
 {
     for (int i = 0; i < nTimes; i++) {
-        beep_sound::onpu(1,0,0.5);
-        wait(0.5);
-        beep_sound::onpu(1,0,0.5);
-        wait(0.5);
-        beep_sound::onpu(1,0,0.5);
-        wait(0.5);
-        beep_sound::onpu(2,0,1);
+        beep_sound::setGakuhu(1,0,0.5);
+        beep_sound::setKyuhu(0.5);
+        beep_sound::setGakuhu(1,0,0.5);
+        beep_sound::setKyuhu(0.5);
+        beep_sound::setGakuhu(1,0,0.5);
+        beep_sound::setKyuhu(0.5);
+        beep_sound::setGakuhu(2,0,1);
     }
+    beep_sound::playGakuhu();
 }
 void beep_sound::beep_encount(int nTimes)
 {
@@ -216,7 +240,7 @@
         beep_sound::setGakuhu(3,10,0.1);
         beep_sound::setGakuhu(4,2,0.1);
     }
-    if(playing == false)beep_sound::playGakuhu();
+    beep_sound::playGakuhu();
 }
 void beep_sound::beep_notif2(int nTimes){
     for (int i = 0; i < nTimes; i++) {
@@ -224,7 +248,7 @@
         beep_sound::setGakuhu(1,9,0.1);
         beep_sound::setGakuhu(2,2,0.2);
     }
-    if(playing == false)beep_sound::playGakuhu();
+    beep_sound::playGakuhu();
 }
 void beep_sound::beep_potatoKansei(int nTimes){
     for (int i = 0; i < nTimes; i++) {
@@ -233,5 +257,5 @@
         beep_sound::setGakuhu(1,7,0.25);
         beep_sound::setKyuhu(0.25);
     }
-    if(playing == false)beep_sound::playGakuhu();
+    beep_sound::playGakuhu();
 }