2222 */
2323
2424#include " HDF5Recording.h"
25- #define MAX_BUFFER_SIZE 10000
25+ #define MAX_BUFFER_SIZE 40960
2626#define CHANNEL_TIMESTAMP_PREALLOC_SIZE 16
2727#define TIMESTAMP_EACH_NSAMPLES 1024
2828
29- HDF5Recording::HDF5Recording () : processorIndex(-1 ), hasAcquired(false )
29+ HDF5Recording::HDF5Recording () : processorIndex(-1 ), hasAcquired(false ), bufferSize(MAX_BUFFER_SIZE)
3030{
3131 // timestamp = 0;
32- scaledBuffer = new float [ MAX_BUFFER_SIZE] ;
33- intBuffer = new int16[ MAX_BUFFER_SIZE] ;
32+ scaledBuffer. malloc ( MAX_BUFFER_SIZE) ;
33+ intBuffer. malloc ( MAX_BUFFER_SIZE) ;
3434}
3535
3636HDF5Recording::~HDF5Recording ()
37- {
38- delete scaledBuffer;
39- delete intBuffer;
37+ {
4038}
4139
4240String HDF5Recording::getEngineID () const
@@ -67,6 +65,9 @@ void HDF5Recording::registerProcessor(const GenericProcessor* proc)
6765
6866void HDF5Recording::resetChannels ()
6967{
68+ scaledBuffer.malloc (MAX_BUFFER_SIZE);
69+ intBuffer.malloc (MAX_BUFFER_SIZE);
70+ bufferSize = MAX_BUFFER_SIZE;
7071 processorIndex = -1 ;
7172 fileArray.clear ();
7273 channelsPerProcessor.clear ();
@@ -173,6 +174,7 @@ void HDF5Recording::closeFiles()
173174 {
174175 if (fileArray[i]->isOpen ())
175176 {
177+ std::cout << " Closed file " << i << std::endl;
176178 fileArray[i]->stopRecording ();
177179 fileArray[i]->close ();
178180 bitVoltsArray[i]->clear ();
@@ -196,11 +198,18 @@ void HDF5Recording::startChannelBlock()
196198
197199void HDF5Recording::writeData (int writeChannel, int realChannel, const float * buffer, int size)
198200{
201+ if (size > bufferSize) // Shouldn't happen, and if it happens it'll be slow, but better this than crashing. Will be reset on reset.
202+ {
203+ std::cerr << " Write buffer overrun, resizing to" << size << std::endl;
204+ bufferSize = size;
205+ scaledBuffer.malloc (size);
206+ intBuffer.malloc (size);
207+ }
199208 double multFactor = 1 / (float (0x7fff ) * getChannel (realChannel)->bitVolts );
200209 int index = processorMap[getChannel (realChannel)->recordIndex ];
201- FloatVectorOperations::copyWithMultiply (scaledBuffer, buffer, multFactor, size);
202- AudioDataConverters::convertFloatToInt16LE (scaledBuffer, intBuffer, size);
203- fileArray[index]->writeRowData (intBuffer, size, recordedChanToKWDChan[writeChannel]);
210+ FloatVectorOperations::copyWithMultiply (scaledBuffer. getData () , buffer, multFactor, size);
211+ AudioDataConverters::convertFloatToInt16LE (scaledBuffer. getData () , intBuffer. getData () , size);
212+ fileArray[index]->writeRowData (intBuffer. getData () , size, recordedChanToKWDChan[writeChannel]);
204213
205214 int sampleOffset = channelLeftOverSamples[writeChannel];
206215 int blockStart = sampleOffset;
0 commit comments