From 4e37eb7f74f141472a6d0a574fce7ccd54103bfc Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Sun, 19 Feb 2012 01:52:34 +0100 Subject: [PATCH] PdGraph::getBlockIndex returns a double for increased precision. --- src/DspObject.cpp | 1 + src/DspObject.h | 2 +- src/PdGraph.cpp | 5 ++--- src/PdGraph.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/DspObject.cpp b/src/DspObject.cpp index 68da4902..3d544f48 100644 --- a/src/DspObject.cpp +++ b/src/DspObject.cpp @@ -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) { diff --git a/src/DspObject.h b/src/DspObject.h index 276405b5..7c0df4ac 100644 --- a/src/DspObject.h +++ b/src/DspObject.h @@ -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 messageQueue; diff --git a/src/PdGraph.cpp b/src/PdGraph.cpp index 10f12301..051766ce 100644 --- a/src/PdGraph.cpp +++ b/src/PdGraph.cpp @@ -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() { diff --git a/src/PdGraph.h b/src/PdGraph.h index 5b73ee70..1a9a4dfd 100644 --- a/src/PdGraph.h +++ b/src/PdGraph.h @@ -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();