convert RIFX to RIFF

Codecs, formats, encoding/decoding of game audio, video and music
AlphaTwentyThree
Posts: 909
Joined: Sat Aug 09, 2014 11:21 am

convert RIFX to RIFF

Post by AlphaTwentyThree »

Hello folks!

Does anybody know if there is a tool or script to convert RIFX files to RIFF? Not all codecs regarded, only the standard PCM and ADPCM ones (PCM, MS_ADPCM, IMA_ADPCM).
If you need samples, here are some for MS_ADPCM: http://upfile.mobi/655416
Thanks for your help! :)
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: convert RIFX to RIFF

Post by aluigi »

As far as I can see the only difference with a normal RIFF is the endianess.
Exists a very basic way to do this job with quickbms, basically all you need to create is a script that parses the format (no extraction), then use "quickbms -w -E script.bms backup_file.lwav" and backup_file will contain all the fields in reverse endian.

The following is a script able to read any RIFF and RIFX with automatic endian guessing, if you use it with -E it will auotmatically reverse the endianess.

Code: Select all

idstring "RIF"
get TYPE byte
get SIZE long
endian guess SIZE
idstring "WAVE"
get RIFF_SIZE asize
savepos NEXT_OFF
for NEXT_OFF = NEXT_OFF < RIFF_SIZE
    getdstring CHUNK_TYPE 4
    get CHUNK_SIZE long

    savepos CHUNK_OFF
    xmath NEXT_OFF "CHUNK_OFF + CHUNK_SIZE"

    if CHUNK_TYPE == "fmt "
        get wFormatTag short
        get wChannels short
        get dwSamplesPerSec long
        get dwAvgBytesPerSec long
        get wBlockAlign short
        get wBitsPerSample short

        savepos TMP
        for TMP = TMP < NEXT_OFF
            get DUMMY short
        next TMP += 2

    elif CHUNK_TYPE == "akd "
        getdstring DUMMY 0x10

        savepos TMP
        for TMP = TMP < NEXT_OFF
            get DUMMY short
        next TMP += 2

    elif CHUNK_TYPE == "data"
        if wFormatTag == 1
            savepos TMP
            for TMP = TMP < NEXT_OFF
                for c = 0 < wChannels
                    if wBitsPerSample == 8
                        get SAMPLE byte
                    elif wBitsPerSample == 16
                        get SAMPLE short
                    elif wBitsPerSample == 32
                        get SAMPLE long
                    endif
                next c
                savepos TMP
            next
        endif

    endif

    goto NEXT_OFF
next
AlphaTwentyThree
Posts: 909
Joined: Sat Aug 09, 2014 11:21 am

Re: convert RIFX to RIFF

Post by AlphaTwentyThree »

Hm, "quickbms -w -E read_riff.bms 0x0c395de5.lwav" doesn't do anything. Did I overlook something important?
AlphaTwentyThree
Posts: 909
Joined: Sat Aug 09, 2014 11:21 am

Re: convert RIFX to RIFF

Post by AlphaTwentyThree »

Wait it's ok, everything went fine. However, the file doesn't produce any usable result. Is there a way to change the interleave value? Running the file through ima_rejigger didn't help either.
AlphaTwentyThree
Posts: 909
Joined: Sat Aug 09, 2014 11:21 am

Re: convert RIFX to RIFF

Post by AlphaTwentyThree »

Anybody has an idea how to get a playable result?