Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: kiokuryoku_game escapeFromYou junirobo_sample001 ROBOX_Sample_IRcon ... more
Diff: beep_sound.cpp
- Revision:
- 4:237b642c2ffa
- Parent:
- 3:86238dba1529
- Child:
- 5:a64e653b0ce1
--- a/beep_sound.cpp Tue Jun 28 09:47:46 2016 +0000
+++ b/beep_sound.cpp Sat Jul 09 11:39:11 2016 +0000
@@ -14,7 +14,7 @@
delete m_pwm;
}
-void beep_sound::stop(){
+void beep_sound::stopGakuhu(){
m_pwm->write(0.0f);
// キューが空でなければ次の音へ
if(otoQue.empty() != 1){
@@ -25,27 +25,34 @@
// 音の再生
void beep_sound::NoteOn(int octave, int note)
{
- frequency = frequencyTable[note] << octave;
- m_pwm->period(1.0f/(float)frequency);
- m_pwm->write(0.5f);
+ if(octave >= 0){
+ frequency = frequencyTable[note] << octave;
+ m_pwm->period(1.0f/(float)frequency);
+ m_pwm->write(0.5f);
+ }else{
+ octave = (-1)*octave;
+ frequency = frequencyTable[note] >> octave;
+ m_pwm->period(1.0f/(float)frequency);
+ m_pwm->write(0.5f);
+ }
}
// 1音ずつ音符情報をキューに追加
void beep_sound::setGakuhu(int argOc, int argNo, float argTi)
{
- buf.octave = argOc;
- buf.note = argNo;
- buf.time_s = argTi;
- otoQue.push(buf);
+ bufG.octave = argOc;
+ bufG.note = argNo;
+ bufG.time_s = argTi;
+ otoQue.push(bufG);
}
// 休符をキューに追加
void beep_sound::setKyuhu(float argTi)
{
- buf.octave = 1000;
- buf.note = 0;
- buf.time_s = argTi;
- otoQue.push(buf);
+ bufG.octave = 1000;
+ bufG.note = 0;
+ bufG.time_s = argTi;
+ otoQue.push(bufG);
}
// 楽譜キューを再生、音停止の割り込み予約
@@ -54,7 +61,7 @@
void beep_sound::playGakuhu()
{
beep_sound::NoteOn(otoQue.front().octave, otoQue.front().note);
- interruptStop.attach(this, &beep_sound::stop, otoQue.front().time_s);
+ interruptStop.attach(this, &beep_sound::stopGakuhu, otoQue.front().time_s);
otoQue.pop();
}
@@ -109,25 +116,21 @@
void beep_sound::beep_right(int nTimes)
{
for(int i=0; i<nTimes; i++){
- beep_sound::onpu(3,11,0.1);
- beep_sound::onpu(3,7,0.35);
- wait(0.1);
+ beep_sound::setGakuhu(3,11,0.1);
+ beep_sound::setGakuhu(3,7,0.35);
+ beep_sound::setKyuhu(0.1);
}
+ beep_sound::playGakuhu();
}
void beep_sound::beep_wrong(int nTimes)
{
for (int i = 0; i < nTimes; i++) {
- m_pwm->period(0.01f);
- m_pwm->write(0.5f);
- wait(0.1);
- m_pwm->write(0.0f);
- wait(0.1);
- m_pwm->period(0.01f);
- m_pwm->write(0.5f);
- wait(0.35);
- m_pwm->write(0.0f);
- wait(0.1);
+ beep_sound::setGakuhu(0, 12, 0.1);
+ beep_sound::setKyuhu(0.1);
+ beep_sound::setGakuhu(0, 12, 0.35);
+ beep_sound::setKyuhu(0.1);
}
+ beep_sound::playGakuhu();
}
void beep_sound::beep_1up(int nTimes)
{