Skip to content

Commit 2eb3cdf

Browse files
committed
Fix timestamp error in kwik format
1 parent 8491492 commit 2eb3cdf

1 file changed

Lines changed: 15 additions & 25 deletions

File tree

Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.cpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -196,41 +196,31 @@ void HDF5Recording::startChannelBlock()
196196

197197
void HDF5Recording::writeData(int writeChannel, int realChannel, const float* buffer, int size)
198198
{
199-
// int64 t1 = Time::getHighResolutionTicks();
200199
double multFactor = 1 / (float(0x7fff) * getChannel(realChannel)->bitVolts);
201200
int index = processorMap[getChannel(realChannel)->recordIndex];
202201
FloatVectorOperations::copyWithMultiply(scaledBuffer, buffer, multFactor, size);
203202
AudioDataConverters::convertFloatToInt16LE(scaledBuffer, intBuffer, size);
204203
fileArray[index]->writeRowData(intBuffer, size, recordedChanToKWDChan[writeChannel]);
205-
// int64 t2 = Time::getHighResolutionTicks();
206-
// std::cout << "record time: " << float(t2 - t1) / float(Time::getHighResolutionTicksPerSecond()) << std::endl;
207-
int64 sampleOffset = channelLeftOverSamples[writeChannel];
208-
if (writeChannel == 0)
209-
std::cout << "Write " << size << " off " << sampleOffset << " ts " << getTimestamp(realChannel) << " - ";
210-
if (sampleOffset + size >= TIMESTAMP_EACH_NSAMPLES)
211-
{
212-
int64 currentTimestamp = getTimestamp(realChannel);
213-
if (sampleOffset > 0)
214-
{
215-
currentTimestamp = getTimestamp(realChannel) + TIMESTAMP_EACH_NSAMPLES - sampleOffset;
216-
}
217204

218-
for (int samp = 0; samp < size; samp += TIMESTAMP_EACH_NSAMPLES)
219-
{
220-
if (writeChannel == 0)
221-
std::cout << "w: " << currentTimestamp << " ";
222-
channelTimestampArray[writeChannel]->add(currentTimestamp);
223-
currentTimestamp += TIMESTAMP_EACH_NSAMPLES;
224-
}
205+
int sampleOffset = channelLeftOverSamples[writeChannel];
206+
int blockStart = sampleOffset;
207+
int64 currentTS = getTimestamp(realChannel);
225208

226-
channelLeftOverSamples.set(writeChannel, (size + sampleOffset) % TIMESTAMP_EACH_NSAMPLES);
209+
if (sampleOffset > 0)
210+
{
211+
currentTS += TIMESTAMP_EACH_NSAMPLES - sampleOffset;
212+
blockStart += TIMESTAMP_EACH_NSAMPLES - sampleOffset;
227213
}
228-
else
214+
215+
for (int i = 0; i < size; i += TIMESTAMP_EACH_NSAMPLES)
229216
{
230-
channelLeftOverSamples.set(writeChannel, sampleOffset + size);
217+
if ((blockStart + i) < (sampleOffset + size))
218+
{
219+
channelTimestampArray[writeChannel]->add(currentTS);
220+
currentTS += TIMESTAMP_EACH_NSAMPLES;
221+
}
231222
}
232-
if (writeChannel == 0)
233-
std::cout << std::endl;
223+
channelLeftOverSamples.set(writeChannel, (size + sampleOffset) % TIMESTAMP_EACH_NSAMPLES);
234224
}
235225

236226
void HDF5Recording::endChannelBlock()

0 commit comments

Comments
 (0)