About Monkey 2 › Forums › Monkey 2 Programming Help › Unable to load certain WAV files
This topic contains 6 replies, has 5 voices, and was last updated by 
 Mark Sibly
 1 year, 12 months ago.
- 
		AuthorPosts
 - 
		
			
				
April 18, 2017 at 5:33 am #7946
I’m working on a sort of music player for a certain type of music file format.
That means I have to load the WAV files that comes with those music files.
But I’m having some issues, only about 15% of the WAV files I try to load actually gets loaded.
And I’m sure it has to do with the compression or something like that, but I really need a way to load them…Here’s a test WAV file I’m having issues with: http://www.wikifortio.com/707390/test.wav
And here’s some code to test it with:Monkey12345678910111213141516171819202122232425262728293031323334#Import "<std>"#Import "<mojo>"#Import "assets/"Using std..Using mojo..Class MyWindow Extends WindowField sound:SoundField channel:ChannelMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )sound=Sound.Load("asset::test.wav")channel=New ChannelIf Not sound Then Print "Unable to load sound!"EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.DrawText( "Hello World!",Width/2,Height/2,.5,.5 )If Keyboard.KeyHit(Key.Space) Then channel.Play(sound)EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndApril 18, 2017 at 7:37 am #7947I can tell you it’s a standard stereo 16bit uncompressed wav file. so… in theory it should load.
Confirmed. wav not loaded!
one thing I’ve found is to NEVER use #Import”assets/”. always import each asset individually otherwise there is a tendency of multiple duplications on compile.
OK. Checking the wav file itself reveals the header is reporting 0 channels and 0 bits. Monkey dumps this sample as the needed header information is not compatible. So you have a technical error with your wav file.
The next best thing to do would be to write your own wav loader that deals correctly with this situation as there is other info about the wav file and its contents which would correctly return the channel and bit information
April 18, 2017 at 8:14 am #7948Thanks for figuring that out.
All applications load the WAV files just fine so it seems like Monkey 2 should load them too.
I think maybe Mark needs to look at this instead of me writing a WAV loader.April 19, 2017 at 4:32 am #7962a game engine isn’t an audio editor, so I’d argue it’s still your responsibility to fix wave files with bad headers if you want them to play in your project. Without a proper header, the entire file needs to be read and the length and format guessed.
April 19, 2017 at 5:39 am #7963I’m not sure I agree. The example is a perfectly valid WAV with an additional JUNK block preceeding the fmt block at start which does NOT make it technically incorrect.
The fact monkey2 uses it’s own wav parser that expects the fmt block to always be first like the blitzmax loader is the problem here.
April 20, 2017 at 12:17 am #7971ah, fair enough. I was under the assumption that the fmt block was incomplete or had bad data.
April 22, 2017 at 4:02 am #7989Fix pushed to develop branch.
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.