Skip to content

Commit

Permalink
inlet~ and outlet~ pass on their input buffers directly to following …
Browse files Browse the repository at this point in the history
…objects.

When the input buffer to these objects is updated, they inform
following objects of the buffer update.
  • Loading branch information
mhroth committed Feb 26, 2012
1 parent c2cb504 commit 7bd3d98
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/DspFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void DspFilter::onInletConnectionUpdate(unsigned int inletIndex) {
// TODO(mhroth)
}

float *DspFilter::getDspBufferRefAtOutlet(int outletIndex) {
float *DspFilter::getDspBufferAtOutlet(int outletIndex) {
return dspBufferAtOutlet0+2;
}

Expand Down
2 changes: 1 addition & 1 deletion src/DspFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DspFilter : public DspObject {
DspFilter(int numMessageInlets, PdGraph *graph);
~DspFilter();

float *getDspBufferRefAtOutlet(int outletIndex);
float *getDspBufferAtOutlet(int outletIndex);

void onInletConnectionUpdate(unsigned int inletIndex);

Expand Down
19 changes: 15 additions & 4 deletions src/DspInlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ MessageObject *DspInlet::newObject(PdMessage *initMessage, PdGraph *graph) {
}

DspInlet::DspInlet(PdGraph *graph) : DspObject(0, 1, 0, 1, graph) {
// nothing to do
free(dspBufferAtOutlet0); // this buffer is not needed
dspBufferAtOutlet0 = NULL; // the inlet buffer is passed directly to subsequent dsp objects
}

DspInlet::~DspInlet() {
Expand Down Expand Up @@ -70,10 +71,20 @@ list<MessageObject *> *DspInlet::getProcessOrderFromInlet() {
return processList;
}

void DspInlet::receiveMessage(int inletIndex, PdMessage *message) {
graph->printErr("DspInlet has received a message in error: %s", message->toString());
void DspInlet::onDspBufferAtInletUpdate(float *buffer, unsigned int inletIndex) {
// when the dsp buffer updates at a given inlet, inform all receiving objects
list<ObjectLetPair> dspConnections = outgoingDspConnections[0];
for (list<ObjectLetPair>::iterator it = dspConnections.begin(); it != dspConnections.end(); ++it) {
ObjectLetPair letPair = *it;
DspObject *dspObject = reinterpret_cast<DspObject *>(letPair.first);
dspObject->setDspBufferAtInlet(dspBufferAtInlet[inletIndex], letPair.second);
}
}

float *DspInlet::getDspBufferAtOutlet(int outletIndex) {
return dspBufferAtInlet[outletIndex];
}

void DspInlet::processDsp() {
memcpy(dspBufferAtOutlet0, dspBufferAtInlet[0], numBytesInBlock);
// nothing to do
}
6 changes: 5 additions & 1 deletion src/DspInlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ class DspInlet : public DspObject {
list<MessageObject *> *getProcessOrder();
list<MessageObject *> *getProcessOrderFromInlet();

void receiveMessage(int inletIndex, PdMessage *message);
float *getDspBufferAtOutlet(int outletIndex);

void processDsp();

protected:
void onDspBufferAtInletUpdate(float *buffer, unsigned int inletIndex);
};

#endif // _DSP_INLET_H_
18 changes: 12 additions & 6 deletions src/DspObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ ConnectionType DspObject::getConnectionType(int outletIndex) {
return DSP;
}

float *DspObject::getDspBufferRefAtOutlet(int outletIndex) {
float *DspObject::getDspBufferAtOutlet(int outletIndex) {
// sanity check on outletIndex
return (outletIndex < outgoingDspConnections.size()) ? dspBufferAtOutlet0 + (outletIndex * blockSizeInt) : NULL;
}
Expand Down Expand Up @@ -141,21 +141,21 @@ void DspObject::addConnectionFromObjectToInlet(MessageObject *messageObject, int
list<ObjectLetPair> *connections = &incomingDspConnections[inletIndex];
ObjectLetPair objectLetPair = make_pair(messageObject, outletIndex);
connections->push_back(objectLetPair);

onInletConnectionUpdate(inletIndex);
}

onInletConnectionUpdate(inletIndex);
}

void DspObject::removeConnectionFromObjectToInlet(MessageObject *messageObject, int outletIndex, int inletIndex) {
if (messageObject->getConnectionType(outletIndex) == DSP) {
list<ObjectLetPair> *connections = &incomingDspConnections[inletIndex];
ObjectLetPair objectLetPair = make_pair(messageObject, outletIndex);
connections->remove(objectLetPair); // NOTE(mhroth): does this work?

onInletConnectionUpdate(inletIndex);
} else {
MessageObject::removeConnectionFromObjectToInlet(messageObject, outletIndex, inletIndex);
}

onInletConnectionUpdate(inletIndex);
}

void DspObject::onInletConnectionUpdate(unsigned int inletIndex) {
Expand Down Expand Up @@ -183,8 +183,14 @@ void DspObject::removeConnectionToObjectFromOutlet(MessageObject *messageObject,
}
}

void DspObject::setDspBufferRefAtInlet(float *buffer, unsigned int inletIndex) {
void DspObject::setDspBufferAtInlet(float *buffer, unsigned int inletIndex) {
dspBufferAtInlet[inletIndex] = buffer;

onDspBufferAtInletUpdate(buffer, inletIndex);
}

void DspObject::onDspBufferAtInletUpdate(float *buffer, unsigned int inletIndex) {
// nothign to do
}


Expand Down
6 changes: 4 additions & 2 deletions src/DspObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class DspObject : public MessageObject {
/** Returns the connection type of the given outlet. */
virtual ConnectionType getConnectionType(int outletIndex);

virtual float *getDspBufferRefAtOutlet(int outletIndex);
virtual float *getDspBufferAtOutlet(int outletIndex);

virtual void setDspBufferRefAtInlet(float *buffer, unsigned int inletIndex);
virtual void setDspBufferAtInlet(float *buffer, unsigned int inletIndex);

virtual void addConnectionFromObjectToInlet(MessageObject *messageObject, int outletIndex, int inletIndex);
virtual void addConnectionToObjectFromOutlet(MessageObject *messageObject, int inletIndex, int outletIndex);
Expand Down Expand Up @@ -117,6 +117,8 @@ class DspObject : public MessageObject {
*/
virtual void onInletConnectionUpdate(unsigned int inletIndex);

virtual void onDspBufferAtInletUpdate(float *buffer, unsigned int inletIndex);

/** Immediately deletes all messages in the message queue without executing them. */
void clearMessageQueue();

Expand Down
19 changes: 15 additions & 4 deletions src/DspOutlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ MessageObject *DspOutlet::newObject(PdMessage *initMessage, PdGraph *graph) {
}

DspOutlet::DspOutlet(PdGraph *graph) : DspObject(0, 1, 0, 1, graph) {
canvasX = 0.0f;
free(dspBufferAtOutlet0);
dspBufferAtOutlet0 = NULL;
}

DspOutlet::~DspOutlet() {
Expand All @@ -50,10 +51,20 @@ bool DspOutlet::isLeafNode() {
return true;
}

float *DspOutlet::getDspBufferRefAtOutlet(int outletIndex) {
return dspBufferAtOutlet0;
void DspOutlet::onDspBufferAtInletUpdate(float *buffer, unsigned int inletIndex) {
// when the dsp buffer updates at a given inlet, inform all receiving objects
list<ObjectLetPair> dspConnections = outgoingDspConnections[0];
for (list<ObjectLetPair>::iterator it = dspConnections.begin(); it != dspConnections.end(); ++it) {
ObjectLetPair letPair = *it;
DspObject *dspObject = reinterpret_cast<DspObject *>(letPair.first);
dspObject->setDspBufferAtInlet(dspBufferAtInlet[inletIndex], letPair.second);
}
}

float *DspOutlet::getDspBufferAtOutlet(int outletIndex) {
return dspBufferAtInlet[outletIndex];
}

void DspOutlet::processDsp() {
memcpy(dspBufferAtOutlet0, dspBufferAtInlet[0], numBytesInBlock);
// nothing to do
}
5 changes: 4 additions & 1 deletion src/DspOutlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ class DspOutlet : public DspObject {

bool isLeafNode();

float *getDspBufferRefAtOutlet(int outletIndex);
float *getDspBufferAtOutlet(int outletIndex);

void processDsp();

protected:
void onDspBufferAtInletUpdate(float *buffer, unsigned int inletIndex);
};

#endif // _DSP_OUTLET_H_
2 changes: 1 addition & 1 deletion src/DspRfft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void DspRfft::processDsp() {
inputVector.imagp = DspObject::zeroBuffer;
DSPSplitComplex outputVector;
outputVector.realp = dspBufferAtOutlet0;
outputVector.imagp = getDspBufferRefAtOutlet(1);
outputVector.imagp = getDspBufferAtOutlet(1);
vDSP_fft_zop(fftSetup, &inputVector, 1, &outputVector, 1, log2n, kFFTDirection_Forward);

// NOTE(mhroth): vDSP_fft_zop outputs the entire series of symmetric coefficients.
Expand Down
10 changes: 5 additions & 5 deletions src/PdGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ void PdGraph::addLetObjectToLetList(MessageObject *inletObject, float newPositio

#pragma mark -

float *PdGraph::getDspBufferRefAtOutlet(int outletIndex) {
float *PdGraph::getDspBufferAtOutlet(int outletIndex) {
DspObject *dspOutlet = (DspObject *) outletList.at(outletIndex);
return dspOutlet->getDspBufferRefAtOutlet(0);
return dspOutlet->getDspBufferAtOutlet(0);
}


Expand Down Expand Up @@ -694,15 +694,15 @@ void PdGraph::computeLocalDspProcessOrder() {
switch (incomingDspConnectionsList.size()) {
case 0: {
// if no connections are made to an inlet, then it receives a zero buffer
dspObject->setDspBufferRefAtInlet(zeroBuffer, i);
dspObject->setDspBufferAtInlet(zeroBuffer, i);
break;
}
case 1: {
// if only one connections exists to the object, add the connection directly
ObjectLetPair objectLetPair = incomingDspConnectionsList.front();
DspObject *prevObject = (DspObject *) objectLetPair.first;
unsigned int outletIndex = objectLetPair.second;
dspObject->setDspBufferRefAtInlet(prevObject->getDspBufferRefAtOutlet(outletIndex), i);
dspObject->setDspBufferAtInlet(prevObject->getDspBufferAtOutlet(outletIndex), i);
break;
}
default: {
Expand All @@ -722,7 +722,7 @@ void PdGraph::computeLocalDspProcessOrder() {
implicitDspAddList.push_back(dspAdd);
}
// set dsp ref at inlet of dspObject to prevObject
dspObject->setDspBufferRefAtInlet(prevObject->getDspBufferRefAtOutlet(0), i);
dspObject->setDspBufferAtInlet(prevObject->getDspBufferAtOutlet(0), i);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/PdGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class PdGraph : public DspObject {
void setValueForName(char *name, float constant);
float getValueForName(char *name);

float *getDspBufferRefAtOutlet(int outletIndex);
float *getDspBufferAtOutlet(int outletIndex);

void processDsp();

Expand Down

0 comments on commit 7bd3d98

Please sign in to comment.