@@ -47,10 +47,12 @@ String HDF5Recording::getEngineID()
4747// this->timestamp = timestamp;
4848// }
4949
50- void HDF5Recording::registerProcessor (GenericProcessor* proc)
50+ void HDF5Recording::registerProcessor (const GenericProcessor* proc)
5151{
5252 HDF5RecordingInfo* info = new HDF5RecordingInfo ();
53- info->sample_rate = proc->getSampleRate ();
53+ // This is a VERY BAD thig to do. temporary only until we fix const-correctness on GenericEditor methods
54+ // (which implies modifying all the plugins and processors)
55+ info->sample_rate = const_cast <GenericProcessor*>(proc)->getSampleRate ();
5456 info->bit_depth = 16 ;
5557 info->multiSample = false ;
5658 infoArray.add (info);
@@ -70,11 +72,12 @@ void HDF5Recording::resetChannels()
7072 sampleRatesArray.clear ();
7173 processorMap.clear ();
7274 infoArray.clear ();
75+ recordedChanToKWDChan.clear ();
7376 if (spikesFile)
7477 spikesFile->resetChannels ();
7578}
7679
77- void HDF5Recording::addChannel (int index, Channel* chan)
80+ void HDF5Recording::addChannel (int index,const Channel* chan)
7881{
7982 processorMap.add (processorIndex);
8083}
@@ -94,15 +97,40 @@ void HDF5Recording::openFiles(File rootFolder, int experimentNumber, int recordi
9497 // Let's just put the first processor (usually the source node) on the KWIK for now
9598 infoArray[0 ]->name = String (" Open Ephys Recording #" ) + String (recordingNumber);
9699
97- if (hasAcquired)
100+ /* if (hasAcquired)
98101 infoArray[0]->start_time = (*timestamps)[getChannel(0)->sourceNodeId]; //(*timestamps).begin()->first;
99102 else
100- infoArray[0 ]->start_time = 0 ;
103+ infoArray[0]->start_time = 0;*/
104+ infoArray[0 ]->start_time = getTimestamp (0 );
101105
102106 infoArray[0 ]->start_sample = 0 ;
103107 eventFile->startNewRecording (recordingNumber,infoArray[0 ]);
104108
105109 // KWD files
110+ recordedChanToKWDChan.clear ();
111+ Array<int > processorRecPos;
112+ processorRecPos.insertMultiple (0 , 0 , fileArray.size ());
113+ for (int i = 0 ; i < getNumRecordedChannels (); i++)
114+ {
115+ int index = processorMap[getRealChannel (i)];
116+ if (!fileArray[index]->isOpen ())
117+ {
118+ fileArray[index]->initFile (getChannel (getRealChannel (i))->nodeId , basepath);
119+ infoArray[index]->start_time = getTimestamp (i);
120+ }
121+
122+ channelsPerProcessor.set (index, channelsPerProcessor[index] + 1 );
123+ bitVoltsArray[index]->add (getChannel (getRealChannel (i))->bitVolts );
124+ sampleRatesArray[index]->add (getChannel (getRealChannel (i))->sampleRate );
125+ if (getChannel (getRealChannel (i))->sampleRate != infoArray[index]->sample_rate )
126+ {
127+ infoArray[index]->multiSample = true ;
128+ }
129+ int procPos = processorRecPos[index];
130+ recordedChanToKWDChan.add (procPos);
131+ processorRecPos.set (index, procPos+1 );
132+ }
133+ #if 0
106134 for (int i = 0; i < processorMap.size(); i++)
107135 {
108136 int index = processorMap[i];
@@ -125,6 +153,7 @@ void HDF5Recording::openFiles(File rootFolder, int experimentNumber, int recordi
125153 }
126154 }
127155 }
156+ #endif
128157 for (int i = 0 ; i < fileArray.size (); i++)
129158 {
130159 if ((!fileArray[i]->isOpen ()) && (fileArray[i]->isReadyToOpen ()))
@@ -169,42 +198,32 @@ void HDF5Recording::closeFiles()
169198 }
170199}
171200
172- void HDF5Recording::writeData (AudioSampleBuffer& buffer)
201+ void HDF5Recording::writeData (int writeChannel, int realChannel, const float * buffer, int size )
173202{
174203// int64 t1 = Time::getHighResolutionTicks();
175- for (int i = 0 ; i < buffer.getNumChannels (); i++)
176- {
177- if (getChannel (i)->getRecordState ())
178- {
179-
180- int sourceNodeId = getChannel (i)->sourceNodeId ;
181- int nSamples = (*numSamples)[sourceNodeId];
182-
183- double multFactor = 1 /(float (0x7fff ) * getChannel (i)->bitVolts );
184- int index = processorMap[getChannel (i)->recordIndex ];
185- FloatVectorOperations::copyWithMultiply (scaledBuffer,buffer.getReadPointer (i,0 ),multFactor,nSamples);
186- AudioDataConverters::convertFloatToInt16LE (scaledBuffer,intBuffer,nSamples);
187- fileArray[index]->writeRowData (intBuffer,nSamples);
188- }
189- }
204+ double multFactor = 1 / (float (0x7fff ) * getChannel (realChannel)->bitVolts );
205+ int index = processorMap[getChannel (realChannel)->recordIndex ];
206+ FloatVectorOperations::copyWithMultiply (scaledBuffer, buffer, multFactor, size);
207+ AudioDataConverters::convertFloatToInt16LE (scaledBuffer, intBuffer, size);
208+ fileArray[index]->writeRowData (intBuffer, size, recordedChanToKWDChan[writeChannel]);
190209// int64 t2 = Time::getHighResolutionTicks();
191210// std::cout << "record time: " << float(t2 - t1) / float(Time::getHighResolutionTicksPerSecond()) << std::endl;
192211}
193212
194- void HDF5Recording::writeEvent (int eventType, MidiMessage& event, int samplePosition )
213+ void HDF5Recording::writeEvent (int eventType, const MidiMessage& event, int64 timestamp )
195214{
196215 const uint8* dataptr = event.getRawData ();
197216 if (eventType == GenericProcessor::TTL)
198- eventFile->writeEvent (0 ,*(dataptr+2 ),*(dataptr+1 ),(void *)(dataptr+3 ),(*timestamps)[*(dataptr+ 1 )]+samplePosition );
217+ eventFile->writeEvent (0 ,*(dataptr+2 ),*(dataptr+1 ),(void *)(dataptr+3 ),timestamp );
199218 else if (eventType == GenericProcessor::MESSAGE)
200- eventFile->writeEvent (1 ,*(dataptr+2 ),*(dataptr+1 ),(void *)(dataptr+6 ),(*timestamps)[*(dataptr+ 1 )]+samplePosition );
219+ eventFile->writeEvent (1 ,*(dataptr+2 ),*(dataptr+1 ),(void *)(dataptr+6 ),timestamp );
201220}
202221
203- void HDF5Recording::addSpikeElectrode (int index, SpikeRecordInfo* elec)
222+ void HDF5Recording::addSpikeElectrode (int index, const SpikeRecordInfo* elec)
204223{
205224 spikesFile->addChannelGroup (elec->numChannels );
206225}
207- void HDF5Recording::writeSpike (const SpikeObject& spike, int electrodeIndex )
226+ void HDF5Recording::writeSpike (int electrodeIndex, const SpikeObject& spike, int64 /* timestamp */ )
208227{
209228 spikesFile->writeSpike (electrodeIndex,spike.nSamples ,spike.data ,spike.timestamp );
210229}
0 commit comments