19.2 ADPCM AIFC Format

The compressed ADPCM file format is based around AIFC. It uses a non-standard compression type and two application-specific chunks that contain the codebook and loop point information. This file is generated by the ADPCM encoding tool from standard AIFC and AIFF sample files, and is used by the Instrument Compiler to generate Bank Files and Table files.

As in AIFC, chunks are grouped together in a "FORM" container chunk:

typedef struct {
        ID              ckID;           /* "FORM" */
        s32             ckDataSize;
        s32             formType;       /* "AIFC" */
        Chunk           chunks[]
}

where ckID is always FORM and formType is AIFC. The standard AIFC chunks, which are essential, are the Common chunk, which contains information about the sound length; and the Sound data chunk.

typedef struct {
        u32             ckID;                   /* "COMM" */
        S32             ckDataSize;
        s16             numChannels;
        u32             numSampleFrames;
        s16             sampleSize;
        extended        sampleRate;
        u32             compressionType;        /* "VAPC" */
        pstring         compressionName;        /* "VADPCM ~ 4:1" */
}

The current format accepts only a single channel. The numSampleFrames field should be set to the number of bytes represented by the compressed data, not the the number of bytes used. The sampleRate is an 80 bit floating point number (see AIFC spec).

The Sound data chunk contains the compressed data:

typedef struct {
        u32             ckID;           /* "SSND" */
        s32             ckDataSize;
        u32             offset;
        u32             blockSize
        u8              soundData[];
}

Both offset and blockSize are set to zero.

The encoded file will include two application-specific chunks. The common Application Specific data chunk format in AIFC is:

typedef struct {
        u32             ckID;                           /* "APPL" */
        s32             ckDataSize;
        u32             applicationSignature;           /* "stoc" */
        u8              data[];
}

where data[] contains the application-specific data.

The Codebook application-specific data define a set of predictors that are used in the decoding of the compressed ADPCM data.

typedef struct {
        u16             version;        /* Should be 01 */
        s16             order;
        u16             nEntries;       /* "stoc" */
        s16             tableData[];
}

The order and nEntries fields together determine the length of the tableData field. In the current implementation, order, which defines the ADPCM predictor order, must be 2. nEntries can be anything from 1 to 8. The length of the tableData field is order*nEntries*16 bytes.

The Loop application-specific data contains information necessary to allow the ADPCM decompresser to loop a sound. It has the following structure:

typedef struct {
        u16             version;        /* Should be 01 */
        s16             nLoops;
        adpcmLoop       loopData[];
}

nLoops defines the number of loop points and hence the number of adpcmLoop structures in the chunk. In the current library, only one loop point can be specified. loopData has the following structure:

typedef struct {
        u16             state[16];
        s32             start;
        s32             end;
        s32             count;
} adpcmLoop

state defines the internal state of the ADPCM decoder at the start of the loop and is necessary for smooth playback across the loop point. The start and end values are represented in number of samples. count defines the number of times the loop is played before the sound completes. Setting count to -1 indicates that the loop should play indefinitely.

UP