Skip to content

Commit ce1afbd

Browse files
committed
Fix AudioSample loop()
1 parent e6144e4 commit ce1afbd

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

Diff for: src/processing/sound/AudioSample.java

+12-15
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,14 @@ private boolean setStartTime(float time) {
262262
}
263263

264264
/**
265-
* Jump to a specific position in the audiosample while continuing to play (or starting to play if it wasn't playing already).
266-
*
267-
* @param time
268-
* position to jump to, in seconds.
265+
* Jump to a specific position in the audiosample while continuing to play (or
266+
* starting to play if it wasn't playing already).
267+
*
268+
* @param time position to jump to, in seconds
269269
* @see AudioSample#cue(float)
270270
* @see AudioSample#play()
271271
* @webref Sampling:AudioSample
272-
* @webBrief Jump to a specific position in the audiosample while continuing to play (or starting to play if it wasn't playing already).
272+
* @webBrief Jumps to a specific position in the audio sample.
273273
**/
274274
public void jump(float time) {
275275
// FIXME this currently only works for simply *playing* files, if the
@@ -327,27 +327,25 @@ private void setStartFrameCountOffset() {
327327
private void loopInternal(int startFrame, int numFrames, int numLoops) {
328328
// always use current sample player
329329
this.stop();
330+
super.play(); // adds the player
330331
this.setStartFrameCountOffset();
331332
this.startFrame = startFrame;
332333
QueueDataCommand cmd = this.player.dataQueue.createQueueDataCommand(this.sample, startFrame, numFrames);
333334
// TODO setAutoStop(true) ?
334-
// TODO setImmadiate(true) ?
335+
// TODO setImmediate(true) ?
335336
cmd.setCallback(new PlaybackFinishedCallback());
336337
// TODO how to loop indefinitely??
337-
if (numLoops > 1) {
338-
// how many times it's *repeated* after the first time
339-
cmd.setNumLoops(numLoops - 1);
340-
} else {
341-
// TODO this.player.dataQueue.queueLoop(this.sample, startFrame,
342-
// numFrames);
343-
}
338+
// how many times it's *repeated* after the first time
339+
// any negative number makes an infinite loop
340+
cmd.setNumLoops(numLoops - 1);
341+
// TODO this.player.dataQueue.queueLoop(this.sample, startFrame, numFrames);
344342
this.player.getSynthesizer().queueCommand(cmd);
345343
this.isPlayingAtLeastUntil = System.currentTimeMillis() + 50;
346344
this.isPlaying = true;
347345
}
348346

349347
private void loopInternal(int startFrame, int numFrames) {
350-
this.loopInternal(startFrame, numFrames, 0);
348+
this.loopInternal(startFrame, numFrames, -1);
351349
}
352350

353351
/*
@@ -440,7 +438,6 @@ public void finished(QueueDataEvent event) {
440438
stop();
441439
}
442440
public void looped(QueueDataEvent event) {
443-
System.out.println("loop");
444441
}
445442
public void started(QueueDataEvent event) {
446443
}

0 commit comments

Comments
 (0)