Skip to content

Commit becba90

Browse files
committed
Add events to FileReader
1 parent 744e2e8 commit becba90

3 files changed

Lines changed: 47 additions & 9 deletions

File tree

188 KB
Binary file not shown.

Source/Processors/FileReader/FileReader.cpp

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ FileReader::FileReader()
5757
supportedExtensions.set (extensions[j].toLowerCase(), i + 1);
5858
}
5959
}
60+
61+
/*
62+
const DataChannel* in = getDataChannel(0);
63+
EventChannel* ev = new EventChannel(EventChannel::TTL, 8, 1, (in) ? in->getSampleRate() : CoreServices::getGlobalSampleRate(), this);
64+
moduleEventChannels.add(ev);
65+
*/
6066
}
6167

6268

@@ -230,41 +236,51 @@ void FileReader::updateSettings()
230236

231237
void FileReader::process (AudioSampleBuffer& buffer)
232238
{
233-
234-
235239
const int samplesNeeded = int (float (buffer.getNumSamples()) * (getDefaultSampleRate() / 44100.0f));
236240
// FIXME: needs to account for the fact that the ratio might not be an exact
237241
// integer value
238-
239242
int samplesRead = 0;
240243

241244
while (samplesRead < samplesNeeded)
242245
{
246+
count +=1;
243247
int samplesToRead = samplesNeeded - samplesRead;
248+
int iterationsPerSecond = getDefaultSampleRate()/samplesToRead;
249+
int sample = getDefaultSampleRate()-iterationsPerSecond*samplesToRead;
250+
//std::cout<<"sample: " <<sample<<"\n";
244251
if ( (currentSample + samplesToRead) > stopSample)
245252
{
246253
samplesToRead = stopSample - currentSample;
247254
if (samplesToRead > 0)
248-
input->readData (readBuffer + samplesRead * currentNumChannels, samplesToRead);
255+
input->readData (readBuffer + samplesRead, samplesToRead);
249256

250257
input->seekTo (startSample);
251258
currentSample = startSample;
252259
}
253260
else
254261
{
255-
input->readData (readBuffer + samplesRead * currentNumChannels, samplesToRead);
256-
262+
input->readData (readBuffer + samplesRead, samplesToRead);
257263
currentSample += samplesToRead;
258264
}
259-
265+
//std::cout<<"samplesRead: " << samplesRead << "\n";
266+
//std::cout<<"mod operation: " << count % iterationsPerSecond << "\n";
267+
if (count % iterationsPerSecond == 0){
268+
int *evntData= 0;
269+
TTLEventPtr event = TTLEvent::createTTLEvent(moduleEventChannels[0], getTimestamp(0),
270+
&evntData, sizeof(int), 0);
271+
//TTLEvent::createTTLEvent(<#const EventChannel *channelInfo#>, <#int64 timestamp#>, <#const void *eventData#>, <#int dataSize#>, <#uint16 channel#>)
272+
addEvent(moduleEventChannels[0], event, sample);
273+
//addEvent(<#int channelIndex#>, <#const Event *event#>, <#int sampleNum#>)
274+
}
275+
260276
samplesRead += samplesToRead;
261277
}
262278

263279
for (int i = 0; i < currentNumChannels; ++i)
264280
{
265281
input->processChannelData (readBuffer, buffer.getWritePointer (i, 0), i, samplesNeeded);
266282
}
267-
283+
268284
timestamp += samplesNeeded;
269285
setTimestampAndSamples(timestamp, samplesNeeded);
270286

@@ -309,3 +325,22 @@ int64 FileReader::millisecondsToSamples (unsigned int ms) const
309325
{
310326
return (int64) (currentSampleRate * float (ms) / 1000.f);
311327
}
328+
329+
void FileReader::createEventChannels(){
330+
331+
moduleEventChannels.clear();
332+
333+
const DataChannel* in = getDataChannel(0);
334+
EventChannel* ev = new EventChannel(EventChannel::TTL, 8, 1, (in) ? in->getSampleRate() : CoreServices::getGlobalSampleRate(), this);
335+
336+
ev->setName("regular file reader output ");
337+
ev->setDescription("Triggers about every second");
338+
String identifier = "secondly.reader.";
339+
String typeDesc = "secondly";
340+
ev->setIdentifier(identifier);
341+
//MetaDataDescriptor md(MetaDataDescriptor::CHAR, 34, "Phase Type", "Description of the phase condition", "channelInfo.extra");
342+
//MetaDataValue mv(md);
343+
//mv.setValue(typeDesc);
344+
eventChannelArray.add(ev);
345+
moduleEventChannels.add(ev);
346+
}

Source/Processors/FileReader/FileReader.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,12 @@ class FileReader : public GenericProcessor
6767

6868
bool isFileSupported (const String& filename) const;
6969
bool isFileExtensionSupported (const String& ext) const;
70-
70+
void createEventChannels();
7171

7272
private:
73+
Array<const EventChannel*> moduleEventChannels;
74+
unsigned int count = 0;
75+
7376
void setActiveRecording (int index);
7477

7578
unsigned int samplesToMilliseconds (int64 samples) const;

0 commit comments

Comments
 (0)