Skip to content
Snippets Groups Projects
Commit 502f5322 authored by Josh Siegle's avatar Josh Siegle Committed by GitHub
Browse files

Merge pull request #47 from beOn/development

addToBuffer with >1 item
parents 2b94695d c408fc40
Branches
Tags
No related merge requests found
......@@ -49,25 +49,39 @@ void DataBuffer::resize(int chans, int size)
numChans = chans;
}
void DataBuffer::addToBuffer(float* data, int64* timestamps, uint64* eventCodes, int numItems)
int DataBuffer::addToBuffer(float* data, int64* timestamps, uint64* eventCodes, int numItems, int chunkSize)
{
// writes one sample for all channels
int startIndex1, blockSize1, startIndex2, blockSize2;
abstractFifo.prepareToWrite(numItems, startIndex1, blockSize1, startIndex2, blockSize2);
for (int chan = 0; chan < numChans; chan++)
{
buffer.copyFrom(chan, // int destChannel
startIndex1, // int destStartSample
data + chan, // const float* source
1); // int num samples
int bs[3] = {blockSize1, blockSize2, 0};
int si[2] = {startIndex1, startIndex2};
int cSize = 0;
int idx = 0;
int blkIdx;
for (int i=0; bs[i] != 0; i++) { // for each of the dest blocks we can write to...
blkIdx = 0;
for (int j=0; j<bs[i]; j+= chunkSize) { // for each chunk...
cSize = chunkSize <= bs[i]-j ? chunkSize : bs[i]-j; // ...figure our how much you can write
for (int chan = 0; chan < numChans; chan++) { // ...write that much, per channel
buffer.copyFrom(chan, // (int destChannel)
si[i]+j, // (int destStartSample)
data + (idx*numChans) + chan, // (const float* source)
cSize); // (int num samples)
}
for (int k=0; k<cSize; k++) {
timestampBuffer[si[i] + blkIdx + k] = timestamps[idx + k];
eventCodeBuffer[si[i] + blkIdx + k] = eventCodes[idx + k];
}
idx+=cSize;
blkIdx+=cSize;
}
}
*(timestampBuffer + startIndex1) = *timestamps;
*(eventCodeBuffer + startIndex1) = *eventCodes;
abstractFifo.finishedWrite(numItems);
// finish write
abstractFifo.finishedWrite(idx);
return idx;
}
int DataBuffer::getNumSamples()
......
......@@ -45,8 +45,17 @@ public:
/** Clears the buffer.*/
void clear();
/** Add an array of floats to the buffer.*/
void addToBuffer(float* data, int64* ts, uint64* eventCodes, int numItems);
/** Add an array of floats to the buffer.
@param data The data.
@param timestamps Array of timestamps. Same length as numItems.
@param eventCodes Array of event codes. Same length as numItems.
@param numItems Total number of samples per channel.
@param chunkSize Number of consecutive samples per channel per chunk.
1 by default. Typically 1 or numItems.
@return The number of items actually written. May be less than numItems if
the buffer doesn't have space.
*/
int addToBuffer(float* data, int64* timestamps, uint64* eventCodes, int numItems, int chunkSize=1);
/** Returns the number of samples currently available in the buffer.*/
int getNumSamples();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment