saw, envelope, decoupled voice code but doesn't compile

This commit is contained in:
Gordon JC Pearce 2024-09-03 15:22:56 +01:00
parent 3a953390ff
commit df37350fb4
5 changed files with 52 additions and 39 deletions

View File

@ -1,7 +1,7 @@
###############################
#
# Makefile for BarrVerb
# based on the work of falkTX
# Makefile for BarrChassis
# based on the work of falkTX, in the DPF example plugins
#
# for full licence, see LICENCE in the root of the project
#
@ -9,10 +9,12 @@
NAME = chassis
FILES_DSP = chassis.cpp
FILES_DSP = \
chassis.cpp
include ../dpf/Makefile.plugins.mk
TARGETS += vst2 vst3 jack lv2_dsp
TARGETS += jack
all: $(TARGETS)

View File

@ -25,16 +25,17 @@ Chassis::Chassis() : Plugin(kParameterCount, 0, 0) { // one parameter, no progr
// Initialisation functions
void Chassis::initParameter(uint32_t index, Parameter &parameter) {
}
//void Chassis::initParameter(uint32_t index, Parameter &parameter) {
//}
/*
void Chassis::setParameterValue(uint32_t index, float value) {
}
float Chassis::getParameterValue(uint32_t index) const {
return 0;
}
*/
void Chassis::initAudioPort(bool input, uint32_t index, AudioPort &port) {
port.groupId = kPortGroupStereo;
Plugin::initAudioPort(input, index, port);
@ -72,22 +73,21 @@ void Chassis::noteOn(uint8_t note) {
if (vPtr == NUM_VOICES) vPtr = 0;
if (voice[vPtr].isFree()) {
// if it's an existing note don't reset
voice[vPtr].voiceOn(note, voice[i].note != note);
voice[vPtr].on(note, voice[i].note != note);
break;
}
}
if (i == NUM_VOICES) { // didn't find a free voice
vPtr++;
if (vPtr == NUM_VOICES) vPtr = 0;
voice[vPtr].voiceOn(note, true);
voice[vPtr].on(note, true);
}
}
void Chassis::noteOff(uint8_t note) {
uint32_t v;
for (uint32_t i = 0; i < NUM_VOICES; i++) {
if (voice[i].note == note && !voice[i].isFree()) {
voice[i].voiceOff();
voice[i].off();
break;
}
}

View File

@ -46,10 +46,10 @@ class Chassis : public Plugin {
// Initialisation
void initAudioPort(bool input, uint32_t index, AudioPort &port) override;
void initParameter(uint32_t index, Parameter &parameter) override;
//void initParameter(uint32_t index, Parameter &parameter) override;
void setParameterValue(uint32_t index, float value) override;
float getParameterValue(uint32_t index) const override;
//void setParameterValue(uint32_t index, float value) override;
//float getParameterValue(uint32_t index) const override;
// void initProgramName(uint32_t index, String &programName) override;
// void loadProgram(uint32_t index) override;

View File

@ -15,3 +15,35 @@
OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <math.h>
#include "voice.hpp"
inline bool Voice::isFree() {
return keyState == K_OFF;
}
void Voice::on(uint32_t key, bool reset = 0) {
keyState = K_ON;
envState = ATTACK;
note = key;
if (reset) env = 0;
omega = (261.63 * powf(2, (note - 60) / 12.0f)) / 48000.0f;
target = 1;
}
void Voice::off() {
keyState = K_OFF;
envState = RELEASE;
target = 0;
}
void Voice::run(float *buffer, uint32_t samples) {
env = ((target - env) * 0.01) + env;
for (uint32_t i = 0; i < samples; i++) {
phase += omega;
if (phase > 1) phase -= 1;
buffer[i] += (0.5 - phase) * env;
}
}

View File

@ -25,34 +25,13 @@ class Voice {
public:
uint8_t note;
void voiceOn(uint32_t key, bool reset = 0) {
keyState = K_ON;
envState = ATTACK;
note = key;
if (reset) env = 0;
omega = (261.63 * powf(2, (note - 60)/12.0f))/48000.0f;
target = 1;
}
void on(uint32_t key, bool reset);
void voiceOff() {
keyState = K_OFF;
envState = RELEASE;
target = 0;
}
void off();
inline bool isFree() {
return keyState == K_OFF;
}
inline bool isFree();
void run(float *buffer, uint32_t samples) {
env = ((target - env)*0.01) + env;
for (uint32_t i = 0; i < samples; i++) {
phase += omega;
if (phase > 1) phase -= 1;
buffer[i] += (0.5-phase) * env;
}
}
void run(float *buffer, uint32_t samples);
private:
enum { ATTACK,