Content deleted Content added
No edit summary |
Minor correction |
||
Line 146:
The accquistion of the desired byte seems more complex then it really is, the long calculation can actually be more easily performed using a byte counter that is incremented every 'audio frame' processed but for complete clarity, the entire calculation is shown. It is assumed the entire file has been either [[mmap]]-ed or else read into memory, however progressive reading [ie. [[Streaming media | streaming]]] of the file is entirely possible as well. We start at the begining of the audio section of the ADX then move the pointer to the 'audio frame' currently being processed, the calculation finds the number of frames already processed then, of course, there is a block for each channel in each frame with each being 18 bytes that must be skipped over until we reach the frame we want. Once that is done it is then necessary to move to the block that belongs to the channel that is currently being processed in the frame (ie. if we are reading the right channel, we must skip over the left channel block), we then skip over the 2 byte scale value at the start of the block before proceeding to the byte we want within it. The division by 2 in the last calculation is done because it is assumed that the array contains 8bit [unsigned] bytes, with each holding 2 samples.
The highest bit of the 4bit sample is the [[sign bit]] (negative when set, [[Two's complement]]) so the number has to be converted into an 8bit or larger signed integer for proper arithmetic handling as few processors can handle 4bit numbers natively. The next stage is to multiply the sample by the scale which gives it a rational amplitude, then amplify by a volume, values between 0-2000<sub>16</sub> tend to work best for the volume but can go higher. The next 2 steps include information from the previous two samples to bring the sample in line with the others, be aware that the previous samples progress across block boundaries, but separate sample sets must be kept for each channel [NOTE: The values start at 0 on the first audio frame]. Lastly, it's
The decoded samples from each channel will still need to be interleaved together to form raw [[PCM]] audio data suitable for output into a sound card.
|