Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/filters/filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "SC_PlugIn.h"
#include "fir.hpp"

InterfaceTable *ft;

PluginLoad(flex_filters) {
ft = inTable;
registerUnit<FIR>(ft, "FIR", false);
registerUnit<FlexPlugins::FIR>(ft, "FIR", false);
}
20 changes: 10 additions & 10 deletions src/filters/fir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "fir.hpp"
extern InterfaceTable *ft;

FIR::FIR() {
FlexPlugins::FIR::FIR() {
m_z = static_cast<float*>(RTAlloc(mWorld, fullBufferSize() * sizeof(float)));
for (size_t i = 0; i < fullBufferSize(); i++) {
m_z[i] = 0.f;
Expand All @@ -34,26 +34,26 @@ FIR::FIR() {
next(1);
}

FIR::~FIR() {
FlexPlugins::FIR::~FIR() {
if (m_z) RTFree(mWorld, m_z);
}

void FIR::next(int inNumSamples) {
void FlexPlugins::FIR::next(int inNumSamples) {
size_t numCoefs = static_cast<size_t>(mNumInputs - 1);
numCoefs = sc_clip(numCoefs, 0, static_cast<size_t>(fullBufferSize()));
const float *inBuf = in(0);
float *outBuf = out(0);
for (size_t xxi = 0; xxi < inNumSamples; xxi++) {
for (size_t i = 0; i < inNumSamples; i++) {
float convResult = 0.f;
// unit delay
for (size_t xxj = fullBufferSize() - 1; xxj > 0; xxj--) {
m_z[xxj] = m_z[xxj-1];
for (size_t j = fullBufferSize() - 1; j > 0; j--) {
m_z[j] = m_z[j-1];
}
m_z[0] = inBuf[xxi];
m_z[0] = inBuf[i];
// convolve
for (size_t xxk = 0; xxk < numCoefs; xxk++) {
convResult += in0(1+xxk) * m_z[xxk];
for (size_t k = 0; k < numCoefs; k++) {
convResult += in0(1+k) * m_z[k];
}
outBuf[xxi] = convResult;
outBuf[i] = convResult;
}
}
22 changes: 12 additions & 10 deletions src/filters/fir.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.

#include "SC_PlugIn.hpp"

class FIR : public SCUnit {
public:
FIR();
~FIR();

private:
void next(int inNumSamples);
float *m_z;
size_t m_delaySize;
};
namespace FlexPlugins {
class FIR : public SCUnit {
public:
FIR();
~FIR();

private:
void next(int inNumSamples);
float *m_z;
size_t m_delaySize;
};
}
24 changes: 13 additions & 11 deletions src/generators/LoopPhasor.schelp
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,29 @@ b = Buffer.read(s, p);
x = Bus.audio(s, 1);

SynthDef(\ptr, {
var sig;
sig = LoopPhasor.ar(\t_start.tr(0.0), \t_end.tr(0.0), \rate.kr(1.0) * BufRateScale.ir(b), 0.0, BufFrames.kr(b), \loopStart.ir(0), \loopEnd.ir(1));
Out.ar(\out.kr(0), sig);
arg rate=1, loopStart=0, loopEnd=1, out=0, trigEnd=0.0;
var sig;
sig = LoopPhasor.ar(0.0, trigEnd, 1 * BufRateScale.ir(b), 0.0, BufFrames.ir(b), loopStart, loopEnd);
sig.poll;
Out.ar(out, sig);
}).add;

SynthDef(\player, {
var sig, ptr_in;
ptr_in = In.ar(\ptr.kr(0));
sig = BufRd.ar(1, b, ptr_in, 0);
Out.ar(0, sig);
arg ptr;
var sig, ptr_in;
ptr_in = In.ar(ptr);
sig = BufRd.ar(1, b, ptr_in, 0);
Out.ar(0, sig);
}).add;
)

// we need two synths: a pointer synth and a player synth
y = Synth(\ptr, [\out, x, \loopStart, 80e3, \loopEnd, 120e3]);
y = Synth(\ptr, [\out, x, \loopStart, 8e4, \loopEnd, 9e4]);
z = Synth(\player, [\ptr, x], addAction: \addToTail);

// to stop looping and end naturally
y.set(\t_end, 1.0);
y.set(\trigEnd, 1.0);

// free the synths
z.free;
y.free;
)
::
8 changes: 4 additions & 4 deletions src/generators/generators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "SC_PlugIn.h"
#include "SC_PlugIn.hpp"
#include "loopPhasor.hpp"
#include "impulseDropout.hpp"
#include "impulseJitter.hpp"
Expand All @@ -31,7 +31,7 @@ InterfaceTable *ft;

PluginLoad(flexplugin_generators) {
ft = inTable;
DefineSimpleUnit(ImpulseDropout);
DefineDtorUnit(ImpulseJitter);
DefineSimpleUnit(LoopPhasor);
registerUnit<FlexPlugins::ImpulseDropout>(ft, "ImpulseDropout", false);
registerUnit<FlexPlugins::ImpulseJitter>(ft, "ImpulseJitter", false);
registerUnit<FlexPlugins::LoopPhasor>(ft, "LoopPhasor", false);
}
Loading
Loading