31 class SegmentBoundaries
36 SegmentBoundaries(
int size):mArray(size)
54 myStream <<
"SpectralMean";
59 myStream <<
"SpectralGeometricMean";
64 myStream <<
"SpectralEnergy";
69 myStream <<
"SpectralCentroid";
74 myStream <<
"SpectralMoment2";
79 myStream <<
"SpectralMoment3";
84 myStream <<
"SpectralMoment4";
89 myStream <<
"SpectralMoment5";
94 myStream <<
"SpectralMoment6";
99 myStream <<
"SpectralFlatness";
104 myStream <<
"SpectralKurtosis";
109 myStream <<
"Fundamental";
114 myStream <<
"UnknownDescriptor";
118 myStream <<
"threshold=";
121 myStream <<
"percentil=";
128 CLAM_ASSERT(
false,
"TDescriptorParams extractor operator is not implemented");
136 AddDescriptorsParams();
137 AddMinSegmentLength();
140 SetDescriptorsParams(tmpArray);
145 SetMinSegmentLength(0);
151 if(GetDescriptorsParams().Size()==0)
152 GetDescriptorsParams().AddElem(descParams);
155 if(descParams<GetDescriptorsParams()[0])
156 GetDescriptorsParams().InsertElem(0,descParams);
158 GetDescriptorsParams().AddElem(descParams);
161 GetDescriptorsParams().InsertElem(position,descParams);
170 descParams.
percentil=GetDescriptorsParams()[pos].percentil;
171 descParams.
threshold=GetDescriptorsParams()[pos].threshold;
178 GetDescriptorsParams().Init();
209 CLAM_ASSERT(
false,
"Segmentator: Do(): Supervised mode not implemented");
218 Matrix descriptorsValues(
mConfig.GetDescriptorsParams().Size(),nFrames);
220 Algorithm(originalSegment,descriptorsValues);
228 int nDescriptors=
mConfig.GetDescriptorsParams().Size();
229 for(
int i=0;i<nFrames;i++)
236 value=descriptors.
GetFrameD(i).GetSpectrumD().GetMean();
237 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
238 descriptorsValues.
SetAt(z,i,value);
239 else descriptorsValues.
SetAt(z,i,0);
244 value=descriptors.
GetFrameD(i).GetSpectrumD().GetGeometricMean();
245 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
246 descriptorsValues.
SetAt(z,i,value);
247 else descriptorsValues.
SetAt(z,i,0);
252 value=descriptors.
GetFrameD(i).GetSpectrumD().GetEnergy();
253 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
254 descriptorsValues.
SetAt(z,i,value);
255 else descriptorsValues.
SetAt(z,i,0);
260 value=descriptors.
GetFrameD(i).GetSpectrumD().GetCentroid();
261 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
262 descriptorsValues.
SetAt(z,i,value);
263 else descriptorsValues.
SetAt(z,i,0);
268 value=descriptors.
GetFrameD(i).GetSpectrumD().GetMoment2();
269 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
270 descriptorsValues.
SetAt(z,i,value);
271 else descriptorsValues.
SetAt(z,i,0);
276 value=descriptors.
GetFrameD(i).GetSpectrumD().GetMoment3();
277 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
278 descriptorsValues.
SetAt(z,i,value);
279 else descriptorsValues.
SetAt(z,i,0);
284 value=descriptors.
GetFrameD(i).GetSpectrumD().GetMoment4();
285 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
286 descriptorsValues.
SetAt(z,i,value);
287 else descriptorsValues.
SetAt(z,i,0);
292 value=descriptors.
GetFrameD(i).GetSpectrumD().GetMoment5();
293 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
294 descriptorsValues.
SetAt(z,i,value);
295 else descriptorsValues.
SetAt(z,i,0);
300 value=descriptors.
GetFrameD(i).GetSpectrumD().GetMoment6();
301 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
302 descriptorsValues.
SetAt(z,i,value);
303 else descriptorsValues.
SetAt(z,i,0);
308 value=descriptors.
GetFrameD(i).GetSpectrumD().GetFlatness();
309 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
310 descriptorsValues.
SetAt(z,i,value);
311 else descriptorsValues.
SetAt(z,i,0);
316 value=descriptors.
GetFrameD(i).GetSpectrumD().GetMagnitudeKurtosis();
317 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
318 descriptorsValues.
SetAt(z,i,value);
319 else descriptorsValues.
SetAt(z,i,0);
324 value=originalSegment.
GetFrame(i).GetFundamental().GetFreq();
325 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
326 descriptorsValues.
SetAt(z,i,value);
327 else descriptorsValues.
SetAt(z,i,0);
332 value=descriptors.
GetFrameD(i).GetAudioFrameD().GetEnergy();
333 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
334 descriptorsValues.
SetAt(z,i,value);
335 else descriptorsValues.
SetAt(z,i,0);
340 value=descriptors.
GetFrameD(i).GetAudioFrameD().GetVariance();
341 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
342 descriptorsValues.
SetAt(z,i,value);
343 else descriptorsValues.
SetAt(z,i,0);
348 value=descriptors.
GetFrameD(i).GetAudioFrameD().GetTemporalCentroid();
349 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
350 descriptorsValues.
SetAt(z,i,value);
351 else descriptorsValues.
SetAt(z,i,0);
356 value=descriptors.
GetFrameD(i).GetAudioFrameD().GetZeroCrossingRate();
357 if(value>
mConfig.GetDescriptorsParams()[z].threshold)
358 descriptorsValues.
SetAt(z,i,value);
359 else descriptorsValues.
SetAt(z,i,0);
374 int nDescriptors=
mConfig.GetDescriptorsParams().Size();
375 SegmentBoundaries segmentBoundaries(nDescriptors);
377 segmentBoundaries.mArray.SetSize(nDescriptors);
379 for (
int z=0;z<nDescriptors;z++)
383 for (
int i=0; i<nFrames-4; i++)
385 for (
int z=0;z<nDescriptors;z++)
394 const TData relevance = fabs((x3-x2)/x2);
395 const TData & ratio =
mConfig.GetDescriptorsParams()[z].percentil/100;
398 if ((x3/x2)>(1+ratio) ||
408 if (( x3>x2 && x2>x1 && x1>x0 )||
409 ( x3<x2 && x2<x1 && x1<x0 ))
412 segmentBoundaries.mArray[z].AddElem(tmpValue);
414 else if((x3/x2)>(1+2*ratio)||
418 segmentBoundaries.mArray[z].AddElem(tmpValue);
452 DataFusion(s,segmentBoundaries);
455 void Segmentator::DataFusion(
Segment& s,
const SegmentBoundaries& segmentBoundaries)
461 const int nDescriptors=
mConfig.GetDescriptorsParams().Size();
463 TData sampleRate=s.GetSamplingRate();
466 Matrix probabilityMatrix(nFrames,nDescriptors);
467 memset(probabilityMatrix.GetBuffer().GetPtr(),0,nFrames*nDescriptors*
sizeof(
TData));
470 for (
int z=0;z<nDescriptors;z++)
472 for (
int n=0;n<segmentBoundaries.mArray[z].Size();n++)
473 probabilityMatrix.SetAt(segmentBoundaries.mArray[z][n].GetX(),z,segmentBoundaries.mArray[z][n].GetY());
478 for (
int n=0; n<nFrames; n++)
481 for(
int z=0;z<nDescriptors;z++)
483 tmpProb+=probabilityMatrix.GetAt(n,z);
495 while(globalProb[n]<=0)
497 TData mag=globalProb[n];
498 TData gcenter=n*globalProb[n];
500 for (
int m=n+1; m<globalProb.Size(); m++)
502 if (globalProb[m]<=0)
continue;
503 if ((m-n)>
mConfig.GetMinSegmentLength())
506 prob_fusion[(
int)(gcenter/mag)]=mag;
511 gcenter+=m*globalProb[m];
518 for (
int n=0; n<prob_fusion.Size(); n++)
519 if (prob_fusion[n]>max)
521 for (
int n=0; n<prob_fusion.Size(); n++)
523 if (prob_fusion[n]<=(max/100))
527 for (
int n=0; n<prob_fusion.Size(); n++)
529 if (prob_fusion[n]>0)
530 finalSegments.
AddElem(n*duration*sampleRate);
535 if (finalSegments.
Size()<=0)
return;
537 for (
int n=0; n<(finalSegments.
Size()-1); n++)
540 tmpSegment.SetBeginTime(finalSegments[n] /sampleRate);
541 tmpSegment.SetEndTime (finalSegments[n+1]/sampleRate);
544 s.GetChildren().AddElem(tmpSegment);
548 tmpSegment.SetBeginTime(finalSegments[finalSegments.
Size()-1] /sampleRate);
549 tmpSegment.SetEndTime(s.GetAudio().GetEndTime());
551 s.GetChildren().AddElem(tmpSegment);