Threads have been posted on this topic before; however, I've yet to find the fruits of anyone's labors and have written an ugly python script to decode a Discworld 2 music file and convert it into uncompressed *.wav
Unfortunately, my implimentation of the decoder from Scummvm's adpcm.cpp generates a skewed output with lots of outliers:
(Wave seems offset from the y-axis, and there should be much less rubbish exceeding 32767 (int16 limit) on the same axis)
The script, with decoding loop highlighted: http://pastebin.com/7Apu6uQ5
Scummvm isn't a Python project (clearly) but I've stumped myself for a couple days: over something that's clearly a small fix. If the flaw is obvious to anyone I'd appreciate input. The script is free for anyone to use. Thanks
Stumped - Decoding Tinsel/Discworld 2 Music - Python Script
Moderator: ScummVM Team
Re: Stumped - Decoding Tinsel/Discworld 2 Music - Python Scr
The way the y-offset is bad in your graph suggests a conversion mistake between unsigned and two's complement. Especially the middle part where zero tends to be the floor value instead of the average value.nivardus wrote:Wave seems offset from the y-axis,
8bit/sample wav's use unsigned values and 16bit/sample wav's use two's complement values.
Great reading material about wav's
http://www.lightlink.com/tjweber/StripWav/WAVE.html
http://www.lightlink.com/tjweber/StripWav/Canon.html
Explanation of unsigned and two's complement
http://en.wikipedia.org/wiki/Two's_complement
http://www.rwc.uc.edu/koehler/comath/13.html
-----
If you want to convert 8bit/sample to 16bit/sample, preferably use a 'real' audio editor (like Audacity) and not just a byte-by-byte script.
Audacity will will not only take care of the signed/unsigned problem but also take into account the shape of the sound wave, getting you a much smoother result.
Just figure out how to output an 8bit/sample wav with Python and then convert to 16bit/sample with Audacity.
Last edited by bobdevis on Thu Oct 07, 2010 8:43 am, edited 1 time in total.
Thanks, bobdevis. This is great reading material: I will probably need to trace down the problem among python's implicit types and casting.
A point of clarification: the graph is the raw sample output from the conversion, and not from the encoded *.WAV. (The error lies in the decoding of the ADPCM data.)
A point of clarification: the graph is the raw sample output from the conversion, and not from the encoded *.WAV. (The error lies in the decoding of the ADPCM data.)
This may or may not be relevant. Officially wav is just a container format. In many cases it can be just PCM with a header slapped on it.nivardus wrote: A point of clarification: the graph is the raw sample output from the conversion, and not from the encoded *.WAV. (The error lies in the decoding of the ADPCM data.)
In any case, it's hard to see what is going on exactly because you use external tools to format the file that I am not familiar with.
So yeah. Either you find out exactly what those tools do, or you manually format your output 8bit/sample canonical wav file, byte for byte.
Re: Stumped - Decoding Tinsel/Discworld 2 Music - Python Scr
Yep I didSeldon wrote:You missed that one
Files converted.