crappy squarewave generator

This commit is contained in:
Gordon JC Pearce 2025-08-17 20:37:55 +01:00
parent 5bfe06f721
commit 55bdeae1e7
8 changed files with 147 additions and 10 deletions

41
notes.txt Normal file
View File

@ -0,0 +1,41 @@
highest A violin 1760
c0 from divider = 4186
c1 = top output of divider chain = midi C7 = 2093Hz
c5 = bottom of divider chain = midi C3 = 130.81Hz
RC networks = capacitor and effectively 10k because of the diode and 27.6k resistor network
c1=2842
c6 =
Each key drives two sets of gates, for 4' (violin) and 8' (viola/trumpet/horn)
Five sets of gates apiece
C6 is the *lowest* note
C1 is the *highest* note
Viola filters
C5 to G#4 = D43 10k/18n/5k6 180n/22k/10k
A4 to F#3 = D41 10k/12n/8k2
G3 to E2 = D39 10k/10n/10k 270n/22k/10k
F2 to D1 = D37 10k/4n7/12k
D#1 to C1 = D35 10k/2n2/18k
Violin filters
C5 to G#4 = D105 10k/68n/5k6 47n/22k 4n7/10k
A4 to F#3 = D103 10k/47n/8k2 47n/22k 4n7/10k
G3 to E2 = D101 10k/22n/5k6 47n/22k 1n/18k
F2 to D1 = D99 10k/10n/8k2
D#1 to C1 = D97 10k/5n6/10k
Cello filter = 6n8/50k
Bass filter = 10n/50k
bass lowpass filter = 2-pole 208Hz / Q=1.4
prechorus lpf = 12600 Q=1.3

View File

@ -9,7 +9,7 @@
NAME = sonnenlicht
FILES_DSP = assigner.cpp sonnenlicht.cpp
FILES_DSP = assigner.cpp generator.cpp sonnenlicht.cpp
include ../dpf/Makefile.plugins.mk
TARGETS += vst2 vst3 jack lv2_dsp

View File

@ -1,7 +1,7 @@
/*
sonnenlicht poly ensemble
Copyright 2025 Gordon JC Pearce <gordonjcp@gjcp.net>
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
@ -18,7 +18,7 @@
#include "assigner.hpp"
#define DEBUG
// #define DEBUG
void Assigner::dumpTables() {
#ifdef DEBUG

View File

@ -25,12 +25,12 @@ class Assigner {
public:
Assigner();
void handleMidi(MidiEvent *ev);
uint8_t noteTbl[NUM_VOICES]; // note played by voice
private:
void noteOn(uint8_t note); // incoming note on (or off, if velocity = 0)
void noteOff(uint8_t note); // incoming note off
uint8_t voiceTbl[NUM_VOICES]; // voices in order of use
uint8_t noteTbl[NUM_VOICES]; // note played by voice
void dumpTables();
};

59
plugin/generator.cpp Normal file
View File

@ -0,0 +1,59 @@
#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);
}
}
}

36
plugin/generator.hpp Normal file
View File

@ -0,0 +1,36 @@
/*
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.
*/
#ifndef GENERATOR_HPP
#define GENERATOR_HPP
#include <stdint.h>
class Generator {
public:
Generator();
void setupGenerator(double sampleRate);
void runBlock(float *output, uint8_t *noteTable, uint32_t frames);
uint32_t phase[12];
uint32_t omega[12];
};
#endif

View File

@ -24,9 +24,8 @@ START_NAMESPACE_DISTRHO
Sonnenlicht::Sonnenlicht() : Plugin(kParameterCount, 0, 0), fSampleRate(getSampleRate()) {
printf("initialiser called\n");
w = 440.0 / fSampleRate;
phase = 0;
assigner = new Assigner;
genny.setupGenerator(fSampleRate);
}
Sonnenlicht::~Sonnenlicht() {
@ -52,15 +51,17 @@ void Sonnenlicht::deactivate() {
}
void Sonnenlicht::initParameter(uint32_t index, Parameter& parameter) {
(void) index; (void) &parameter; // pretend these aren't here
return;
}
void Sonnenlicht::run(const float**, float** outputs, uint32_t frames,
const MidiEvent* ev, uint32_t evCount) {
for (uint32_t i = 0; i < evCount; i++) {
//printf("%3d: %02x %02x\n", i, midiEvents[i].data[0], midiEvents[i].data[1]);
assigner->handleMidi((MidiEvent *)&ev[i]);
assigner->handleMidi((MidiEvent*)&ev[i]);
}
genny.runBlock(outputs[0], assigner->noteTbl, frames);
}
Plugin* createPlugin() { return new Sonnenlicht(); }

View File

@ -21,6 +21,7 @@
#include "DistrhoPlugin.hpp"
#include "assigner.hpp"
#include "generator.hpp"
START_NAMESPACE_DISTRHO
@ -59,8 +60,7 @@ class Sonnenlicht : public Plugin {
private:
Assigner *assigner;
double fSampleRate;
float phase;
float w;
Generator genny;
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Sonnenlicht);
};