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.
Dependencies: UITDSP_ADDA UIT_ACM1602NI UIT_AQM1602 mbed
Rosenberg.hpp
00001 //------------------------------------------------------------------------------ 00002 // 声帯波の合成 ― Rosenberg 波(ヘッダ) 00003 // 作成者:三上直樹,2013/10/27 作成,(c)三上直樹 2013 00004 //------------------------------------------------------------------------------ 00005 00006 #include "mbed.h" 00007 00008 #ifndef ROSENBERG_HPP 00009 #define ROSENBERGL_HPP 00010 00011 namespace Mikami 00012 { 00013 class Rosenberg 00014 { 00015 private: 00016 const float DT_; 00017 00018 float period_, t1_, t2_, t_, amp_; 00019 00020 // コピー・コンストラクタの使用禁止 00021 Rosenberg(const Rosenberg& g); 00022 // 代入演算子の使用禁止 00023 Rosenberg& operator=(const Rosenberg& g); 00024 00025 public: 00026 // 初期化を行うコンストラクタ 00027 // f0: 基本周波数 00028 // fs: 標本化周波数 00029 // amp: 振幅 00030 Rosenberg(float f0, float fs, float amp) 00031 : DT_(1.0f/fs), t_(0), amp_(amp) 00032 { SetPeriod(f0); } 00033 00034 // 基本周期の再設定 00035 void SetPeriod(float f0) 00036 { 00037 period_ = 1.0f/f0; 00038 t1_ = 0.4f/f0; 00039 t2_ = 0.16f/f0; 00040 } 00041 00042 // 振幅の再設定 00043 void SetAmplitude(float amp) { amp_ = amp; } 00044 00045 // t_ = 0 に設定 00046 void Reset() { t_ = 0; } 00047 00048 // Rosengerg 波の計算 00049 // amp: 振幅 00050 float Execute() 00051 { 00052 float g = 0; 00053 00054 if (t_ < t1_) 00055 { 00056 float x = t_/t1_; 00057 g = amp_*(3.0f - 2.0f*x)*x*x; 00058 } 00059 if ((t_ >= t1_) && (t_ < t1_+t2_)) 00060 { 00061 float x = (t_ - t1_)/t2_; 00062 g = amp_*(1.0f - x*x); 00063 } 00064 00065 if ((t_+=DT_) > period_) t_ -= period_; 00066 00067 return g; 00068 } 00069 }; 00070 } 00071 #endif // ROSENBERG_HPP
Generated on Thu Jul 14 2022 18:44:13 by
1.7.2