AVR File format

I have had a number of questions regarding the AVR file-format, and how to load them into memory and then play them using the Falcon.

Well, the playing part of this is defined elsewhere but here is some information which should be useful for people loading them into memory and interpreting them.


AVR files are made up of a 128 byte header, followed immediately by the first piece of sample data. The header is composed as inidcated by the following C structure:

typedef struct
   {
    char magic[4];     /* must be '2BIT' */
    char name[8];      /* filename - may need appending to nameext */
    short stereo;      /* 0=mono, $ffff=stereo */
    short resolution;  /* 8=8-bit 12=12-bit 18=16-bit */
    short signed;      /* 0=unsigned $ffff=signed */
    short looping;     /* 0=no loop, $ffff=looping (other values used)
    short midinote;    /* $ffff=none, $ffxx= single note $llhh=split */
    long freq;         /* mask top byte, and rest = freq in Hz */
    long length;       /* in data bytes/words - ie *2 for 16-bit */
    long loopstart;    /* offset in data bytes/words */
    long loopend;      /* and again... */
    short midisplit;   /* dont use - split point for midi keyboards */
    short compression; /* do not use - fill with 0's */
    short resv;        /* reserved - fill with 0's   */
    char nameext[20];  /* more space for filename. Pad with 0's */
    char markers[64];  /* sample position markers. fill with 0's */
   } AVR_header;
Note that all values are in motorola (big-endian) format, and that long is assumed to be 4 bytes, and short 2 bytes.

When reading the samples, you should handle both signed and unsigned data, and be prepared to convert 16->8 bit, or mono->stereo if needed. To convert 8-bit data between signed/unsigned just add 127 to the sample values. Simularly for 16-bit data you should add 32769

Note that due to numerous errors in documentation, the frequency given in the freq field may not be 100% correct. Therefore, it is best to take the nearest frequency that the hardware supports instead of refusing to play if un-recognised frequency.


Back to the programming page
Back to the main index

Email me at: jacquesa@zetnet.co.uk