Hirotaka Yoneda / beep_sound

Dependents:   kiokuryoku_game escapeFromYou junirobo_sample001 ROBOX_Sample_IRcon ... more

Revision:
5:a64e653b0ce1
Parent:
4:237b642c2ffa
Child:
6:adb925f93199
--- a/beep_sound.cpp	Sat Jul 09 11:39:11 2016 +0000
+++ b/beep_sound.cpp	Sat Jul 09 15:08:56 2016 +0000
@@ -5,6 +5,7 @@
 
 beep_sound::beep_sound(PinName pwm)
 {
+    lastPeriod = 0.0;
     m_pwm = new PwmOut(pwm);
     m_pwm->write(0.0f);
 }
@@ -14,7 +15,7 @@
     delete m_pwm;
 }
 
-void beep_sound::stopGakuhu(){
+void beep_sound::stop(){
     m_pwm->write(0.0f);
     // キューが空でなければ次の音へ
     if(otoQue.empty() != 1){
@@ -25,13 +26,19 @@
 // 音の再生
 void beep_sound::NoteOn(int octave, int note)
 {
-    if(octave >= 0){
+    if(lastPeriod == 1.0f/(float)frequency){
         frequency = frequencyTable[note] << octave;
+        //m_pwm->period(1.0f/(float)frequency);
+        m_pwm->write(0.5f);
+    }else if(octave >= 0){
+        frequency = frequencyTable[note] << octave;
+        lastPeriod = 1.0f/(float)frequency;
         m_pwm->period(1.0f/(float)frequency);
         m_pwm->write(0.5f);
     }else{
         octave = (-1)*octave;
         frequency = frequencyTable[note] >> octave;
+        lastPeriod = 1.0f/(float)frequency;
         m_pwm->period(1.0f/(float)frequency);
         m_pwm->write(0.5f);
     }
@@ -61,7 +68,7 @@
 void beep_sound::playGakuhu()
 {
     beep_sound::NoteOn(otoQue.front().octave, otoQue.front().note);
-    interruptStop.attach(this, &beep_sound::stopGakuhu, otoQue.front().time_s);
+    interruptStop.attach(this, &beep_sound::stop, otoQue.front().time_s);
     otoQue.pop();
 }
 
@@ -143,6 +150,7 @@
         beep_sound::onpu(4,7,0.1);
         wait(0.1);
     }
+    //beep_sound::playGakuhu();
 }
 void beep_sound::beep_konbini(int nTimes)
 {