Newer
Older
music / app / src / main / cpp / Instrument.cpp
@lukas lukas on 6 Aug 2022 635 bytes add envelope modulation
#include "Instrument.h"

Instrument::Instrument(AudioHost *host) {
    wave->initialize(host);
}

float *multiply(float *target, float *modulation, uint32_t size) {
    for (uint32_t i = 0; i < size; i++) {
        target[i] *= modulation[i];
    }
    return target;
}

void Instrument::render(float *buffer, uint32_t count) {
    float *modulation = envelope->render(count);
    wave->render(buffer, count);
    multiply(buffer, modulation, count);
}

void Instrument::startNote(float frequency) {
    wave->setFrequency(frequency);
    envelope->startNote();
}

void Instrument::endNote(float frequency) {
    envelope->endNote();
}