#93299 - melw - Tue Jul 18, 2006 12:35 pm
(Note: I did some searching on the forums and read through the previous ADPCM threads but didn't find conclusive answers in the end, thus the new topic.)
So, I have been fiddling lately with ADPCM sounds. Normal 8/16-bit wave files play perfectly using sound FIFO between ARM 7 and 9, but when I try ADPCM there's lots of playback problems. I'm not really sure if it's the source files or the fact that there's a need for buffering unlike with raw/pcm-wav sounds.
Exact problems I'm facing right now:
- When using sounds converted with SOX (from 22khz 16-bit mono wav files to IMA-ADPCM), the sound is garbled and there's weird echoes going on. Some sounds play somehow better than the others, but in the end none is 100% functional
- I also tried the sample ADPCM from 8ad package (~18khz) - that one gave every time just static
The visible differences with the sounds converted with SOX is that they have 0x3C long header, the latter only 0x2C sized header. Didn't check the block data though. Everything plays well for example in SoundForge or WinAmp or with FMOD so the files should be ok.
#93331 - tepples - Tue Jul 18, 2006 6:11 pm
8ad by default uses my modified "ima9" tables, with residual tables and step index change tables modified to give fewer slope overload artifacts. You'll have to change myima.c to use init_encode_ima() instead of init_encode_ima() in order to use the standard IMA.
You'll also have to prepend a 3-byte header stating the initial step size (which the encoder passes to init_encode_ima()) and the initial sample value (use 0).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#93359 - agentq - Tue Jul 18, 2006 7:51 pm
I never got the ADPCM hardware to play back standard IMA-ADPCM sounds, because the initial value needed to be reset each time the sample buffer looped.
Eventually I decoded the sample in software while streaming off the disk and played it back as a plain 8-bit sound.
#93401 - tepples - Tue Jul 18, 2006 11:42 pm
I think DS hardware ADPCM is meant not for streaming but for in-game sound effects and musical instruments, which are loaded entirely into RAM and stay in RAM. If you're streaming audio, you're probably only streaming one thing at a time (such as music or speech), and you can use a more sophisticated codec such as variable-length ADPCM, some more sophisticated predictive codec (e.g. GSM 06.10), or some transform codec (e.g. MP2).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#93464 - melw - Wed Jul 19, 2006 9:19 am
Thanks for both of the replies. Would be interesting to know if anyone has succeeded in getting the hardware ADPCM working... otherwise it might not be worth the trouble for me as low sample rate wav's work pretty well and don't take that much memory for sound effects.
Tepples: The samples I have are loaded in RAM, only on the ARM9 side, from where I use FIFO to transfer them to ARM7 whenever needed.
Agentq: Before you changed to software, how well did you get the hardware playback to work? I remember reading in the older ScummVM threads that looping sounds were problematic, or was it just these resetting values with the sample buffer?
I might take another look at this, but no high hopes if nobody else has got the ADPCM working so far. :)
#93653 - JimmyL - Thu Jul 20, 2006 1:22 pm
I've been using adpcm for the music in my games, by putting in all in ram, not the best method, but so far my games have been small and everything fits.
I wrote a simple tool to convert an ima-adpcm to raw, which strips some header and index blocks from the file which the ds doesn't seem to like, then the raw file gets converted by my makefile, the same way the simplesound sample of libnds does. It seems to work and I haven't noticed any artifacts when the music loops, but it only loops every couple of minutes, and I haven't really listened for it.
Also, for some reason, my tool doesn't handle ima's made with sox properly, they must format it slightly differently than windows soundrecorder or cdex.
oops, forgot a link to the tool :)
http://www.atouchofwar.com/Files/ima2raw.zip
Jimmy
_________________
A Touch of War
#93822 - melw - Fri Jul 21, 2006 2:50 pm
JimmyL, millions of thanks! It does work indeed perfectly, even the looping sounds. What does the converter do exactly? From a hex editor I can see the file header (and the block headers?) are stripped, but the output file is still some hundred bytes larger than the original.
Will do some automation to get working batch converter straight from pcm wav to this modified raw adpcm format with minimal header/footer information included (sample rate at least) - then I'm more than satisfied with the given audio solution.
PS. Libsndfile does pretty good command line wav -> ima-adpcm convertion, been using that during the past week without any problems. Works on Linux, Windows and Macs all alike.
#93904 - JimmyL - Fri Jul 21, 2006 10:14 pm
Interesting, I never noticed that the files grew. All that tool does is rip out the wav header, then only keep the first block header, ignoring the rest.
I just took a quick look at the source(which I included in the zip), and the only thing I can see is the final block is being read/written at 'blocksize', and I'm guessing the final block of wave data is probably smaller than that. I'm not sure what fread fills the buffer with if you ask for too large a block, but it's probably filled with wav info from the previous block and could cause sound glitches at the end of the wav... I'll fix that later this weekend assuming that's the problem.
Jimmy
#94249 - JimmyL - Mon Jul 24, 2006 1:05 am
melw,
I just posted a new version of the converter, it should fix the size growth problem.
you can grab it here http://www.atouchofwar.com/Files/ima2raw.zip
Jimmy
#94319 - melw - Mon Jul 24, 2006 10:55 am
Thanks! I still have some garbage with at the end of short sound files, but it seems to be sox doing that extra garbage... I guess I'll just upgrade to Sound Forge 8 and use it's batch converter for the wav->adpcm part.
Btw. If anybody knows any other command line tools than sox for doing audio conversions, resampling etc. - suggestions are welcome.