1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874
|
/*
* Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
* UNIVERSITAT POMPEU FABRA
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "OnsetDetector.hxx"
#include "Point.hxx"
#include "OD_AudioDecimation.hxx"
#include "CLAM_Math.hxx"
#include <libresample.h>
namespace CLAM
{
OnsetDetector::OnsetDetector()
{
AttachChildren();
Configure(OnsetDetectorConfig());
}
OnsetDetector::OnsetDetector(OnsetDetectorConfig& c)
{
AttachChildren();
Configure(c);
}
bool OnsetDetector::ConcreteConfigure(const ProcessingConfig& c)
{
CopyAsConcreteConfig( mConfig, c );
mnBands = mConfig.GetnBands();
mLowFreq = mConfig.GetLowFreq();
mHighFreq = mConfig.GetHighFreq();
mBandThreshold = mConfig.GetBandThreshold();
mMinPeakDist = mConfig.GetMinPeakDist();
mGlobalThreshold = mConfig.GetGlobalThreshold();
mNoiseThreshold = mConfig.GetNoiseThreshold();
mComputeOffsets = mConfig.GetComputeOffsets();
mOffsetThreshold = mConfig.GetOffsetThreshold();
//Computes the smoothing filter coefficients
mWinSize = mConfig.GetSmoothFiltSize();
mWinCoef.Resize(mWinSize);
mWinCoef.SetSize(mWinSize);
double dPhi = ( 2.0 * M_PI ) / ( TData(mWinSize)*2.0 );
double phi = 0.0;
mWinCoefSummation = 0.0;
for(int i=0; i<mWinSize; i++, phi += dPhi )
{
mWinCoef[i]=0.5+0.5*std::cos(phi);
mWinCoefSummation += mWinCoef[i];
}
ConfigureChildren();
return true;
}
bool OnsetDetector::ConfigureChildren()
{
//Filter Bank Configuration
GT_FilterBankConfig bankcfg;
bankcfg.SetnChannels(mnBands);
bankcfg.SetLowFreq(mLowFreq);
bankcfg.SetHighFreq(mHighFreq);
bankcfg.SetSampleRate(22050);
mFilterBank.Configure(bankcfg);
return true;
}
void OnsetDetector::AttachChildren()
{
mFilterBank.SetParent(this);
}
bool OnsetDetector::Do(Segment &originalSegment, Array<TimeIndex>& out)
{
CLAM_ASSERT( int(originalSegment.GetAudio().GetSampleRate()) == 44100,
"This onset detection algorithm only works for signals sampled at a 44.1kHz rate" );
//Downsampling 1:2 factor
TSize originalAudioSize = originalSegment.GetAudio().GetSize();
TSize downAudioSize = (originalSegment.GetAudio().GetSize()/2);
mAudio.SetSize( downAudioSize + 1000 );
mAudio.SetSampleRate(originalSegment.GetAudio().GetSampleRate()/2);
void* handle = resample_open( 1, 0.5, 0.5 );
int srcused;
resample_process( handle, 0.5,
originalSegment.GetAudio().GetBuffer().GetPtr(),
originalAudioSize,
1, &srcused,
mAudio.GetBuffer().GetPtr(), downAudioSize+1000 );
resample_close( handle );
mAudio.SetSize( downAudioSize );
//Filter bank output computation
mFilterBankOutputs.Resize(mnBands);
mFilterBankOutputs.SetSize(mnBands);
CalcFilterBankOutput( );
mnSamples = mFilterBankOutputs[0].Size();
//Onset detection
Algorithm( originalSegment, out );
return true;
}
///////////////
//FILTER BANK//
///////////////
bool OnsetDetector::CalcFilterBankOutput()
{
//Filter Bank
const TSize bandSize=mAudio.GetSize();
for ( int band = 0; band < mnBands; band++ )
{
mFilterBankOutputs[band].Resize((bandSize/90) + 1000);
mFilterBankOutputs[band].SetSize(( bandSize/90) + 1000);
}
mFilterBank.Do( mAudio, mFilterBankOutputs );
mSampleRate = 245;
return true;
}
////////////////////////////////////////
////////SEGMENTATION ALGORITHM//////////
////////////////////////////////////////
void OnsetDetector::Algorithm( Segment& s , Array<TimeIndex>& finalOnsets )
{
Array< Array<float> > smoothedInput(mnBands); //Smoothed Band Energy Array
smoothedInput.SetSize(mnBands);
for ( int i = 0; i < mnBands; i++ )
{
smoothedInput[i].Resize( mnSamples );
smoothedInput[i].SetSize( mnSamples );
}
Array< Array<float> > bandOnsetDetectData(mnBands); //Data on which detection is performed
bandOnsetDetectData.SetSize(mnBands);
for ( int i = 0; i < mnBands; i++ )
{
bandOnsetDetectData[i].Resize( mnSamples );
bandOnsetDetectData[i].SetSize( mnSamples );
}
std::list< TimeIndex > candidates;
TimeIndex tempOnset;
Array< Array<TimeIndex> > bandOnsets(mnBands);
bandOnsets.SetSize(mnBands);
DataArray onsetsArray(mnSamples); //sum of cleaned onsets detected in each bands (Data)
onsetsArray.SetSize(mnSamples);
std::map< TIndex, double > onsetsDetected;
mRevSmoothedEnergy.Resize( mnSamples );
mRevSmoothedEnergy.SetSize( mnSamples );
//////////////////////////
//ONSET DETECTION PER BAND
for (int band=0 ; band<mnBands ; band++)
{
//smoothing
Smoothing( mFilterBankOutputs[band] , smoothedInput[band] );
//Detection Function Calculation
DetectPosition( smoothedInput[band] , bandOnsetDetectData[band]);
//Candidates Detection
DetectCandidates( bandOnsetDetectData[band] , smoothedInput[band], mBandThreshold , candidates);
//weak onsets deletion
RemoveTooNearOnsetsFromCandidatesList( candidates );
//sums up band results
for ( LI j = candidates.begin();
j != candidates.end();
j++ )
if ( onsetsDetected.find( (TIndex)j->GetPosition() ) != onsetsDetected.end() )
onsetsDetected[ (TIndex)j->GetPosition() ] += j->GetWeight();
else
onsetsDetected[ (TIndex)j->GetPosition() ] = j->GetWeight();
candidates.clear();
}
if ( onsetsDetected.empty() )
return;
TimeIndex tmp;
for ( MI i = onsetsDetected.begin(); i != onsetsDetected.end();
i++ )
{
tmp.SetPosition( i->first );
tmp.SetWeight( i->second );
candidates.push_back( tmp );
}
//weak onsets deletion (weak onsets intensities are summed up
//and added to the highest peak in a mMinPeakDist long window)
RemoveTooWeakOnsetsFromCandidatesList( candidates );
double maxWeight = 0.0;
LI i = candidates.begin();
while( i != candidates.end() )
{
if ( i->GetWeight() <= mGlobalThreshold )
{
i = candidates.erase( i );
continue;
}
if ( i->GetWeight() >= maxWeight )
maxWeight = i->GetWeight();
++i;
}
if ( candidates.empty() )
return;
if ( mComputeOffsets )
CheckOffset( s, candidates );
finalOnsets.Resize( candidates.size() );
finalOnsets.SetSize( candidates.size() );
int k = 0;
for ( LI i = candidates.begin();
i != candidates.end(); i++, k++ )
{
finalOnsets[k].SetPosition( i->GetPosition() / mSampleRate );
finalOnsets[k].SetWeight( i->GetWeight() / maxWeight );
}
}
void OnsetDetector::Smoothing(Array<float>& energy, Array<float>& smoothedEnergy )
{
int i, j, k;
double temp;
double inverseWCSum = 1.0 / mWinCoefSummation;
CLAM_ASSERT( mnSamples > mWinSize,
"OnsetDetector::Smoothing() : number of samples to process should be greater than mWinSize" );
//convolution
for ( i = 0; i < mWinSize; i++ )
{
temp = 0.0;
for ( j = -(i-mWinSize)-1; j < mWinSize; j++ )
temp+=energy[i-mWinSize+1+j]*mWinCoef[mWinSize-1-j];
const double normConv = temp * inverseWCSum;
smoothedEnergy[i] = ( normConv > mNoiseThreshold ) ? normConv : mNoiseThreshold;
mRevSmoothedEnergy[mnSamples-i-1]=smoothedEnergy[i];
}
for(; i<mnSamples;i++)
{
temp=0.0;
for(j = 0; j<mWinSize; j++)
temp+=energy[i-mWinSize+1+j]*mWinCoef[mWinSize-1-j];
const double normConv = temp * inverseWCSum;
smoothedEnergy[i] = ( normConv > mNoiseThreshold ) ? normConv : mNoiseThreshold;
mRevSmoothedEnergy[mnSamples-i-1]=smoothedEnergy[i];
}
//reverse convolution for zero-phase distortion
for ( i = 0; i < mWinSize; i++ )
{
temp=0.0;
for( j = -(i-mWinSize)-1; j<mWinSize; j++)
{
temp+=mRevSmoothedEnergy[i-mWinSize+1+j]*mWinCoef[mWinSize-1-j];
}
smoothedEnergy[mnSamples-i-1]=temp*inverseWCSum;
}
for(; i<mnSamples;i++)
{
temp=0.0;
for(j=0; j<mWinSize; j++)
{
temp+=mRevSmoothedEnergy[i-mWinSize+1+j]*mWinCoef[mWinSize-1-j];
}
smoothedEnergy[mnSamples-i-1]=temp*inverseWCSum;
}
}
void OnsetDetector::DetectPosition(Array<float>& in, Array<float>& ret)
{
int i;
//Sets first and last values to zero
ret[0] = 0.0;
ret[mnSamples-1] = 0.0;
// MRJ: Original computation was a loop from 1:mnSamples-1 where
// ret(i):=log(in[i+1])-log(in[i-1]).
// This simple trick reduces the overall number of log()'s to
// exactly mnSamples ( which is yet a lot of times ).
double a = log( in[0] );
double b = log( in[1] );
double c = log( in[2] );
ret[1] = c - a;
for (i=2; i<mnSamples-1; i++)
{
a = b; b = c; c = log( in[i+1] );
ret[i] = c - a;
}
}
////////////////////////////////
///////CANDIDATE DETECTION//////
////////////////////////////////
void OnsetDetector::DetectCandidates(Array<float>& in, Array<float>& weight,
TData threshold , std::list<TimeIndex>& ret)
{
//This function detect the positions and weights of candidates
//The highest peak in the derivative of the log smoothed energy is taken as the position
//(Instead, the position of the first peak or the highest peak in the derivative of the smoothed energy can be taken)
//The weigth is the derivative of the smoothed energy at this position
//(instead, the derivative of the log smoothed energy or the "dynamic" can be taken)
int i=1, maxLogPos, maxLinPos;
TData maxLog, maxLin;
TimeIndex candidate;
TSize maxPosition = in.Size() - 3;
//takes peaks above the threshold
while(i < maxPosition)
{
maxLog=maxLin=0;
if(in[i]>0 || in[i+1]>0 || in[i+2]>0 )
{
//while the derivative is positive (up to 2 negative values are allowed)
do
{
//store the position and the value of the highest peak in the detection function (derivative of
//the log smoothed energy)
if(in[i]>maxLog)
{
maxLog = in[i];
maxLogPos = i;
}
//store the position and the value of the highest peak in the derivative of
//the smoothed energy
double deltaEnergy = weight[i+1] - weight[i-1];
if(deltaEnergy > maxLin)
{
maxLin = deltaEnergy;
maxLinPos = i;
}
i++;
}
while(i < maxPosition && (in[i]>0 || in[i+1]>0 || in[i+2]>0));
if(maxLog>threshold)
{
candidate.SetPosition(maxLogPos);
candidate.SetWeight(maxLin);
ret.push_back( candidate );
}
}
else
i++;
}
}
void OnsetDetector::RemoveTooNearOnsetsFromCandidatesList( std::list<TimeIndex>& in )
{
TimeIndex newPeak;
typedef std::list<TimeIndex>::iterator LI;
LI theLastOne = in.end();
theLastOne--;
LI j = in.begin();
LI k, knext, lastToRemove;
while ( j != theLastOne )
{
k = j;
knext = k; knext++;
while( k != theLastOne
&& ( knext->GetPosition() - k->GetPosition() ) < mMinPeakDist )
{
knext++;
k++;
}
if ( j == k ) // No peaks were found to be "deleteable"
j++;
else
{
TimeIndex newPeak;
PeakDeletion( j, knext, newPeak );
*j = newPeak;
LI first = j; first++;
LI last = k;
if ( last != in.end() ) last++;
in.erase( first, last );
theLastOne = in.end();
theLastOne--;
}
}
}
void OnsetDetector::PeakDeletion( LI first, LI last, TimeIndex& newPeak )
{
double max = -1.0;
for ( LI i = first; i != last; i++ )
if ( i->GetWeight() > max )
{
max = i->GetWeight();
newPeak.SetPosition( i->GetPosition() );
newPeak.SetWeight( i->GetWeight() );
}
}
void OnsetDetector::RemoveTooWeakOnsetsFromCandidatesList( std::list<TimeIndex>& in )
{
TimeIndex newPeak;
typedef std::list<TimeIndex>::iterator LI;
LI theLastOne = in.end();
theLastOne--;
LI j = in.begin();
LI k, knext, lastToRemove;
while ( j != theLastOne )
{
k = j;
knext = k; knext++;
while( k != theLastOne
&& ( knext->GetPosition() - j->GetPosition() ) < mMinPeakDist )
{
knext++;
k++;
}
if ( j == k ) // No peaks were found to be "deleteable"
j++;
else
{
TimeIndex newPeak;
PeakSummation( j, knext, newPeak );
*j = newPeak;
LI first = j; first++;
LI last = k;
if ( last != in.end() ) last++;
in.erase( first, last );
theLastOne = in.end();
theLastOne--;
}
}
}
void OnsetDetector::PeakSummation( LI first, LI last, TimeIndex& newPeak )
{
double max = -1.0, sum = 0.0;
for ( LI i = first; i != last; i++ )
{
sum += i->GetWeight();
if ( i->GetWeight() > max )
{
max = i->GetWeight();
newPeak.SetPosition( i->GetPosition() );
}
}
newPeak.SetWeight( sum );
}
//PEAK DELETION
/////////////////////
//CHECK FOR OFFSETS//
/////////////////////
void OnsetDetector::DecimationForEnvelopeComputation( Array<float>& envelope )
{
TSize originalAudioSize = mAudio.GetSize();
TSize downAudioSize = mAudio.GetSize() / 90;
envelope.Resize( downAudioSize + 1000 );
envelope.SetSize( downAudioSize + 1000 );
DataArray& samples = mAudio.GetBuffer();
for ( int i = 0; i < originalAudioSize; i++ )
samples[i] = fabsf( samples[i] );
// Decimation
double factor = 245.0 / 22050.0;
void* handle = resample_open( 1, factor, factor );
int srcused;
resample_process( handle, factor,
samples.GetPtr(), originalAudioSize,
1, &srcused,
envelope.GetPtr(), downAudioSize+1000 );
resample_close( handle );
envelope.SetSize( downAudioSize );
}
void OnsetDetector::ComputeSmoothingFilterCoeffs( Array<float>& coeffs )
{
TSize winSize = TSize(0.05 * mSampleRate);
coeffs.Resize( winSize );
coeffs.SetSize( winSize );
for ( int i = 0; i < winSize; i++ )
coeffs[i] = 1.0;
}
void OnsetDetector::ExtractAudioEnvelope( Array<float>& envelope )
{
// Extraction of amplitude envelope
Array<float> amplitude;
DecimationForEnvelopeComputation( amplitude );
Array<float> winCoef;
ComputeSmoothingFilterCoeffs( winCoef );
// rescaling factor
double sum = winCoef.Size();
//convolution
envelope.Resize(amplitude.Size());
envelope.SetSize(amplitude.Size());
Array<float> revenvelope(amplitude.Size());
revenvelope.SetSize(amplitude.Size());
//convolution
double inverseWCSum = 1.0 / sum;
TSize ampSize = amplitude.Size();
double temp;
int j = 0;
int i = 0;
for ( i = 0; i < mWinSize; i++ )
{
temp = 0.0;
for ( j = -(i-mWinSize)-1; j < mWinSize; j++ )
temp+=amplitude[i-mWinSize+1+j]*mWinCoef[mWinSize-1-j];
envelope[i] = temp * inverseWCSum;
revenvelope[ampSize-i-1]=envelope[i];
}
for(; i<ampSize;i++)
{
temp=0.0;
for(j = 0; j<mWinSize; j++)
temp+=amplitude[i-mWinSize+1+j]*mWinCoef[mWinSize-1-j];
envelope[i] = temp * inverseWCSum;
revenvelope[ampSize-i-1]=envelope[i];
}
//reverse convolution for zero-phase distortion
for ( i = 0; i < mWinSize; i++ )
{
temp=0.0;
for( j = -(i-mWinSize)-1; j<mWinSize; j++)
{
temp+=revenvelope[i-mWinSize+1+j]*mWinCoef[mWinSize-1-j];
}
envelope[ampSize-i-1]=temp*inverseWCSum;
}
for(; i<ampSize;i++)
{
temp=0.0;
for(j=0; j<mWinSize; j++)
{
temp+=revenvelope[i-mWinSize+1+j]*mWinCoef[mWinSize-1-j];
}
envelope[ampSize-i-1]=temp*inverseWCSum;
}
}
void OnsetDetector::CheckOffset( Segment& s, std::list<TimeIndex>& candidates )
{
int i, j;
std::list< PointTmpl<int,int> > offsets;
typedef std::list< PointTmpl<int,int> >::iterator PLI;
Array<float> envelope;
ExtractAudioEnvelope( envelope );
// Actual Offset Checking
PointTmpl<int,int> temp;
double min = 0;
LI prev, next;
prev = candidates.begin();
next = prev;
next++;
for ( ; next != candidates.end() ; prev++, next++)
{
//onset position
i=int(next->GetPosition());
temp.SetX(int(prev->GetPosition()));
//looks for the first min before the onset
min = envelope[i];
do
{
if(envelope[i]<min)
min = envelope[i];
i--;
}
while (i>0 && envelope[i]>envelope[i-1]);
//finds the point (going backwards) where the amplitude rises above the threshold
if (min < mOffsetThreshold && i>0)
{
while (envelope[i] < mOffsetThreshold && i>prev->GetPosition())
i--;
if(i>prev->GetPosition())
{
temp.SetY(i);
offsets.push_back(temp);
}
}
}
//Checking for last offset
i=int(candidates.back().GetPosition());
temp.SetX(int(candidates.back().GetPosition()));
bool found=false;
do
{
if (envelope[i]< mOffsetThreshold
&& envelope[i]>envelope[i+1]
&& envelope[i+1]>envelope[i+2]
&& envelope[i+2]>envelope[i+3] )
{
temp.SetY(i);
offsets.push_back(temp);
found=true;
}
i++;
}
while(i<envelope.Size()-3 && !found);
// Onset/Offset information info
// A segment start is always an onset
// A segment end is either an offset ( if the amplitude goes below mOffsetThreshold )
// or the next onset
if ( candidates.empty() )
return;
bool hasOffset = false;
int offsetNumber = offsets.size();
PLI offsetIt = offsets.begin();
LI last = candidates.end();
last--;
for ( LI candidateIt = candidates.begin(); candidateIt != last; candidateIt++ )
{
Segment tmpSegment;
int onset = int(candidateIt->GetPosition());
if ( offsetIt != offsets.end() )
{
int offOnset = offsetIt->GetX();
if ( onset == offOnset )
hasOffset = true;
}
if ( hasOffset )
{
tmpSegment.SetBeginTime( (TTime)offsetIt->GetX()/(TTime)mSampleRate );
tmpSegment.SetEndTime( (TTime)offsetIt->GetY()/(TTime)mSampleRate );
tmpSegment.SetpParent( &s );
s.GetChildren().AddElem( tmpSegment );
offsetIt++;
candidateIt++;
hasOffset = false;
}
else
{
tmpSegment.SetBeginTime( (TTime)candidateIt->GetPosition()/ (TTime) mSampleRate );
LI nextCandidateIt = candidateIt;
nextCandidateIt++;
tmpSegment.SetEndTime( (TTime)nextCandidateIt->GetPosition() / (TTime) mSampleRate );
tmpSegment.SetpParent( &s );
s.GetChildren().AddElem( tmpSegment );
}
}
// Last boundaries
Segment tmpSegment;
int onset = int(candidates.back().GetPosition());
if ( offsetIt != offsets.end() )
{
int offOnset = offsetIt->GetX();
if ( onset == offOnset )
hasOffset = true;
}
if (hasOffset)
{
tmpSegment.SetBeginTime((TTime)offsetIt->GetX()/(TTime)mSampleRate);
tmpSegment.SetEndTime((TTime)offsetIt->GetY()/(TTime)mSampleRate);
tmpSegment.SetpParent(&s);
s.GetChildren().AddElem(tmpSegment);
}
else
{
tmpSegment.SetBeginTime((TTime)candidates.back().GetPosition() / (TTime)mSampleRate);
tmpSegment.SetEndTime(s.GetEndTime());
tmpSegment.SetpParent(&s);
s.GetChildren().AddElem(tmpSegment);
}
}
}
|