Content deleted Content added
Minor correction |
Touchups |
||
Line 9:
}}
ADX is a lossy [[proprietary]] audio storage and compression format developed by [[CRI Middleware]] specifically for use in [[video games]]. The format is similar in principal to [[ADPCM]] but offers smaller storage sizes
== File Format ==
The ADX format's specification is not freely available, however the internal structure of the most significant elements that make up the format have been described in various places on the internet. The information given here may be incomplete but is sufficient to build a working [[codec]] or [[transcoder]].
The format is inherently [[big-endian]] even when used on [[little-endian]] architectures such as the [[Xbox | original Xbox]] or [[x86]] computer. The standard [[byte]] size is an [[Octet (computing) | octet]]. The basic structure is outlined below:
{| class="wikitable" <!-- File layout outline -->
!
Line 101:
=== Decoding Samples ===
As noted above, each sample consists of 4bits, the high 4bits of
{| class="wikitable"
!7
Line 119:
int_fast32_t sample;
uint_least8_t sample_4bit;
uint_fast16_t block_scale;
/* ... Get 4 bit sample ... */
data_index = audio_data_start + (sample_index / 32) * num_channels * 18 + (current_channel - 1) * 18
block_scale = ntohs( *(uint16_t*)&raw_data[data_index] );
data_index += 2 + sample_index % 32 / 2;
sample_4bit = raw_data[data_index];
if (sample_index % 2) /* If the sample index [starting at 0] is odd then we are decoding a
sample_4bit &= 0x0F;
else /* Otherwise it is a primary sample */
Line 135 ⟶ 138:
sample += previous_sample * 0x7298; /* Incorporate previous sample data */
sample -= second_previous_sample * 0x3350; /* Incorporate previous previous sample data */
sample >>= 14; /*
if (sample > 32767) /* Round-off the sample within the valid range for a 16bit signed sample */
sample = 32767;
Line 144 ⟶ 147:
previous_sample = sample;
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
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-
The decoded samples from each channel
== Sources ==
|