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

Dependencies:   UITDSP_ADDA UIT_ACM1602NI UIT_AQM1602 mbed

Synthesizer/Rosenberg.hpp

Committer:
MikamiUitOpen
Date:
2015-07-25
Revision:
5:0396de26b449
Parent:
Rosenberg.hpp@ 0:6c67a9387981

File content as of revision 5:0396de26b449:

//------------------------------------------------------------------------------
//  声帯波の合成 ― 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