AVR

From Atari Wiki
Revision as of 17:13, 19 March 2016 by Admin (talk | contribs)
Jump to navigation Jump to search

AVR Sample File Format was introduced by 2 Bit Systems in 1990.


The following is taken from the 'Stereo Master' manual page 36-37 (1991 Audio Video Research / 2 Bit Systems).

APPENDIX ii

.AVR Sample DATA format

Here is a brief description of the AVR sample format :-

The first 128 BYTES of an 'AVR' sound file on disk contain a sound file header. The first BYTE or WORD immediately following the header (START + 128) is the first BYTE or WORD of the sound sample itself. The contents of the header are as follows ...


OFFSET SIZE(BYTES) DESCRIPTION 0-3 4 4 BYTE ASCII CHARACTER I.D. CONTAINS "2BIT"

4-11 8 8 BYTE ASCII CHARACTER SAMPLE NAME. UNUSED BYTES PADDED WITH NULL ($00).

12-13 2 WORD = 0 FOR MONO / $FFFF FOR STEREO SAMPLE

14-15 2 WORD = SAMPLE RESOLUTION $0008 ( 8 BIT) $0010 (16 BIT)


16-17 2 WORD $0000 = UNSIGNED SAMPLE WORD SFFFF = SIGNED SAMPLE

18-19 2 WORD $0000 = NON LOOPING SAMPLE WORD WORD $FFFF = LOOPING SAMPLE OTHER VALUES RESERVED FOR ALTERNATIVE LOOP TYPES

20-21 2 WORD = ASSIGNED MIDI NOTE / SPLIT $FFFF = NO ASSIGNMENT (DEFAULT) $FFXX = SINGLE KEY NOTE ASSIGNMENT $LLHH = KEY SPLIT, TWO BYTES NOTE LOW/NOTE HI

22-25 4 LONG = SAMPLE SPEED SPLIT INTO 1 BYTE & 3 BYTES BYTE 22 = 0 TO 7 OR $FF BYTE 23 - 25 = 3 BYTE SAMPLE FREQUENCY IN HERTZ


26-29 4 LONG LENGTH OF SAMPLE IN DATA BYTES OR WORDS

30-34 4 LONG FIRST LOOP POINT (OFFSET IN DATA WORDS) FORCE $0000 IF UNUSED

34-37 4 LONG END LOOP POINT (OFFSET IN DATA WORDS) FORCE TO SAMPLE LENGTH IF UNUSED

38-39 2 - DO NOT USE - RESERVED AREA - MIDI KEYBOARD SPLIT

40-41 2 - DO NOT USE - RESERVED AREA - SAMPLE COMPRESSION

42-43 2 - DO NOT USE - RESERVED AREA - FILL WITH $00

44-63 20 FILE NAME EXTENSION. FILL WITH $00 IF UNUSED

64-127 64 FREE AREA FOR DEFINITION BY USER. MAY HAVE ASCII MESSAGE OR OTHER USER DEFINED DATA.

128 - END -SAMPLE- held in format described by header.

This format represents a useful header which can be used to describe, not only 16 BIT samples, but has the flexibilty built into it to cater for MONO/STEREO and 8, 12, 14 and 16 BIT data sizes. 2-BIT SYSTEMS recommend that users DO NOT occupy the reserved space in the first 64 BYTES of the header, the last 64 BYTES have been provided for miscellaneous use and abuse.

If the user is developing software which uses the AVR format, please note the following :-

when reading samples

i) Always check the first 4 BYTES of the sample file for '2BIT' before attempting to load in any sample in from disk. If this header is found, then it can be assumed that the sample is in AVR format, no matter what the file extension is. It is useful, though not important, to save AVR files out as XXXX.AVR.

ii) After having established that the sample is indeed an AVR file, load the 128 BYTE header into a separate area of memory. Interpret this header before attempting to load the rest of the file. This is important for a number of reasons, the least of which is that if a Stereo or 16 BIT sample were just about to be loaded, the load address for the sample block should be made on a WORD boundary.

iii) Do not take anything for granted about the sample. Ensure that all of the important parameters have been read and interpreted. E.G. SIGN status. If your program can only use BYTE EXCESS samples then ensure that the sample is not signed (and un-sign it if it is).


iv) When reading the FREQUENCY long word, mask off the top 8 BITS. These bits were used in ST-REPLAY, REPLAY PROFESSIONAL and the first version of the PRO-SERIES editors. This byte took the form of a value from 0 to 7 which was used to denote a fixed SYSTEM frequency (0 = 5 kHz, 7 = 48 kHz etc). If this value is read as $FF then the editor assumes that the sample frequency is not immediately compatible with the choice which the cartridge and EDITOR support.

v) After reading the 8 byte ASCII file name, if the last byte is NULL ($00) then this is the maximum name length. However, if this last digit is NOT zero, then a check should be made at the first byte of the file name extension. If this value is also not zero, then upto an extra 20 Characters can be added to the first 8, yielding a maximum filename of upto 28 characters.


When writing a file

i) ALWAYS wipe the entire header area with zero's when constructing a new header.

ii) ALWAYS force default values and never leave any RUBBISH in areas unused by the program in question, remember, another program may look for DATA which is nonsense otherwise.

iii) If looping is not used within a sample, always force the start loop to be zero and the end loop to match the sample length.

iv) When writing the sample record frequency long word into the header, ensure that the default of $FF is placed into the top 8 BITS.

SIZES and POINTER OFFSETS

Please note the use of the phrase 'WORD size' when expressing the size of a sample or the offset of the loop pointers from the start of the sample. It is assumed that if the sample is an 8 BIT sample (or less), then this word size is BYTE. If the sample is greater than 8 BITS then the size is assumed to be a 16 BIT data WORD. Hence a 16 BIT file size of 10,000 words would actually be 20,000 BYTES in length. The value stored in the header should be 10,000.

STEREO SAMPLES

In the same way that 16 BIT format samples should be loaded into word boundary addresses, STEREO samples should also be WORD aligned on loading. This ensures that an 8 BIT stereo pair will be readable straight into the full word of a register without causing a BUS ERROR and that 16 BIT samples will again be properly aligned. The Stereo information will be stored in an interleaved fashion with the LEFT channel data being first, followed by the RIGHT channel second. As a result, all Left channel samples will be referenced with EVEN address offsets from the start of the sample beginning with 0 and continuing 2, 4, 6 ... etc.

All Right data will be ODD byte or word offset from the start of the sample, starting from 1 and continuing 3, 5, 7 etc. Upon loading a stereo sample it would be quite possible to split the sample into 2 distinct MONO sample blocks.

MIXED resolution samples

Upon loading a sample which has a resolution of 8 BITS, a simple routine coulc be written to re-format the sample into a signed 16 BIT format. Care must be taken to observe the status of the RESOLUTION and SIGN flags. Please bear in mind that it is totally possible to load in an unsigned 12 BIT sample, in which case the data is assumed to be RIGHT justified and that the most significant 4 BITS are blank. If this were true, then a suitably written routine could re-adjust the sample contents into a more suitable form, ready for direct output, rather than using a completely different output routine. It should be noted that both the AVR PRO series 12 and 16 samplers store their data in 16 BIT signed format, despite the fact that they are 12 BIT and 16 BIT samplers respectively. This ensures a wider range of software compatibility across products and provides a less torturous route to upgrading systems!

Other audio & Tracker Formats