From 537f571f6a3c1a5ae6a2c216e2637e241f93ea75 Mon Sep 17 00:00:00 2001 From: Blitblank Date: Sat, 7 Feb 2026 12:56:21 -0600 Subject: [PATCH] preliminary wavetable generation --- .../example_wavetable.cpython-311.pyc | Bin 0 -> 354 bytes scripts/example_wavetable.py | 3 ++ scripts/generate_wavetable.py | 41 ++++++++++++++++++ src/synth/Voice.cpp | 1 + 4 files changed, 45 insertions(+) create mode 100644 scripts/__pycache__/example_wavetable.cpython-311.pyc create mode 100644 scripts/example_wavetable.py create mode 100644 scripts/generate_wavetable.py diff --git a/scripts/__pycache__/example_wavetable.cpython-311.pyc b/scripts/__pycache__/example_wavetable.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..467c7f9ec231b035040b8c308574fd1ed7b544af GIT binary patch literal 354 zcmZ3^%ge<81o@rqnYuvwF^B^Lj8MjB9w1{nLkdF+Lli>_V=#jzQ!-2qh-QZ3&niI1 zbcPa`J|HiJaT$=e8ZN>JGzFyJuZll2S0Sw^KUblkC_g#1xLA|%7HdIKW?sokhR;Ba z48I)pGxBp&^^+2dQuJN&lS^|`^Gb^Ki&6{ni}iC;OA?b3b4rW#i<65o3xMLO6^Xe8 zIjQmGiDe+UoK(Gn%3JJEvy0e)1~LJ0u{e-uV7SY|d4Ws%B8$uw7MTk$RKyCD^V4Jm zD=uOIa=;=*Y(Um84x8Nkl+v73yCM!C7v!B{IUw<0!+0<0eZjbTkK literal 0 HcmV?d00001 diff --git a/scripts/example_wavetable.py b/scripts/example_wavetable.py new file mode 100644 index 0000000..9397d53 --- /dev/null +++ b/scripts/example_wavetable.py @@ -0,0 +1,3 @@ + +def process(phase): + print("im from process") diff --git a/scripts/generate_wavetable.py b/scripts/generate_wavetable.py new file mode 100644 index 0000000..46fda4b --- /dev/null +++ b/scripts/generate_wavetable.py @@ -0,0 +1,41 @@ + +# this is a script for generating a wavetable file +# a wavetable file consists of a one-dimensional array of samples representing one period of a waveform +# metadata includes: +# - file version (for program compatibility) +# - binary format (float, double, int32, etc.) +# - domain (normal is a phase from x=0 to x=2pi) +# - range (depending on datatypes, e.g. float=[-1,1], int32=[-2^15, 2^15-1]) +# - waveform RMS (for loudness normalization) +# the synth program uses the filename, not any metadata + +# this script uses the function defined in example_wavetable.py to calculate samples +# if you want a custom wavetable, copy/edit/modify the example function (desmos is great for brainstorming) + +import example_wavetable + +def createFile(): + print("creating file") + return 1 + +def writeMetadata(file): + print("im writing metadata") + +def generateWavetable(file): + print("im generating the wavetable") + example_wavetable.process() + +def closeFile(file): + print("finishing up") + +def main(): + print("Hello main") + file = createFile() + writeMetadata(file) + generateWavetable(file) + closeFile(file) + print("done") + + +if __name__ == "__main__": + main() diff --git a/src/synth/Voice.cpp b/src/synth/Voice.cpp index d7c391a..6c8d3e7 100644 --- a/src/synth/Voice.cpp +++ b/src/synth/Voice.cpp @@ -81,6 +81,7 @@ float Voice::process(float* params, bool& scopeTrigger) { float velocityGain = std::lerp(velocityCenter, velocity_, velocitySensitivity); float gain = gainEnv * getParam(ParamId::Osc1VolumeDepth) * velocityGain; + gain *= (100.0f - static_cast(note_)) * 0.005f + 0.75; // sample generation uint8_t osc1Wave = (static_cast(std::round(getParam(ParamId::Osc1WaveSelector1))));