comparison Tempogram.cpp @ 2:1d0b7dcea27f

Added manual setting of timestamps as wasn't working on both test machines.
author Carl Bussey <c.bussey@se10.qmul.ac.uk>
date Wed, 09 Jul 2014 14:32:32 +0100
parents 3fd1a41b089b
children 5125d34fda67
comparison
equal deleted inserted replaced
1:3fd1a41b089b 2:1d0b7dcea27f
238 d_sampleRate = m_inputSampleRate/m_stepSize; 238 d_sampleRate = m_inputSampleRate/m_stepSize;
239 d.sampleRate = d_sampleRate > 0 && !isnan(d_sampleRate) ? d_sampleRate : 0.0; 239 d.sampleRate = d_sampleRate > 0 && !isnan(d_sampleRate) ? d_sampleRate : 0.0;
240 d.hasDuration = false; 240 d.hasDuration = false;
241 list.push_back(d); 241 list.push_back(d);
242 242
243 d.identifier = "spect";
244 d.name = "spect";
245 d.description = "spect";
246 d.unit = "";
247 d.hasFixedBinCount = true;
248 d.binCount = m_blockSize/2;
249 d.hasKnownExtents = false;
250 d.isQuantized = false;
251 d.sampleType = OutputDescriptor::OneSamplePerStep;
252 d.hasDuration = false;
253 list.push_back(d);
254
243 return list; 255 return list;
244 } 256 }
245 257
246 bool 258 bool
247 Tempogram::initialise(size_t channels, size_t stepSize, size_t blockSize) 259 Tempogram::initialise(size_t channels, size_t stepSize, size_t blockSize)
272 FeatureSet featureSet; 284 FeatureSet featureSet;
273 Feature feature; 285 Feature feature;
274 286
275 const float *in = inputBuffers[0]; 287 const float *in = inputBuffers[0];
276 288
277 //Calculate log magnitude
278 float sum = 0; 289 float sum = 0;
279 for (int i = 0; i < n; i++){ 290 for (int i = 0; i < n; i++){
280 float magnitude = sqrt(in[2*i] * in[2*i] + in[2*i + 1] * in[2*i + 1]); 291 float magnitude = sqrt(in[2*i] * in[2*i] + in[2*i + 1] * in[2*i + 1]);
281 currentY[i] = log(1+compressionConstant*magnitude); //should be 1+C*magnitude 292 feature.values.push_back(magnitude);
293 currentY[i] = log(1+compressionConstant*magnitude);
282 if(currentY[i] >= previousY[i]){ 294 if(currentY[i] >= previousY[i]){
283 sum += (currentY[i] - previousY[i]); 295 sum += (currentY[i] - previousY[i]);
284 } 296 }
285 } 297 }
286 298
287 noveltyCurve.push_back(sum); 299 noveltyCurve.push_back(sum);
288 300
289 float *tmpY = currentY; 301 float *tmpY = currentY;
290 currentY = previousY; 302 currentY = previousY;
291 previousY = tmpY; 303 previousY = tmpY;
304 tmpY = NULL;
292 305
293 ncTimestamps.push_back(timestamp); 306 ncTimestamps.push_back(timestamp);
294 307 featureSet[2].push_back(feature);
295 return FeatureSet(); 308
309 return featureSet;
296 } 310 }
297 311
298 void 312 void
299 Tempogram::initialiseForGRF(){ 313 Tempogram::initialiseForGRF(){
300 hannN = 129; 314 hannN = 129;
337 351
338 for(int i = 0; i < ncLength; i++){ 352 for(int i = 0; i < ncLength; i++){
339 noveltyCurve[i] -= noveltyCurveLocalAverage[i]; 353 noveltyCurve[i] -= noveltyCurveLocalAverage[i];
340 noveltyCurve[i] = noveltyCurve[i] >= 0 ? noveltyCurve[i] : 0; 354 noveltyCurve[i] = noveltyCurve[i] >= 0 ? noveltyCurve[i] : 0;
341 Feature ncFeature; 355 Feature ncFeature;
356 ncFeature.hasTimestamp = true;
357 ncFeature.timestamp = ncTimestamps[i];
342 ncFeature.values.push_back(noveltyCurve[i]); 358 ncFeature.values.push_back(noveltyCurve[i]);
343 featureSet[1].push_back(ncFeature); 359 featureSet[1].push_back(ncFeature);
344 } 360 }
345 361
362 WindowFunction::hanning(hannWindowtN, tN);
363
364 int timestampInc = floor((((float)ncTimestamps[1].nsec - ncTimestamps[0].nsec)/1e9)*(thopSize) + 0.5);
346 int i=0; 365 int i=0;
347 WindowFunction::hanning(hannWindowtN, tN);
348
349 int index; 366 int index;
350 int frameBeginOffset = floor(tN/2 + 0.5); 367 int frameBeginOffset = floor(tN/2 + 0.5);
351 int timestampInc = floor((((float)ncTimestamps[1].nsec - ncTimestamps[0].nsec)/1e9)*(thopSize) + 0.5);
352 //cout << timestampInc << endl;
353 368
354 while(i < ncLength){ 369 while(i < ncLength){
355 Feature feature; 370 Feature feature;
356 371
357 for (int n = frameBeginOffset; n < tN; n++){ 372 for (int n = frameBeginOffset; n < tN; n++){