#include "ArrayArithmetic.h"
#include "DspSubtract.h"
class PdGraph;
message::Object *DspSubtract::new_object(pd::Message *init_message, PdGraph *graph) {
return new DspSubtract(init_message, graph);
}
DspSubtract::DspSubtract(pd::Message *init_message, PdGraph *graph) : DspObject(2, 2, 0, 1, graph) {
constant = init_message->is_float(0) ? init_message->get_float(0) : 0.0f;
process_functionNoMessage = &processScalar;
}
DspSubtract::~DspSubtract() {
}
string DspSubtract::toString() {
const char *fmt = (constant == 0.0f) ? "%s" : "%s %g";
char str[snprintf(NULL, 0, fmt, get_object_label(), constant)+1];
snprintf(str, sizeof(str), fmt, get_object_label(), constant);
return string(str);
}
void DspSubtract::onInletConnectionUpdate(unsigned int inlet_index) {
process_function = (incomingDspConnections[0].size() > 0 && incomingDspConnections[1].size() > 0)
? &processSignal : processScalar;
}
void DspSubtract::process_message(int inlet_index, pd::Message *message) {
if (inlet_index == 1) {
if (message->is_float(0)) constant = message->get_float(0);
}
}
void DspSubtract::processSignal(DspObject *dspObject, int fromIndex, int toIndex) {
DspSubtract *d = reinterpret_cast<DspSubtract *>(dspObject);
ArrayArithmetic::subtract(d->dspBufferAtInlet[0], d->dspBufferAtInlet[1],
d->dspBufferAtOutlet[0], 0, toIndex);
}
void DspSubtract::processScalar(DspObject *dspObject, int fromIndex, int toIndex) {
DspSubtract *d = reinterpret_cast<DspSubtract *>(dspObject);
ArrayArithmetic::subtract(d->dspBufferAtInlet[0], d->constant,
d->dspBufferAtOutlet[0], fromIndex, toIndex);
}