Skip to content

Commit

Permalink
PdGraph::getBlockIndex returns a double for increased precision.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhroth committed Feb 19, 2012
1 parent f3606c5 commit 4e37eb7
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/DspObject.cpp
Expand Up @@ -45,6 +45,7 @@ void DspObject::init(int numDspInlets, int numDspOutlets, int blockSize) {
blockSizeInt = blockSize;
blockIndexOfLastMessage = 0.0f;
signalPrecedence = MESSAGE_MESSAGE; // default
blockIndexOfLastMessage = 0.0;
numBytesInBlock = blockSizeInt * sizeof(float);

if (zeroBufferSize < blockSize) {
Expand Down
2 changes: 1 addition & 1 deletion src/DspObject.h
Expand Up @@ -142,7 +142,7 @@ class DspObject : public MessageObject {
int blockSizeInt;

/** The sample index of the last received message, relative to the beginning of the current block. */
float blockIndexOfLastMessage;
double blockIndexOfLastMessage;

/** The local message queue. Messages that are pending for the next block. */
queue<MessageLetPair> messageQueue;
Expand Down
5 changes: 2 additions & 3 deletions src/PdGraph.cpp
Expand Up @@ -434,10 +434,9 @@ void PdGraph::unregisterObject(MessageObject *messageObject) {
}
}

float PdGraph::getBlockIndex(PdMessage *message) {
double PdGraph::getBlockIndex(PdMessage *message) {
// sampleRate is in samples/second, but we need samples/millisecond
return ((float) (message->getTimestamp() - context->getBlockStartTimestamp())) *
context->getSampleRate() / 1000.0f;
return (message->getTimestamp() - context->getBlockStartTimestamp()) * 0.001 * context->getSampleRate();
}

float PdGraph::getSampleRate() {
Expand Down
2 changes: 1 addition & 1 deletion src/PdGraph.h
Expand Up @@ -128,7 +128,7 @@ class PdGraph : public DspObject {
int getNumOutputChannels();

/** A convenience function to determine when in a block a message occurs. */
float getBlockIndex(PdMessage *message);
double getBlockIndex(PdMessage *message);

/** Returns the graphId of this graph. */
int getGraphId();
Expand Down

0 comments on commit 4e37eb7

Please sign in to comment.