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() { Synth::Synth() {
d_debug("initialising synth\n"); d_debug("initialising synth\n");
portaCoeff = 0x0; portaCoeff = 0x0;
noise = new float [4096];
} }
void Synth::buildTables(double sampleRate) { void Synth::buildTables(double sampleRate) {
@ -57,9 +58,14 @@ void Synth::run() {
// 0 sets EA to 0x3fff, 1 adds // 0 sets EA to 0x3fff, 1 adds
uint16_t pwmVal = 0x2000 - ic29.lfo.lfoOut; uint16_t pwmVal = 0x2000 - ic29.lfo.lfoOut;
if (ic29.patchRam.switch2 & 0x01) pwmVal = 0x3fff; if (ic29.patchRam.switch2 & 0x01) pwmVal = 0x3fff;
ic29.pwm = 0.5 - pwmVal / 32768.0f * (ic29.patchRam.pwmLfoMod / 106.0f); 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++) { for (uint8_t i = 0; i < NUM_VOICES; i++) {
ic29.voices[i].update(); ic29.voices[i].update();
} }

View File

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

View File

@ -27,7 +27,7 @@ static inline float poly3blep1(float t) {
return -poly3blep0(1 - 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 // generate a full block of samples for the oscillator
float y, out, t; 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 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! // the signal at about 10Hz or so, preventing any PWM rumble from leaking through!
delay += subosc; delay += subosc;
delay += ic29.noise[i+pos];
out = y * 0.15; out = y * 0.15;
lastpw = pwrc; 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()) { Peacock::Peacock() : Plugin(paramCount, 0, 0), sampleRate(getSampleRate()) {
printf("peacock constructor\n"); printf("peacock constructor\n");
ic29.buildTables(getSampleRate()); 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 // run every synth voice into the buffer here FIXME
for (uint8_t i = 0; i < NUM_VOICES; i++) { 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 framePos += sizeThisTime; // move along the frame