以前のLibraryでは、スピーカ出力にPWM,DigitalOutを使いましたが、これは、両方ともPWMにしたものです。LPC1114FN28ではDigitalOutにノイズが乗ることがありその対応です。

Dependents:   kitchenTimer LPC1114FN28_kitchenTimer_Clock

Fork of Sound by suu pen

Files at this revision

API Documentation at this revision

Comitter:
suupen
Date:
Sun Nov 10 03:57:47 2013 +0000
Parent:
14:027fe57d3491
Commit message:
V0.2 : @SS131110 fixed the bug in the output end processing
;

Changed in this revision

Sound.cpp 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
diff -r 027fe57d3491 -r 7e1945a135d7 Sound.cpp
--- a/Sound.cpp	Sat Oct 26 22:15:13 2013 +0000
+++ b/Sound.cpp	Sun Nov 10 03:57:47 2013 +0000
@@ -27,8 +27,8 @@
     _pwm.period_us(Z_pwmSyuuki);
     
     _pwm.write(0.0);
-    _kijun.write(0.0);  //131027
-//131027    _kijun = 0; //131027
+    _kijun.write(0.0);  //@SS131027
+//@SS131027    _kijun = 0; //@SS131027
 
 
     keikajikan = 0;  // 1tu no oto no keikajikan
@@ -48,18 +48,27 @@
 *****************************************/
 void Sound::sound_out(float siji, int8_t fugo){
 
-    // siji no atai wo fugo ga minus no toki hanten
-    if(fugo == 1){siji = 1.0 - siji;}
-    _kijun.write((float)fugo);    //131027
-//131027    _kijun = fugo;  //131027
+    if(siji != 0){
+        // siji no atai wo fugo ga minus no toki hanten
+         if(fugo == 1){siji = 1.0 - siji;}
+         _kijun.write((float)fugo);    //@SS131027
+//@SS131027    _kijun = fugo;  //@SS131027
       
-    _pwm.write(siji);   // 2tuizyo sound out settei site ,interrupt no nakade renzoku de pwm set wo suruto bousou suru.
+        _pwm.write(siji);   // 2tuizyo sound out settei site ,interrupt no nakade renzoku de pwm set wo suruto bousou suru.
+    }
+    else{                       //@SS131110
+        // sound off            //@SS131110
+        _kijun.write(0.0);      //@SS131110
+        _pwm.write(0.0);        //@SS131110
+ 
+   }
 }
 /*****************************************
 * sound hakei pwm output
 * time interrupt
 *****************************************/
 void Sound::pulseCheck(void) {
+
 //    uint32_t static C_syuukiKeika = 0;
 //    uint8_t static f_muonSet = 0;           // muon ji no sound_out() syori wo kurikaesu no wo fusegu
 //    uint8_t static F_pwmSet = 0;    // 0:zenhan hansyuuki 1:kohan hansyuuki  wo request
@@ -203,13 +212,24 @@
 Description    : enso ji no tugino onpu data syutoku
 ******************************************************************************/
 void Sound::sound_ensoSyori(void) {
+   const sound_t END_DATA[] =     {                                             //@SS131110
+    //   hanon siji 0:b(flat)   1:tujo  2:#(sharp)                              //@SS131110
+    //   |  C1 - B9 kan deno onkai(Gx ha 9x ni okikae te siji)  0xFF=end data   //@SS131110
+    //   |  |   time (1/1[ms]/count)                                            //@SS131110
+    //   |  |   |    envelope(yoin) (1/1 [ms]/count)                            //@SS131110
+    //   |  |   |    |                                                          //@SS131110
+        {1,0xFF,0000,0}   // end                                                //@SS131110
+    };                                                                          //@SS131110
+
+    sound_t data;                                                               //@SS131110
     
     // enso data settei
     if((sound_sound() == false)     // oto no syuturyoku jikan hantei
     & (onpu != NULL)                // enso chu ka wo kakunin
      ){
         // tugi no onpu data syutoku
-        sound_t data = *onpu;
+//@SS131110        sound_t data = *onpu;                                        //@SS131110
+        data = *onpu;                                                           //@SS131110
         if(data.onkai == 0xff){
             sound_sound(data);      //131026
             onpu = NULL;
@@ -221,6 +241,10 @@
         }
     
     }
+    else if(onpu == NULL){                                                      //@SS131110
+        data = *END_DATA;                                                       //@SS131110
+        sound_sound(data);                                                      //@SS131110
+    }                                                                           //@SS131110
 
 }
 
@@ -456,3 +480,4 @@
 
 
 
+
diff -r 027fe57d3491 -r 7e1945a135d7 Sound.h
--- a/Sound.h	Sat Oct 26 22:15:13 2013 +0000
+++ b/Sound.h	Sun Nov 10 03:57:47 2013 +0000
@@ -25,9 +25,10 @@
 /*    Sound.h                                                          */
 /*                                                                     */
 /*    Sound.c V0.4 base                                                */
-/*    V0.1 : 2013/10/27 DigitalOut wo PWMOut ni henko(Noise taisaku)   */
+/*    V0.1 : @SS131027 DigitalOut wo PWMOut ni henko(Noise taisaku)   */
 /*                       koreha LPC1114FN28 no taio                    */
-/*                      Sound end no stop syori                        */  
+/*                      Sound end no stop syori                        */ 
+/*    V0.2 : @SS131110  fixed the bug in the output end processing     */  
 /***********************************************************************/
 #ifndef _SOUND_H
 #define _SOUND_H
@@ -132,18 +133,6 @@
 */
 
 
-
-
-
-
-
-
-
-
-
-
-
-
 class Sound {
 public: