AY Crudentials: 4 Bit Samples
Posted: Sun Jan 22, 2006 11:36 am
The process of Playing a 4 Bit sample is alot easier than an 8 or 2 bit since this is what the AY-3-8912 can handle. The problem is in deciding the format of the source byte.
The Source byte is 8 bits, which may potentially store two 4 bit sample values.
Their are 4 formats possible.
Format 1: 4BIT
Simply storing the 4 bits in the 8 bits available.
However, this is just plain inefficient.
Format 2: B0B1
Keeping to Format 1 but the top 4 bits store a second sample, which may potentially be an extension of the first sample once the lower 4 bit sample has finished.
Note: SoundTracker used this format, but assigned the lower 4 bits to Bank 0 and the upper to Bank 1 (Hence the name BOB1).
Format 3: LOHI
the lower 4 bits is the first value of the byte and the higher 4 bits is the second.
Format 4: HILO
the higher 4 bits is the first value of the byte and the lower 4 bits is the second.
The other problem is detecting the end of a sample.
In my experience, i have used 3 different formats over the years for detecting the end.
Format 1: ZERO (ZERO in data is end)
one value of the 4 bit entity is used to trigger an end, that value being 0.
This is by far the simplest method but does reduce the available values to 1 to 15.
Format 2: HEND (High marks END)
All samples are trimmed to a 256 boundary and always start from the same 256 boundary, then only the high byte of the location needs to be checked for the end location.
Format 3: LEND (Location is END)
A samples end is detected by both Low and High byte End Detection. This has the diasadvantage of being slow (in the play routine) to detect but the advantage of being memory efficient.
The final problem is deciding how the machine code routine plays the sample. A sample must be played at an even tempo otherwise it will sound wrong because the speed will differ from the original the sample was taken from.
The are two known methods for accomplishing this.
Method 1: Play using Cycle exact routine
The sample routine is written accounting for every cycle in the actual code.
Each machine code instruction takes an exact number of machine cycles to execute. With this knowledge it is possible to both calculate the speed of operation and that every loop will consume the same number of cycles.
SoundTracker used this method
Method 2: Play on Interrupt
The sample play routine is placed inside an interrupt framework, which leaves the actual precise timing to the Timer used for the interrupt.
Sonix 4.00 used this method
The Source byte is 8 bits, which may potentially store two 4 bit sample values.
Their are 4 formats possible.
Format 1: 4BIT
Simply storing the 4 bits in the 8 bits available.
However, this is just plain inefficient.
Format 2: B0B1
Keeping to Format 1 but the top 4 bits store a second sample, which may potentially be an extension of the first sample once the lower 4 bit sample has finished.
Note: SoundTracker used this format, but assigned the lower 4 bits to Bank 0 and the upper to Bank 1 (Hence the name BOB1).
Format 3: LOHI
the lower 4 bits is the first value of the byte and the higher 4 bits is the second.
Format 4: HILO
the higher 4 bits is the first value of the byte and the lower 4 bits is the second.
The other problem is detecting the end of a sample.
In my experience, i have used 3 different formats over the years for detecting the end.
Format 1: ZERO (ZERO in data is end)
one value of the 4 bit entity is used to trigger an end, that value being 0.
This is by far the simplest method but does reduce the available values to 1 to 15.
Format 2: HEND (High marks END)
All samples are trimmed to a 256 boundary and always start from the same 256 boundary, then only the high byte of the location needs to be checked for the end location.
Format 3: LEND (Location is END)
A samples end is detected by both Low and High byte End Detection. This has the diasadvantage of being slow (in the play routine) to detect but the advantage of being memory efficient.
The final problem is deciding how the machine code routine plays the sample. A sample must be played at an even tempo otherwise it will sound wrong because the speed will differ from the original the sample was taken from.
The are two known methods for accomplishing this.
Method 1: Play using Cycle exact routine
The sample routine is written accounting for every cycle in the actual code.
Each machine code instruction takes an exact number of machine cycles to execute. With this knowledge it is possible to both calculate the speed of operation and that every loop will consume the same number of cycles.
SoundTracker used this method
Method 2: Play on Interrupt
The sample play routine is placed inside an interrupt framework, which leaves the actual precise timing to the Timer used for the interrupt.
Sonix 4.00 used this method