Permalink
Browse files

Fixed loop position setting/getting code for Music.

  • Loading branch information...
1 parent d172f26 commit cb7c0b77965b7254d3fe81a2a706eebf0f6d247c @finnkuusisto committed Aug 6, 2012
Showing with 15 additions and 5 deletions.
  1. +15 −5 src/kuusisto/tinysound/Music.java
  2. BIN tinysound.zip
@@ -144,26 +144,33 @@ public void setLoop(boolean loop) {
* @return loop position by sample frame
*/
public int getLoopPositionByFrame() {
+ int bytesPerChannelForFrame = TinySound.FORMAT.getFrameSize() /
+ TinySound.FORMAT.getChannels();
int byteIndex = this.reference.getLoopPosition();
- return (byteIndex / TinySound.FORMAT.getFrameSize());
+ return (int)(byteIndex / bytesPerChannelForFrame);
}
/**
* Get the loop position of this Music by seconds.
* @return loop position by seconds
*/
public double getLoopPositionBySeconds() {
+ int bytesPerChannelForFrame = TinySound.FORMAT.getFrameSize() /
+ TinySound.FORMAT.getChannels();
int byteIndex = this.reference.getLoopPosition();
- return (int)(byteIndex / (TinySound.FORMAT.getFrameRate() *
- TinySound.FORMAT.getFrameSize()));
+ return (byteIndex / (TinySound.FORMAT.getFrameRate() *
+ bytesPerChannelForFrame));
}
/**
* Set the loop position of this Music by sample frame.
* @param frameIndex sample frame loop position to set
*/
public void setLoopPositionByFrame(int frameIndex) {
- int byteIndex = frameIndex * TinySound.FORMAT.getFrameSize();
+ //get the byte index for a channel
+ int bytesPerChannelForFrame = TinySound.FORMAT.getFrameSize() /
+ TinySound.FORMAT.getChannels();
+ int byteIndex = (int)(frameIndex * bytesPerChannelForFrame);
this.reference.setLoopPosition(byteIndex);
}
@@ -172,8 +179,11 @@ public void setLoopPositionByFrame(int frameIndex) {
* @param seconds loop position to set by seconds
*/
public void setLoopPositionBySeconds(double seconds) {
+ //get the byte index for a channel
+ int bytesPerChannelForFrame = TinySound.FORMAT.getFrameSize() /
+ TinySound.FORMAT.getChannels();
int byteIndex = (int)(seconds * TinySound.FORMAT.getFrameRate() *
- TinySound.FORMAT.getFrameSize());
+ bytesPerChannelForFrame);
this.reference.setLoopPosition(byteIndex);
}
View
Binary file not shown.

0 comments on commit cb7c0b7

Please sign in to comment.