60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
#include "generator.hpp"
|
|
/*
|
|
sonnenlicht poly ensemble
|
|
|
|
Copyright 2024 Gordon JC Pearce <gordonjcp@gjcp.net>
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
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 <string.h>
|
|
|
|
#include <cstdio>
|
|
|
|
#include "DistrhoPluginInfo.h"
|
|
|
|
Generator::Generator() {
|
|
}
|
|
|
|
void Generator::setupGenerator(double sampleRate) {
|
|
// create the phase increments for each semitone
|
|
for (uint8_t i = 0; i < 12; i++) {
|
|
phase[i] = 0;
|
|
uint32_t f;
|
|
f = (1 << 31) * (65.406 * powf(2, 0.083334 * (i + 12)) / sampleRate);
|
|
omega[i] = f;
|
|
}
|
|
}
|
|
|
|
void Generator::runBlock(float *output, uint8_t *noteTable, uint32_t frames) {
|
|
|
|
memset(output, 0, frames * sizeof(float));
|
|
|
|
for (uint32_t i = 0; i < frames; i++) {
|
|
for (uint8_t p = 0; p < 12; p++) {
|
|
phase[p] += omega[p];
|
|
}
|
|
|
|
for (uint8_t k=0; k<NUM_VOICES; k++) {
|
|
uint8_t n1 = noteTable[k] % 12, n2 = (noteTable[k]/12 - 2);
|
|
output[i] += ((phase[n1] & (0x80000000 >> n2)) ? 0.1 : -0.1) * (noteTable[k]&0x80?0:1);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|