Skip to content

Commit

Permalink
Merge pull request #88 from ninjadev/fix-step-offset
Browse files Browse the repository at this point in the history
Repair stepOffset in sync.flash
  • Loading branch information
aleksanb authored Apr 8, 2023
2 parents 4ad8e74 + 4a21b56 commit 2d62953
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion renin/src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ export class Sync {
this.music = music;
}

/**
* Outputs a number between 0 and 1, signifying the progress between two "flashes", synced to the music.
* "stepStride" denotes the number of steps (subdivisions of a beat) between each flash
* "stepOffset" offsets the flashes from the start of a beat.
*/
flash(frame: number, stepStride: number, stepOffset: number = 0) {
const step = this.stepForFrame(frame);
const startStep = (((step - stepOffset) / stepStride) | 0) * stepStride;
const startStep = (((step - stepOffset) / stepStride) | 0) * stepStride + stepOffset;
const startFrame = this.frameForStep(startStep);
const endFrame = this.frameForStep(startStep + stepStride);
return (frame - startFrame) / (endFrame - startFrame);
Expand Down

0 comments on commit 2d62953

Please sign in to comment.