Skip to content

Commit bc87117

Browse files
committed
Fix event alignment after looping
1 parent cd40e6d commit bc87117

5 files changed

Lines changed: 14 additions & 24 deletions

File tree

Source/Processors/FileReader/BinaryFileSource/BinaryFileSource.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ using namespace BinarySource;
2727

2828
BinaryFileSource::BinaryFileSource()
2929
: m_samplePos (0),
30-
hasEventData (false),
31-
loopCount (0)
30+
hasEventData (false)
3231
{
3332
}
3433

@@ -275,7 +274,6 @@ void BinaryFileSource::processEventData (EventInfo& eventInfo, int64 start, int6
275274
{
276275
int64 local_start = start % getActiveNumSamples();
277276
int64 local_stop = stop % getActiveNumSamples();
278-
int64 loop_count = start / getActiveNumSamples();
279277

280278
std::vector<String> includeStreams = { currentStream, "MessageCenter" };
281279

@@ -291,7 +289,7 @@ void BinaryFileSource::processEventData (EventInfo& eventInfo, int64 start, int6
291289
{
292290
eventInfo.channels.push_back (info.channels[i] - 1);
293291
eventInfo.channelStates.push_back ((info.channelStates[i]));
294-
eventInfo.sampleNumbers.push_back (info.sampleNumbers[i] + loop_count * getActiveNumSamples());
292+
eventInfo.sampleNumbers.push_back (info.sampleNumbers[i]);
295293
eventInfo.text.push_back (info.text[i]);
296294
}
297295
i++;

Source/Processors/FileReader/BinaryFileSource/BinaryFileSource.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class BinaryFileSource : public FileSource
6565
/** Add info about events occurring within a sample range */
6666
void processEventData (EventInfo& info, int64 fromSampleNumber, int64 toSampleNumber) override;
6767

68-
int64 loopCount;
69-
7068
private:
7169
int numActiveChannels;
7270
Array<float> bitVolts;

Source/Processors/FileReader/FileReader.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ FileReader::FileReader() : GenericProcessor ("File Reader"),
4545
currentNumTotalSamples (0),
4646
startSample (0),
4747
stopSample (0),
48-
loopCount (0),
4948
bufferCacheWindow (0),
5049
m_shouldFillBackBuffer (false),
5150
m_bufferSize (1024),
@@ -334,7 +333,6 @@ void FileReader::setActiveStream (int index, bool reset)
334333
startSample = 0;
335334
stopSample = currentNumTotalSamples;
336335
bufferCacheWindow = 0;
337-
loopCount = 0;
338336

339337
/*
340338
startTime->getTimeValue()->setTimeFromMilliseconds (0);
@@ -536,7 +534,6 @@ void FileReader::updateSettings()
536534

537535
/* Set the sample to start of playback and reset loop counter */
538536
playbackSamplePos = startSample;
539-
loopCount = 0;
540537

541538
/* Setup internal buffer based on audio device settings */
542539
AudioDeviceManager& adm = AccessClass::getAudioComponent()->deviceManager;
@@ -668,13 +665,11 @@ void FileReader::process (AudioBuffer<float>& buffer)
668665

669666
int samplesNeededPerBuffer = int (float (buffer.getNumSamples()) * (getDefaultSampleRate() / m_sysSampleRate));
670667

671-
if (! playbackActive && playbackSamplePos + samplesNeededPerBuffer > stopSample)
672-
{
673-
samplesNeededPerBuffer = int (stopSample - playbackSamplePos);
674-
switchNeeded = true;
675-
}
676-
else
677668
m_samplesPerBuffer.set (samplesNeededPerBuffer);
669+
m_samplesPerBuffer.set (samplesNeededPerBuffer);
670+
// FIXME: needs to account for the fact that the ratio might not be an exact
671+
// integer value
672+
m_samplesPerBuffer.set (samplesNeededPerBuffer);
678673
// FIXME: needs to account for the fact that the ratio might not be an exact
679674
// integer value
680675

@@ -684,8 +679,6 @@ void FileReader::process (AudioBuffer<float>& buffer)
684679
switchBuffer();
685680
}
686681

687-
//std::cout << "Reading " << samplesNeededPerBuffer << " samples. " << std::endl;
688-
689682
const float* tempReadBuffer = readBuffer->getData() + (samplesNeededPerBuffer * currentNumChannels * bufferCacheWindow);
690683

691684
for (int ch = 0; ch < currentNumChannels; ++ch)
@@ -705,7 +698,7 @@ void FileReader::process (AudioBuffer<float>& buffer)
705698
// samplesNeededPerBuffer);
706699
}
707700

708-
setTimestampAndSamples (playbackSamplePos, -1.0, samplesNeededPerBuffer, dataStreams[0]->getStreamId()); //TODO: Look at this
701+
setTimestampAndSamples (playbackSamplePos, -1.0, samplesNeededPerBuffer, dataStreams[0]->getStreamId()); //TODO: Look at this could be total or playback
709702

710703
int64 start = playbackSamplePos;
711704

@@ -717,6 +710,11 @@ void FileReader::process (AudioBuffer<float>& buffer)
717710

718711
addEventsInRange (start, stop);
719712

713+
if (playbackSamplePos >= stopSample)
714+
{
715+
playbackSamplePos = startSample + (playbackSamplePos - stopSample);
716+
}
717+
720718
bufferCacheWindow += 1;
721719
bufferCacheWindow %= BUFFER_WINDOW_CACHE_SIZE;
722720

@@ -734,7 +732,7 @@ void FileReader::addEventsInRange (int64 start, int64 stop)
734732

735733
for (int i = 0; i < events.channels.size(); i++)
736734
{
737-
int64 absoluteCurrentSampleNumber = events.sampleNumbers[i] + loopCount * (stopSample - startSample);
735+
int64 absoluteCurrentSampleNumber = events.sampleNumbers[i];
738736
if (events.text.size() && ! events.text[i].isEmpty())
739737
{
740738
String msg = events.text[i];

Source/Processors/FileReader/FileReader.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ class FileReader : public GenericProcessor,
206206
int64 stopSample;
207207
int64 bufferCacheWindow; // the current buffer window to read from readBuffer
208208
Array<RecordedChannelInfo> channelInfo;
209-
int64 loopCount;
210209
bool playbackActive;
211210

212211
std::unique_ptr<FileSource> input;
@@ -218,7 +217,7 @@ class FileReader : public GenericProcessor,
218217

219218
HashMap<String, int> supportedExtensions;
220219

221-
Atomic<int> m_shouldFillBackBuffer;
220+
Atomic<bool> m_shouldFillBackBuffer;
222221
Atomic<int> m_samplesPerBuffer;
223222

224223
unsigned int m_bufferSize;

Source/Processors/FileReader/FileSource.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ class PLUGIN_API FileSource
146146
/** Get the event information for the current stream */
147147
const EventInfo& getEventInfo();
148148

149-
/** Keeps track of how many times the recording has looped */
150-
int64 loopCount = 0;
151-
152149
protected:
153150
/** Holds the name of the current stream */
154151
String currentStream;

0 commit comments

Comments
 (0)