Vowel synthesizer using digital resonators. This program can run without LCD display. ディジタル共振器を使った合成母音ジェネレータ.LCD表示器なしでも動く.

Dependencies:   UITDSP_ADDA UIT_ACM1602NI UIT_AQM1602 mbed

Revision:
5:0396de26b449
Parent:
0:6c67a9387981
diff -r dd2ec72068d0 -r 0396de26b449 Synthesizer/Rosenberg.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Synthesizer/Rosenberg.hpp	Sat Jul 25 07:10:11 2015 +0000
@@ -0,0 +1,71 @@
+//------------------------------------------------------------------------------
+//  声帯波の合成 ― Rosenberg 波(ヘッダ)
+//      作成者:三上直樹,2013/10/27 作成,(c)三上直樹 2013
+//------------------------------------------------------------------------------
+
+#include "mbed.h"
+
+#ifndef ROSENBERG_HPP
+#define ROSENBERGL_HPP
+
+namespace Mikami
+{
+    class Rosenberg
+    {
+    private:
+        const float DT_;
+
+        float period_, t1_, t2_, t_, amp_;
+
+        // コピー・コンストラクタの使用禁止
+        Rosenberg(const Rosenberg& g);
+        // 代入演算子の使用禁止
+        Rosenberg& operator=(const Rosenberg& g);
+
+    public:
+        // 初期化を行うコンストラクタ
+        //      f0: 基本周波数
+        //      fs: 標本化周波数
+        //      amp: 振幅
+        Rosenberg(float f0, float fs, float amp)
+            : DT_(1.0f/fs), t_(0), amp_(amp)
+        { SetPeriod(f0); }
+
+        // 基本周期の再設定
+        void SetPeriod(float f0)
+        {
+            period_ = 1.0f/f0;
+            t1_ = 0.4f/f0;
+            t2_ = 0.16f/f0;
+        }
+
+        // 振幅の再設定
+        void SetAmplitude(float amp) { amp_ = amp; }
+
+        // t_ = 0 に設定
+        void Reset() { t_ = 0; }
+
+        // Rosengerg 波の計算
+        //      amp:    振幅
+        float Execute()
+        {
+            float g = 0;
+
+            if (t_ < t1_)
+            {
+                float x = t_/t1_;
+                g = amp_*(3.0f - 2.0f*x)*x*x;
+            }
+            if ((t_ >= t1_) && (t_ < t1_+t2_))
+            {
+                float x = (t_ - t1_)/t2_;
+                g = amp_*(1.0f - x*x);
+            }
+
+            if ((t_+=DT_) > period_) t_ -= period_;
+
+            return g;
+        }
+    };
+}
+#endif  // ROSENBERG_HPP