basically makes a noise
This commit is contained in:
parent
8c66392e97
commit
634d516b5f
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
#include "assigner.hpp"
|
#include "assigner.hpp"
|
||||||
|
|
||||||
#define DEBUG
|
#include "module.hpp"
|
||||||
|
|
||||||
void Assigner::dumpTables() {
|
void Assigner::dumpTables() {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
@ -93,6 +93,8 @@ void Assigner::noteOff(uint8_t note) {
|
||||||
memmove(voiceTbl + i, voiceTbl + i + 1, NUM_VOICES - i - 1);
|
memmove(voiceTbl + i, voiceTbl + i + 1, NUM_VOICES - i - 1);
|
||||||
voiceTbl[NUM_VOICES - 1] = v;
|
voiceTbl[NUM_VOICES - 1] = v;
|
||||||
noteTbl[v] |= 0x80;
|
noteTbl[v] |= 0x80;
|
||||||
|
|
||||||
|
voice[v].off();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Assigner::noteOn(uint8_t note) {
|
void Assigner::noteOn(uint8_t note) {
|
||||||
|
|
@ -136,4 +138,5 @@ void Assigner::noteOn(uint8_t note) {
|
||||||
noteTbl[v] = note;
|
noteTbl[v] = note;
|
||||||
|
|
||||||
d_debug("send voice on %3d to voice %d", note, v);
|
d_debug("send voice on %3d to voice %d", note, v);
|
||||||
|
voice[v].on(note);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,13 @@
|
||||||
#define _ASSIGNER_HPP
|
#define _ASSIGNER_HPP
|
||||||
|
|
||||||
#include "DistrhoPlugin.hpp"
|
#include "DistrhoPlugin.hpp"
|
||||||
|
#include "module.hpp"
|
||||||
|
|
||||||
class Assigner {
|
class Assigner {
|
||||||
public:
|
public:
|
||||||
Assigner();
|
Assigner();
|
||||||
void handleMidi(MidiEvent* ev);
|
void handleMidi(MidiEvent* ev);
|
||||||
|
Voice* voice;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void noteOn(uint8_t note); // incoming note on (or off, if velocity = 0)
|
void noteOn(uint8_t note); // incoming note on (or off, if velocity = 0)
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,15 @@ START_NAMESPACE_DISTRHO
|
||||||
|
|
||||||
Peacock::Peacock() : Plugin(0, 0, 0) {
|
Peacock::Peacock() : Plugin(0, 0, 0) {
|
||||||
d_debug("peacock constructor\n");
|
d_debug("peacock constructor\n");
|
||||||
|
sampleRate = getSampleRate();
|
||||||
|
m = new Module;
|
||||||
ic1 = new Assigner;
|
ic1 = new Assigner;
|
||||||
|
ic1->voice = voice;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Peacock::~Peacock() {
|
||||||
|
free(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peacock::initAudioPort(bool input, uint32_t index, AudioPort& port) {
|
void Peacock::initAudioPort(bool input, uint32_t index, AudioPort& port) {
|
||||||
|
|
@ -47,11 +55,50 @@ void Peacock::runMidi(const MidiEvent *ev, uint32_t ev_count, uint32_t timeLimit
|
||||||
}
|
}
|
||||||
|
|
||||||
void Peacock::run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) {
|
void Peacock::run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) {
|
||||||
|
// calculate a block of samples, allowing for the synth timing not dividing exactly
|
||||||
|
uint32_t framePos = 0;
|
||||||
|
uint32_t sizeThisTime = 0;
|
||||||
|
framesLeft = frames;
|
||||||
|
|
||||||
|
// now clear the left and right audio buffers
|
||||||
memset(outputs[0], 0, frames * sizeof(float));
|
memset(outputs[0], 0, frames * sizeof(float));
|
||||||
memset(outputs[1], 0, frames * sizeof(float));
|
memset(outputs[1], 0, frames * sizeof(float));
|
||||||
|
|
||||||
|
// if there were any events that happen between now and the end of this block, process them
|
||||||
lastEvent = 0;
|
lastEvent = 0;
|
||||||
runMidi(midiEvents, midiEventCount, frames);
|
//printf("in run(), %d samples left in block\n", blockLeft);
|
||||||
|
runMidi(midiEvents, midiEventCount, blockLeft);
|
||||||
|
|
||||||
|
while (framePos < frames) {
|
||||||
|
if (blockLeft == 0) {
|
||||||
|
// no more samples to calculate in this update period
|
||||||
|
blockLeft = sampleRate / 238; // update rate in Hz
|
||||||
|
//printf("no more samples in block, resetting to %d at %d\n", blockLeft, framePos);
|
||||||
|
runMidi(midiEvents, midiEventCount, framePos + blockLeft);
|
||||||
|
|
||||||
|
// FIXME run one IC29 loop
|
||||||
|
}
|
||||||
|
|
||||||
|
// how many frames to do? Are we about to run off an update block
|
||||||
|
sizeThisTime = (framesLeft < blockLeft) ? framesLeft : blockLeft;
|
||||||
|
|
||||||
|
//printf("running voices for %d at %d\n", sizeThisTime, framePos);
|
||||||
|
// now run all the voices for this chunk of samples
|
||||||
|
for (uint32_t i = 0; i < NUM_VOICES; i++) {
|
||||||
|
voice[i].run(m, outputs[0] + framePos, sizeThisTime);
|
||||||
|
}
|
||||||
|
//printf("\n");
|
||||||
|
|
||||||
|
framePos += sizeThisTime;
|
||||||
|
framesLeft -= sizeThisTime;
|
||||||
|
blockLeft -= sizeThisTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
// now we've assembled a full chunk of audio
|
||||||
|
// we'd apply the highpass filter and chorus here
|
||||||
|
// for now just copy left to right
|
||||||
|
memcpy(outputs[1], outputs[0], sizeof(float) * frames);
|
||||||
|
// outputs[0][0]=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Plugin* createPlugin() { return new Peacock(); }
|
Plugin* createPlugin() { return new Peacock(); }
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,16 @@
|
||||||
#ifndef _PEACOCK_HPP
|
#ifndef _PEACOCK_HPP
|
||||||
#define _PEACOCK_HPP
|
#define _PEACOCK_HPP
|
||||||
|
|
||||||
#define DEBUG
|
|
||||||
|
|
||||||
#include "DistrhoPlugin.hpp"
|
#include "DistrhoPlugin.hpp"
|
||||||
#include "assigner.hpp"
|
#include "assigner.hpp"
|
||||||
|
#include "module.hpp"
|
||||||
START_NAMESPACE_DISTRHO
|
START_NAMESPACE_DISTRHO
|
||||||
|
|
||||||
class Peacock : public Plugin {
|
class Peacock : public Plugin {
|
||||||
public:
|
public:
|
||||||
Peacock();
|
Peacock();
|
||||||
|
~Peacock();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const char* getLabel() const override { return "peacock-8"; }
|
const char* getLabel() const override { return "peacock-8"; }
|
||||||
|
|
@ -46,9 +46,20 @@ class Peacock : public Plugin {
|
||||||
void run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) override;
|
void run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) override;
|
||||||
void runMidi(const MidiEvent* ev, uint32_t ev_count, uint32_t timeLimit);
|
void runMidi(const MidiEvent* ev, uint32_t ev_count, uint32_t timeLimit);
|
||||||
|
|
||||||
|
Voice voice[NUM_VOICES];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t lastEvent = 0; // event number of last MIDI event processed in a chunk
|
|
||||||
Assigner* ic1;
|
Assigner* ic1;
|
||||||
|
Module* m;
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t sampleRate;
|
||||||
|
|
||||||
|
// variables for breaking up the 4.3 millisecond module board ticks
|
||||||
|
uint32_t lastEvent = 0; // event number of last MIDI event processed in a chunk
|
||||||
|
uint32_t framesLeft = 0, blockLeft = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Peacock);
|
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Peacock);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "module.hpp"
|
#include "module.hpp"
|
||||||
|
|
||||||
|
|
||||||
// antialiasing using polybleps, as described in KVRAudio forum by Mystran
|
// antialiasing using polybleps, as described in KVRAudio forum by Mystran
|
||||||
|
|
||||||
static inline float poly3blep0(float t) {
|
static inline float poly3blep0(float t) {
|
||||||
float t2 = t * t;
|
float t2 = t * t;
|
||||||
return t * t2 - 0.5f * t2 * t2;
|
return 2*( t * t2 - 0.5f * t2 * t2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline float poly3blep1(float t) {
|
static inline float poly3blep1(float t) {
|
||||||
|
|
@ -51,6 +51,12 @@ void Voice::run(Module *m, float* buffer, uint32_t samples) {
|
||||||
// carry out per-voice calculations for each block of samples
|
// carry out per-voice calculations for each block of samples
|
||||||
float out, t;
|
float out, t;
|
||||||
|
|
||||||
|
// printf("%f ", delay);
|
||||||
|
m->saw = 1;
|
||||||
|
m->square=1;
|
||||||
|
m->sub=.5;
|
||||||
|
m->pw = 0.5;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < samples; i++) {
|
for (uint32_t i = 0; i < samples; i++) {
|
||||||
out = delay;
|
out = delay;
|
||||||
delay = 0;
|
delay = 0;
|
||||||
|
|
@ -86,8 +92,8 @@ void Voice::run(Module *m, float* buffer, uint32_t samples) {
|
||||||
delay += m->sub * subosc;
|
delay += m->sub * subosc;
|
||||||
// delay += (1-(m->noisegen/(float)(1<<30))) * m->noise; FIXME figure out what to do about noise
|
// delay += (1-(m->noisegen/(float)(1<<30))) * m->noise; FIXME figure out what to do about noise
|
||||||
|
|
||||||
buffer[i] = 0.125 * amp * out;
|
buffer[i] += 0.125 * amp * out;
|
||||||
lastpw = m->pw;
|
lastpw = m->pw;
|
||||||
}
|
}
|
||||||
|
// buffer[0] += 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue