@@ -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
231237void 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+ }
0 commit comments