I spent most of today trying to find out why my newly downsampled audio files weren't working in our game, where the source audio was.
The source data was 32KHz 16-bit mono, I was converting to 11KHz 8-bit mono in Sound Recorder. That caused an "unhandled exception" in the convertor tool. Using GoldWave (Which is a pretty nice piece of software BTW), the audio made it through Nintendo's convertor program, but then stuttered and then stopped altogether in game, which was odd.
After a couple of hours, I discovered that they weren't playing correctly in the Windows tool - they weren't looping, despite all the additional data files specifying that the files should loop.
Thankfully, I know how the wav format is made up, and I can read it with a hex editor, so I looked at the difference between a source file, a GoldWave-generared file and a Sound Recorder-generated file:
- Source data had the following chunks in the following order: "fmt " (Format), "data" (Data), "smpl" (Sampler), "list" (Extra text data)
- Sound Recorder data had the following chunks in the following order: "fmt " (Format), "fact" (Format dependant data) "data" (Data), "smpl" (Sampler), "list" (Extra text data)
- GoldWavedata had the following chunks in the following order: "fmt " (Format), "data" (Data), "list" (Extra text data)
After arsing around with a hex editor for a further 2 hours, I found that the Nintendo build tool requires a "smpl" chunk to be present in the file to specify that a file should loop. I suppose it makes sense, but nobody could find this mentioned anywhere in any documentation.
I strongly suspect that the Nintendo tool doesn't pay any attention to the wave file format specifications, and can't handle unknown chunks - that'd explain the unhandled exception - it'll run into the "fact" chunk and shit its pants before its got the data chunk. Just a suspicion anyway.
So, I then spent the couple of hours writing a tool that just goes through and stuffs a "smpl" chunk onto the wave file, and bingo, it all started working. I started on a second version of ther tool on the train on the way home, and I'll hopefully finish it on the way in tomorrow. The new version will strip out unknown chunks, which might save us some space. And it'll let you optionally remove existing "smpl" chunks from files to reset the looping. The current version only adds a "smpl" chunk if there isn't one in the file.
Anyway, rant over. But I still spent about 6 hours today doing nothing but trying to get to grips with Nintendo's damn tools. Still, at least I know now...
DruinkScript can now parse most expressions with binary operators (Although it doesn't generate correct I-code yet, just placeholder stuff), and it can parse function calls with expressions for each parameter (Including other functions). Next up is getting unary operators working (I can only think of pre/post incrememnt/decrememnt off the top of my head) and array indices.
I don't think I'll allow conditional logic inside expressions (for now at least) since that should simplify things.
Anyway, I'll throw some code up here once it's all nice and working. Then people can shout at me for my code that's probably a bastardisation of some existing algorithm. At least all the tokens are allocated from a pool allocator and are contiguous, so cache misses should be at a minimum.