protected void fitIntoLoops ( final ChannelMemory actMemo ) { final Sample ins = actMemo . currentSample ; // If Forward direction: if ( actMemo . currentDirection >= 0 ) { actMemo . currentTuningPos += actMemo . currentTuning ; if ( actMemo . currentTuningPos >= Helpers . SHIFT_ONE ) { actMemo . currentSamplePos += ( actMemo . currentTuningPos >> Helpers . SHIFT ) ; actMemo . currentTuningPos &= Helpers . SHIFT_MASK ; if ( ( ins . loopType & Helpers . LOOP_ON ) == 0 ) // NoLoop { actMemo . instrumentFinished = actMemo . currentSamplePos >= ins . length ; } else // loop is On { if ( ( ins . loopType & Helpers . LOOP_IS_PINGPONG ) == 0 ) // No Ping Pong { if ( actMemo . currentSamplePos >= ins . repeatStop ) actMemo . currentSamplePos = ins . repeatStart + ( ( actMemo . currentSamplePos - ins . repeatStart ) % ins . repeatLength ) ; } else // is PingPong { if ( actMemo . currentSamplePos >= ins . repeatStop ) { actMemo . currentDirection = - 1 ; actMemo . currentSamplePos = ins . repeatStop - ( ( actMemo . currentSamplePos - ins . repeatStart ) % ins . repeatLength ) - 1 ; } } } } } else // Loop is on and we have ping pong! { actMemo . currentTuningPos -= actMemo . currentTuning ; if ( actMemo . currentTuningPos <= 0 ) { int hi = ( ( - actMemo . currentTuningPos ) >> Helpers . SHIFT ) + 1 ; actMemo . currentSamplePos -= hi ; actMemo . currentTuningPos += hi << Helpers . SHIFT ; if ( actMemo . currentSamplePos <= ins . repeatStart ) { actMemo . currentDirection = 1 ; actMemo . currentSamplePos = ins . repeatStart + ( ( ins . repeatStart - actMemo . currentSamplePos ) % ins . repeatLength ) ; } } } }
Add current speed to samplepos and fit currentSamplePos into loop values or signal Sample finished