noise gen

This commit is contained in:
Gordon JC Pearce 2024-10-19 00:19:35 +01:00
parent 4f6127cf14
commit 202ddac184
4 changed files with 17 additions and 5 deletions

View File

@ -25,6 +25,7 @@ Synth ic29;
Synth::Synth() {
d_debug("initialising synth\n");
portaCoeff = 0x0;
noise = new float [4096];
}
void Synth::buildTables(double sampleRate) {
@ -57,9 +58,14 @@ void Synth::run() {
// 0 sets EA to 0x3fff, 1 adds
uint16_t pwmVal = 0x2000 - ic29.lfo.lfoOut;
if (ic29.patchRam.switch2 & 0x01) pwmVal = 0x3fff;
ic29.pwm = 0.5 - pwmVal / 32768.0f * (ic29.patchRam.pwmLfoMod / 106.0f);
// generate the voices, then
for (uint32_t i=0; i<bufferSize; i++) {
tr21 = (tr21*519) + 3;
noise[i] = (1-(tr21 & 0x00ffffff) / 8388608.0f) * (ic29.patchRam.noiseLevel * 0.0063);
}
for (uint8_t i = 0; i < NUM_VOICES; i++) {
ic29.voices[i].update();
}

View File

@ -72,7 +72,7 @@ class Voice {
public:
Voice();
uint8_t note = 0x3c; // middle C
void run(float *buffer, uint32_t samples);
void run(float *buffer, uint32_t pos, uint32_t samples);
void update();
void on(uint8_t note);
void off();
@ -106,6 +106,7 @@ class Synth {
void buildTables(double sampleRate);
double sampleRate;
uint32_t bufferSize;
uint16_t masterPitch; // sum of bend and LFO, plus any other pitch-setting value
// protected:
uint16_t envAtk, envDcy, envStn, envRls;
@ -113,6 +114,8 @@ class Synth {
bool sustained;
double pitchTable[104];
float *noise;
// private:
uint8_t vcoBend=42;
uint8_t vcfBend=42;
@ -123,6 +126,7 @@ class Synth {
uint8_t modWheel = 0x00;
float pwm;
uint32_t tr21;
struct {
uint8_t lfoRate = 0x3f;

View File

@ -27,7 +27,7 @@ static inline float poly3blep1(float t) {
return -poly3blep0(1 - t);
}
void Voice::run(float *buffer, uint32_t samples) {
void Voice::run(float *buffer, uint32_t pos, uint32_t samples) {
// generate a full block of samples for the oscillator
float y, out, t;
@ -69,10 +69,11 @@ void Voice::run(float *buffer, uint32_t samples) {
// the DC correction is important because the hardware synth is AC-coupled effectively high-passing
// the signal at about 10Hz or so, preventing any PWM rumble from leaking through!
delay += subosc;
delay += ic29.noise[i+pos];
out = y * 0.15;
lastpw = pwrc;
buffer[i] += out * gain;
buffer[i + pos] += out * gain;
}
}

View File

@ -26,6 +26,7 @@ START_NAMESPACE_DISTRHO
Peacock::Peacock() : Plugin(paramCount, 0, 0), sampleRate(getSampleRate()) {
printf("peacock constructor\n");
ic29.buildTables(getSampleRate());
ic29.bufferSize = getBufferSize();
}
@ -86,7 +87,7 @@ void Peacock::run(const float **, float **outputs, uint32_t frames, const MidiEv
// run every synth voice into the buffer here FIXME
for (uint8_t i = 0; i < NUM_VOICES; i++) {
ic29.voices[i].run(outputs[0] + framePos, sizeThisTime);
ic29.voices[i].run(outputs[0], framePos, sizeThisTime);
}
framePos += sizeThisTime; // move along the frame