Browse Source

bugfix for sound looping when incorrect sampleCount extracted

Nicolas Cannasse 11 years ago
parent
commit
b757e545a1
1 changed files with 4 additions and 5 deletions
  1. 4 5
      hxd/res/Sound.hx

+ 4 - 5
hxd/res/Sound.hx

@@ -88,20 +88,19 @@ class Sound extends Resource {
 	function onMp3Sample(e:flash.events.SampleDataEvent) {
 	function onMp3Sample(e:flash.events.SampleDataEvent) {
 		var out = e.data;
 		var out = e.data;
 		out.position = 0;
 		out.position = 0;
-		var size = BUFFER_SIZE;
+
 		var MAGIC_DELAY = 2257;
 		var MAGIC_DELAY = 2257;
 		var position = bytesPosition;
 		var position = bytesPosition;
-		while( size > 0 ) {
+		while( true ) {
+			var size = BUFFER_SIZE - (out.position >> 3);
+			if( size == 0 ) break;
 			if( position + size >= mp3SampleCount ) {
 			if( position + size >= mp3SampleCount ) {
 				var read = mp3SampleCount - position;
 				var read = mp3SampleCount - position;
 				mp3Data.extract(out, read, position + MAGIC_DELAY);
 				mp3Data.extract(out, read, position + MAGIC_DELAY);
 				position = 0;
 				position = 0;
-				size -= read;
-				//onEnd();
 			} else {
 			} else {
 				mp3Data.extract(out, size, position + MAGIC_DELAY);
 				mp3Data.extract(out, size, position + MAGIC_DELAY);
 				position += size;
 				position += size;
-				size = 0;
 			}
 			}
 		}
 		}
 		bytesPosition = position;
 		bytesPosition = position;