![](/media/cache/profiles/P1050323.jpg.50x50_q85.jpg)
KIK01 Release
Dependencies: mcp3008 mbed mbed-rtos AverageMCP3008 VoltageMonitor
Diff: main.cpp
- Revision:
- 22:a3bb7594f9bb
- Parent:
- 21:a527f51381d6
- Child:
- 23:da7c5f7feff1
--- a/main.cpp Sat Sep 16 00:26:56 2017 +0000 +++ b/main.cpp Sun Sep 17 19:11:41 2017 +0000 @@ -12,6 +12,7 @@ #include "mbed.h" #include "rtos.h" #include "mcp3008.h" +#include "EnvelopeAR.h" #define UART_TRACE (1) #define PIN_CHECK (1) @@ -46,122 +47,6 @@ DigitalOut Dout1(D9); DigitalOut Dout2(D14); -class EnvelopeAR -{ -public: - EnvelopeAR(int _attack, int _release, float _v0, float _v1, float _v2, float _attackTauRatio=0.36f, float _releaseTauRatio=0.36f) : - amplitude(_v0), - v0(_v0), - v1(_v1), - v2(_v2), - vLast(_v0), - attackTauRatio(_attackTauRatio), - releaseTauRatio(_releaseTauRatio) { - setAttack(_attack); - setRelease(_release); - } - - ~EnvelopeAR() {} - - void setAttack(int _attack) { - attack = _attack; - tau0 = attack * attackTauRatio; - } - int getAttack() { - return attack; - } - - void setRelease(int _release) { - release = _release; - tau1 = release * releaseTauRatio; - } - int getRelease() { - return release; - } - - void setAttackTauRatio(float _attackTauRatio) { - attackTauRatio = _attackTauRatio; - tau0 = attack * attackTauRatio; - } - float getAttackTauRatio() { - return attackTauRatio; - } - - void setReleaseTauRatio(float _releaseTauRatio) { - releaseTauRatio = _releaseTauRatio; - tau1 = release * releaseTauRatio; - } - float getReleaseTauRatio() { - return releaseTauRatio; - } - - float getTau0() { - return tau0; - } - float getTau1() { - return tau1; - } - - void setV0(float _v0) { - v0 = _v0; - } - float getV0() { - return v0; - } - void setV1(float _v1) { - v1 = _v1; - } - float getV1() { - return v1; - } - void setV2(float _v2) { - v2 = _v2; - } - float getV2() { - return v2; - } - - float getAmplitude() { - return amplitude; - } - float getAmplitude(int tick) { - if (tick < attack) { - // attackの処理 - amplitude = v0 + (v1 - v0) * (1 - expf(-(float)tick / tau0)); - vLast = amplitude; - } else { - // releaseの処理 - amplitude = (vLast - v2) * (expf(-(float)(tick - attack) / tau1)) + v2; - } - return amplitude; - } - -private: - int attack; - int release; - float amplitude; - float v0; - float v1; - float v2; - float vLast; - float tau0; - float tau1; - float attackTauRatio; - float releaseTauRatio; -}; - -class EnvelopeParam -{ -public: - int attack; - int release; - float v0; - float v1; - float v2; - float attackTauRatio; - float releaseTauRatio; -}; - EnvelopeAR envelopeFrequency(5, 300, 880.0f, 120.0f, 40.0f, 0.36f, 0.1f); EnvelopeAR envelopeAmplitude(50, 200, 0.99f, 1.0f, 0.0f);