Skip to content

Commit

Permalink
Fix AudioSample loop()
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinstadler committed Sep 24, 2023
1 parent e6144e4 commit ce1afbd
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/processing/sound/AudioSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ private boolean setStartTime(float time) {
}

/**
* Jump to a specific position in the audiosample while continuing to play (or starting to play if it wasn't playing already).
*
* @param time
* position to jump to, in seconds.
* Jump to a specific position in the audiosample while continuing to play (or
* starting to play if it wasn't playing already).
*
* @param time position to jump to, in seconds
* @see AudioSample#cue(float)
* @see AudioSample#play()
* @webref Sampling:AudioSample
* @webBrief Jump to a specific position in the audiosample while continuing to play (or starting to play if it wasn't playing already).
* @webBrief Jumps to a specific position in the audio sample.
**/
public void jump(float time) {
// FIXME this currently only works for simply *playing* files, if the
Expand Down Expand Up @@ -327,27 +327,25 @@ private void setStartFrameCountOffset() {
private void loopInternal(int startFrame, int numFrames, int numLoops) {
// always use current sample player
this.stop();
super.play(); // adds the player
this.setStartFrameCountOffset();
this.startFrame = startFrame;
QueueDataCommand cmd = this.player.dataQueue.createQueueDataCommand(this.sample, startFrame, numFrames);
// TODO setAutoStop(true) ?
// TODO setImmadiate(true) ?
// TODO setImmediate(true) ?
cmd.setCallback(new PlaybackFinishedCallback());
// TODO how to loop indefinitely??
if (numLoops > 1) {
// how many times it's *repeated* after the first time
cmd.setNumLoops(numLoops - 1);
} else {
// TODO this.player.dataQueue.queueLoop(this.sample, startFrame,
// numFrames);
}
// how many times it's *repeated* after the first time
// any negative number makes an infinite loop
cmd.setNumLoops(numLoops - 1);
// TODO this.player.dataQueue.queueLoop(this.sample, startFrame, numFrames);
this.player.getSynthesizer().queueCommand(cmd);
this.isPlayingAtLeastUntil = System.currentTimeMillis() + 50;
this.isPlaying = true;
}

private void loopInternal(int startFrame, int numFrames) {
this.loopInternal(startFrame, numFrames, 0);
this.loopInternal(startFrame, numFrames, -1);
}

/*
Expand Down Expand Up @@ -440,7 +438,6 @@ public void finished(QueueDataEvent event) {
stop();
}
public void looped(QueueDataEvent event) {
System.out.println("loop");
}
public void started(QueueDataEvent event) {
}
Expand Down

0 comments on commit ce1afbd

Please sign in to comment.