瀏覽代碼

Fixed wav loader crashing with odd length sample data.

Mark Sibly 7 年之前
父節點
當前提交
82094b5604
共有 1 個文件被更改,包括 8 次插入9 次删除
  1. 8 9
      modules/std/audio/load_wav.monkey2

+ 8 - 9
modules/std/audio/load_wav.monkey2

@@ -8,22 +8,18 @@ Private
 Using std.stream
 Using std.stream
 
 
 Struct WAV_Header
 Struct WAV_Header
-	'
 	Field RIFF:Int
 	Field RIFF:Int
 	Field len:Int
 	Field len:Int
 	Field WAVE:Int
 	Field WAVE:Int
-	'
 End
 End
 
 
 Struct FMT_Chunk
 Struct FMT_Chunk
-	
 	Field compType:Short
 	Field compType:Short
 	Field numChannels:Short
 	Field numChannels:Short
 	Field samplesPerSec:Int
 	Field samplesPerSec:Int
 	Field avgBytesPerSec:Int
 	Field avgBytesPerSec:Int
 	Field blockalignment:Short
 	Field blockalignment:Short
 	Field bitsPerSample:Short
 	Field bitsPerSample:Short
-	
 End
 End
 
 
 Function ReadWAV:AudioData( stream:std.stream.Stream )
 Function ReadWAV:AudioData( stream:std.stream.Stream )
@@ -74,19 +70,22 @@ Function ReadWAV:AudioData( stream:std.stream.Stream )
 			Endif
 			Endif
 			
 			
 			hertz=fmt.samplesPerSec
 			hertz=fmt.samplesPerSec
-
+			
 			Continue
 			Continue
 			
 			
 		Case $61746164		'DATA
 		Case $61746164		'DATA
 			
 			
 			If Not format Return null
 			If Not format Return null
+			
+			Local bps:=BytesPerSample( format )
+			
+			Local length:=aligned_size/bps
+			
+			Local data:=New AudioData( length,format,hertz )
 
 
-			Local data:=New AudioData( size/BytesPerSample( format ),format,hertz )
-
-			stream.Read( data.Data,size )
+			stream.Read( data.Data,length*bps )
 			
 			
 			Return data
 			Return data
-		
 		End
 		End
 		
 		
 		'skip to next chunk
 		'skip to next chunk