Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mike/hachikit cleanup #304

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
be8965f
gitignore
perkowitz Apr 27, 2024
939a6e7
Add current hachikit code
perkowitz Apr 27, 2024
ec1fcd5
Added jitter and value-jump protection for drum params
perkowitz May 4, 2024
3090dab
Added a 606/808-style hihat source and CH model
perkowitz May 7, 2024
85e16ce
Made HhSource an IDrum, standardized params
perkowitz May 7, 2024
e2ce937
Adjusted default params for drums
perkowitz May 7, 2024
1f9b305
Added OH and AHD env
perkowitz May 11, 2024
11ffe6f
Fixed some issues with params not being set correctly & jumping values
perkowitz May 13, 2024
70f28c8
Added Cy, which uses the hh source but adds HP and LP filters
perkowitz May 19, 2024
e14d11c
Added cowbell using two oscillators from the HH source
perkowitz May 19, 2024
dfb881a
Adding Tom sound; hitting processing limit?
perkowitz May 20, 2024
6b86280
Update README.md
perkowitz May 21, 2024
fe4e601
Added CpuLoadMeter and incremental loading of drums to track CPU usage
perkowitz May 22, 2024
4757a69
Pulled the click part of the Tom out to a shared ClickSource, reducin…
perkowitz May 22, 2024
514c4c7
Fixed small bugs in Blank (drum template)
perkowitz May 25, 2024
0ae093f
Fixed bug in Tom param display, restored default drum order
perkowitz May 25, 2024
a2efc36
Merge branch 'hachikit' of https://github.com/perkowitz/ElectrosmithD…
perkowitz May 25, 2024
030ae80
Added slot to all IDrums. Added a CPU usage debugging mode to play a …
perkowitz May 28, 2024
ba146ac
Display 2nd row of params
perkowitz Jun 1, 2024
e65d70c
Small changes. Start tracking CPU usage in README
perkowitz Jun 4, 2024
91aab7e
Added screensaver that shows midi notes
perkowitz Jun 5, 2024
188b602
Cleanup in screensaver
perkowitz Jun 7, 2024
3745fb6
Added clap
perkowitz Jun 8, 2024
5aa9cb8
Digital clap, using the clocked noise source
perkowitz Jun 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,9 @@ MyProjects/
.cortex-debug.registers.state.json
.cortex-debug.peripherals.state.json



**/build
**/.vscode


40 changes: 40 additions & 0 deletions optic/HachiKit/AhdEnv.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "AhdEnv.h"
#include "Utility.h"

using namespace daisy;
using namespace daisysp;

void AhdEnv::Init(float sample_rate) {
ad.Init(sample_rate);
adsr.Init(sample_rate);
adsr.SetTime(ADSR_SEG_DECAY, 0.001);
adsr.SetSustainLevel(0.5);
}

float AhdEnv::Process() {
// The AD envelope is used to count off the gate time of the ADSR, providing the hold time.
ad.Process();
return adsr.Process(ad.IsRunning());
}

void AhdEnv::Trigger() {
ad.Trigger();
adsr.Retrigger(true);
}

void AhdEnv::SetAttack(float time) {
ad.SetTime(ADENV_SEG_ATTACK, time);
adsr.SetTime(ADSR_SEG_ATTACK, time);
}

void AhdEnv::SetHold(float time) {
ad.SetTime(ADENV_SEG_DECAY, time);
}

void AhdEnv::SetDecay(float time) {
adsr.SetTime(ADSR_SEG_RELEASE, time);
}

bool AhdEnv::IsRunning() const {
return adsr.IsRunning();
}
29 changes: 29 additions & 0 deletions optic/HachiKit/AhdEnv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef AHDENV_H
#define AHDENV_H

#include "daisy_patch.h"
#include "daisysp.h"

using namespace daisy;
using namespace daisysp;

class AhdEnv {

public:
void Init(float sample_rate);
float Process();
void Trigger();
void SetAttack(float time);
void SetHold(float time);
void SetDecay(float time);
void SetCurve(float scalar);
bool IsRunning() const;

private:
AdEnv ad;
Adsr adsr;
};



#endif
141 changes: 141 additions & 0 deletions optic/HachiKit/Bd8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#include "Bd8.h"
#include "Utility.h"

using namespace daisy;
using namespace daisysp;

void Bd8::Init(std::string slot, float sample_rate) {
Init(slot, sample_rate, 78, 0.001, 4.0, 0.001, 0.1, 0.95);
}

void Bd8::Init(std::string slot, float sample_rate, float frequency, float ampAttack, float ampDecay, float pitchAttack, float pitchDecay, float modAmount) {

this->slot = slot;

// oscillator settings
osc.Init(sample_rate);
SetParam(PARAM_FREQUENCY, frequency);
osc.SetWaveform(Oscillator::WAVE_SIN);

// ampEnv settings
ampEnv.Init(sample_rate);
ampEnv.SetMax(1);
ampEnv.SetMin(0);
ampEnv.SetCurve(-100);
SetParam(PARAM_AMP_ATTACK, ampAttack);
SetParam(PARAM_AMP_DECAY, ampDecay);

// pitchEnv settings
pitchEnv.Init(sample_rate);
pitchEnv.SetMax(1);
pitchEnv.SetMin(0);
pitchEnv.SetCurve(-100);
SetParam(PARAM_PITCH_ATTACK, pitchAttack);
SetParam(PARAM_PITCH_DECAY, pitchDecay);
SetParam(PARAM_MOD_AMT, modAmount);
}

float Bd8::Process() {
float psig = pitchEnv.Process();
osc.SetFreq(parameters[PARAM_FREQUENCY].GetScaledValue() + parameters[PARAM_MOD_AMT].GetScaledValue() * psig);
// osc.SetFreq(parameters[PARAM_FREQUENCY].GetScaledValue());
return 2 * velocity * osc.Process() * ampEnv.Process();
}

void Bd8::Trigger(float velocity) {
this->velocity = Utility::Limit(velocity);
if (this->velocity > 0) {
osc.Reset();
ampEnv.Trigger();
pitchEnv.Trigger();
}
}

float Bd8::GetParam(uint8_t param) {
return param < PARAM_COUNT ? parameters[param].GetScaledValue() : 0.0f;
}

std::string Bd8::GetParamString(uint8_t param) {
if (param < PARAM_COUNT) {
switch (param) {
case PARAM_FREQUENCY:
case PARAM_MOD_AMT:
return std::to_string((int)GetParam(param));// + "hz";
case PARAM_AMP_ATTACK:
case PARAM_AMP_DECAY:
case PARAM_PITCH_ATTACK:
case PARAM_PITCH_DECAY:
return std::to_string((int)(GetParam(param) * 1000));// + "ms";
}
}
return "";
}

float Bd8::UpdateParam(uint8_t param, float raw) {
float scaled = raw;
if (param < PARAM_COUNT) {
switch (param) {
case PARAM_FREQUENCY:
scaled = parameters[param].Update(raw, Utility::ScaleFloat(raw, 20, 5000, Parameter::EXPONENTIAL));
break;
case PARAM_AMP_ATTACK:
scaled = parameters[param].Update(raw, Utility::ScaleFloat(raw, 0.01, 5, Parameter::EXPONENTIAL));
ampEnv.SetTime(ADENV_SEG_ATTACK, scaled);
break;
case PARAM_AMP_DECAY:
scaled = parameters[param].Update(raw, Utility::ScaleFloat(raw, 0.01, 5, Parameter::EXPONENTIAL));
ampEnv.SetTime(ADENV_SEG_DECAY, scaled);
break;
case PARAM_PITCH_ATTACK:
scaled = parameters[param].Update(raw, Utility::ScaleFloat(raw, 0.01, 5, Parameter::EXPONENTIAL));
pitchEnv.SetTime(ADENV_SEG_ATTACK, scaled);
break;
case PARAM_PITCH_DECAY:
scaled = parameters[param].Update(raw, Utility::ScaleFloat(raw, 0.01, 5, Parameter::EXPONENTIAL));
pitchEnv.SetTime(ADENV_SEG_DECAY, scaled);
break;
case PARAM_MOD_AMT:
scaled = parameters[param].Update(raw, Utility::ScaleFloat(raw, 0, 2000, Parameter::EXPONENTIAL));
break;
}
}

return scaled;
}

void Bd8::ResetParams() {
for (u8 param = 0; param < PARAM_COUNT; param++) {
parameters[param].Reset();
}
}

void Bd8::SetParam(uint8_t param, float scaled) {
if (param < PARAM_COUNT) {
switch (param) {
case PARAM_FREQUENCY:
parameters[param].SetScaledValue(scaled);
break;
case PARAM_AMP_ATTACK:
parameters[param].SetScaledValue(scaled);
ampEnv.SetTime(ADENV_SEG_ATTACK, scaled);
break;
case PARAM_AMP_DECAY:
parameters[param].SetScaledValue(scaled);
ampEnv.SetTime(ADENV_SEG_DECAY, scaled);
break;
case PARAM_PITCH_ATTACK:
parameters[param].SetScaledValue(scaled);
pitchEnv.SetTime(ADENV_SEG_ATTACK, scaled);
break;
case PARAM_PITCH_DECAY:
parameters[param].SetScaledValue(scaled);
pitchEnv.SetTime(ADENV_SEG_DECAY, scaled);
break;
case PARAM_MOD_AMT:
parameters[param].SetScaledValue(scaled);
break;
}
}

}

56 changes: 56 additions & 0 deletions optic/HachiKit/Bd8.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef BD8_H
#define BD8_H

#include "daisy_patch.h"
#include "daisysp.h"
#include <string>
#include "IDrum.h"
#include "Utility.h"
#include "Param.h"

using namespace daisy;
using namespace daisysp;

class Bd8: public IDrum {

public:
// Number of settable parameters for this model.
static const uint8_t PARAM_COUNT = 6;
// This is the order params will appear in the UI.
static const uint8_t PARAM_FREQUENCY = 0;
static const uint8_t PARAM_MOD_AMT = 1;
static const uint8_t PARAM_AMP_DECAY = 2;
static const uint8_t PARAM_PITCH_DECAY = 3;
static const uint8_t PARAM_AMP_ATTACK = 4;
static const uint8_t PARAM_PITCH_ATTACK = 5;
// TODO: add aCurve and pCurve

void Init(std::string slot, float sample_rate);
void Init(std::string slot, float sample_rate, float frequency, float ampAttack, float ampDecay, float pitchAttack, float pitchDecay, float modAmount);
float Process();
void Trigger(float velocity);

float GetParam(uint8_t param);
std::string GetParamString(uint8_t param);
float UpdateParam(uint8_t param, float value);
void SetParam(uint8_t param, float value);
void ResetParams();

std::string Name() { return "Bd8"; }
std::string Slot() { return slot; }
std::string GetParamName(uint8_t param) { return param < PARAM_COUNT ? paramNames[param] : ""; }

private:
std::string paramNames[PARAM_COUNT] = { "Freq", "Mod", "aDcy", "pDcy", "aAtk", "pAtk" };
std::string slot;
Param parameters[PARAM_COUNT];
Oscillator osc;
AdEnv ampEnv;
AdEnv pitchEnv;
float velocity;

};



#endif
Loading