#include "BufferPool.h"
#include "DspReceive.h"
#include "PdGraph.h"
message::Object *DspReceive::new_object(pd::Message *init_message, PdGraph *graph) {
return new DspReceive(init_message, graph);
}
DspReceive::DspReceive(pd::Message *init_message, PdGraph *graph) : DspObject(1, 0, 0, 1, graph) {
if (init_message->is_symbol(0)) {
name = utils::copy_string(init_message->get_symbol(0));
dspBufferAtOutlet[0] = ALLOC_ALIGNED_BUFFER(graph->get_block_size() * sizeof(float));
} else {
name = NULL;
graph->print_err("receive~ not initialised with a name.");
}
process_function = &processSignal;
dspBufferAtInlet[0] = graph->get_buffer_pool()->get_zero_buffer();
}
DspReceive::~DspReceive() {
free(name);
FREE_ALIGNED_BUFFER(dspBufferAtOutlet[0]);
}
void DspReceive::process_message(int inlet_index, pd::Message *message) {
if (message->has_format("ss") && message->is_symbol_str(0, "set")) {
graph->print_err("[receive~ %s]: message \"set %s\" is not supported.", name, message->get_symbol(1));
}
}
void DspReceive::processSignal(DspObject *dspObject, int fromIndex, int toIndex) {
DspReceive *d = reinterpret_cast<DspReceive *>(dspObject);
memcpy(d->dspBufferAtOutlet[0], d->dspBufferAtInlet[0], toIndex*sizeof(float));
}