Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed loop position setting/getting code for Music.

  • Loading branch information...
commit cb7c0b77965b7254d3fe81a2a706eebf0f6d247c 1 parent d172f26
Finn Kuusisto authored August 05, 2012
20  src/kuusisto/tinysound/Music.java
@@ -144,8 +144,10 @@ public void setLoop(boolean loop) {
144 144
 	 * @return loop position by sample frame
145 145
 	 */
146 146
 	public int getLoopPositionByFrame() {
  147
+		int bytesPerChannelForFrame = TinySound.FORMAT.getFrameSize() /
  148
+			TinySound.FORMAT.getChannels();
147 149
 		int byteIndex = this.reference.getLoopPosition();
148  
-		return (byteIndex / TinySound.FORMAT.getFrameSize());
  150
+		return (int)(byteIndex / bytesPerChannelForFrame);
149 151
 	}
150 152
 	
151 153
 	/**
@@ -153,9 +155,11 @@ public int getLoopPositionByFrame() {
153 155
 	 * @return loop position by seconds
154 156
 	 */
155 157
 	public double getLoopPositionBySeconds() {
  158
+		int bytesPerChannelForFrame = TinySound.FORMAT.getFrameSize() /
  159
+			TinySound.FORMAT.getChannels();
156 160
 		int byteIndex = this.reference.getLoopPosition();
157  
-		return (int)(byteIndex / (TinySound.FORMAT.getFrameRate() *
158  
-				TinySound.FORMAT.getFrameSize()));
  161
+		return (byteIndex / (TinySound.FORMAT.getFrameRate() *
  162
+				bytesPerChannelForFrame));
159 163
 	}
160 164
 	
161 165
 	/**
@@ -163,7 +167,10 @@ public double getLoopPositionBySeconds() {
163 167
 	 * @param frameIndex sample frame loop position to set
164 168
 	 */
165 169
 	public void setLoopPositionByFrame(int frameIndex) {
166  
-		int byteIndex = frameIndex * TinySound.FORMAT.getFrameSize();
  170
+		//get the byte index for a channel
  171
+		int bytesPerChannelForFrame = TinySound.FORMAT.getFrameSize() /
  172
+			TinySound.FORMAT.getChannels();
  173
+		int byteIndex = (int)(frameIndex * bytesPerChannelForFrame);
167 174
 		this.reference.setLoopPosition(byteIndex);
168 175
 	}
169 176
 	
@@ -172,8 +179,11 @@ public void setLoopPositionByFrame(int frameIndex) {
172 179
 	 * @param seconds loop position to set by seconds
173 180
 	 */
174 181
 	public void setLoopPositionBySeconds(double seconds) {
  182
+		//get the byte index for a channel
  183
+		int bytesPerChannelForFrame = TinySound.FORMAT.getFrameSize() /
  184
+			TinySound.FORMAT.getChannels();
175 185
 		int byteIndex = (int)(seconds * TinySound.FORMAT.getFrameRate() *
176  
-			TinySound.FORMAT.getFrameSize());
  186
+			bytesPerChannelForFrame);
177 187
 		this.reference.setLoopPosition(byteIndex);
178 188
 	}
179 189
 	
BIN  tinysound.zip
Binary file not shown

0 notes on commit cb7c0b7

Please sign in to comment.
Something went wrong with that request. Please try again.