<s>
CRI	B-Algorithm
ADX	I-Algorithm
is	O
a	O
lossy	B-Algorithm
proprietary	B-Application
audio	O
storage	O
and	O
compression	O
format	O
developed	O
by	O
CRI	O
Middleware	O
specifically	O
for	O
use	O
in	O
video	O
games	O
;	O
it	O
is	O
derived	O
from	O
ADPCM	B-Algorithm
.	O
</s>
<s>
Its	O
most	O
notable	O
feature	O
is	O
a	O
looping	O
function	O
that	O
has	O
proved	O
useful	O
for	O
background	O
sounds	O
in	O
various	O
games	O
that	O
have	O
adopted	O
the	O
format	O
,	O
including	O
many	O
games	O
for	O
the	O
Sega	B-Operating_System
Dreamcast	I-Operating_System
as	O
well	O
as	O
some	O
PlayStation	B-Device
2	I-Device
,	O
GameCube	B-Application
and	O
Wii	B-Operating_System
games	O
.	O
</s>
<s>
One	O
of	O
the	O
first	O
games	O
to	O
use	O
ADX	B-Algorithm
was	O
Burning	B-Application
Rangers	I-Application
,	O
on	O
the	O
Sega	B-Device
Saturn	I-Device
.	O
</s>
<s>
Notably	O
,	O
the	O
Sonic	B-Application
the	I-Application
Hedgehog	I-Application
series	I-Application
from	O
the	B-Operating_System
Dreamcast	I-Operating_System
generation	O
up	O
to	O
at	O
least	O
Shadow	B-Application
the	I-Application
Hedgehog	I-Application
have	O
used	O
this	O
format	O
for	O
sound	O
and	O
voice	O
recordings	O
.	O
</s>
<s>
Jet	B-Application
Set	I-Application
Radio	I-Application
Future	I-Application
for	O
original	B-Application
Xbox	I-Application
also	O
used	O
this	O
format	O
.	O
</s>
<s>
On	O
top	O
of	O
the	O
main	O
ADPCM	B-Algorithm
encoding	O
,	O
the	O
ADX	B-Algorithm
toolkit	O
also	O
includes	O
a	O
sibling	O
format	O
,	O
AHX	O
,	O
which	O
uses	O
a	O
variant	O
of	O
MPEG-2	B-Algorithm
audio	O
intended	O
specifically	O
for	O
voice	O
recordings	O
and	O
a	O
packaging	O
archive	O
,	O
AFS	O
,	O
for	O
bundling	O
multiple	O
CRI	B-Algorithm
ADX	I-Algorithm
and	O
AHX	O
tracks	O
into	O
a	O
single	O
container	O
file	O
.	O
</s>
<s>
The	O
AWB	O
extension	O
is	O
not	O
to	O
be	O
confused	O
with	O
the	O
Audio	B-Algorithm
format	I-Algorithm
with	I-Algorithm
the	I-Algorithm
same	I-Algorithm
extension	I-Algorithm
and	O
mostly	O
contains	O
the	O
binary	O
data	O
for	O
the	O
HCA	O
files	O
.	O
</s>
<s>
CRI	B-Algorithm
ADX	I-Algorithm
is	O
a	O
compressed	O
audio	O
format	O
,	O
but	O
unlike	O
MP3	B-Application
and	O
similar	O
formats	O
,	O
it	O
does	O
n't	O
apply	O
a	O
psychoacoustic	O
model	O
to	O
the	O
sound	O
to	O
reduce	O
its	O
complexity	O
.	O
</s>
<s>
The	O
ADPCM	B-Algorithm
model	O
instead	O
stores	O
samples	O
by	O
recording	O
the	O
error	O
relative	O
to	O
a	O
prediction	O
function	O
which	O
means	O
more	O
of	O
the	O
original	O
signal	O
survives	O
the	O
encoding	O
process	O
;	O
as	O
such	O
ADPCM	B-Algorithm
compression	O
instead	O
trades	O
accuracy	O
of	O
the	O
representation	O
for	O
size	O
by	O
using	O
relatively	O
small	O
sample	O
sizes	O
,	O
usually	O
4bits	O
.	O
</s>
<s>
Like	O
other	O
encoding	O
formats	O
,	O
CRI	B-Algorithm
ADX	I-Algorithm
supports	O
multiple	O
sampling	O
frequencies	O
such	O
as	O
22050	O
Hz	O
,	O
44100	O
Hz	O
,	O
48000Hz	O
,	O
etc	O
.	O
</s>
<s>
The	O
only	O
particularly	O
distinctive	O
feature	O
that	O
sets	O
CRI	B-Algorithm
ADX	I-Algorithm
apart	O
from	O
alternatives	O
like	O
IMA	B-Algorithm
ADPCM	I-Algorithm
(	O
other	O
than	O
having	O
a	O
different	O
prediction	O
function	O
)	O
is	O
the	O
integrated	O
looping	O
functionality	O
,	O
this	O
enables	O
an	O
audio	O
player	O
to	O
optionally	O
skip	O
backwards	O
after	O
reaching	O
a	O
single	O
specified	O
point	O
in	O
the	O
track	O
to	O
create	O
a	O
coherent	O
loop	O
;	O
hypothetically	O
,	O
this	O
functionality	O
could	O
be	O
used	O
to	O
skip	O
forwards	O
as	O
well	O
but	O
that	O
would	O
be	O
redundant	O
since	O
the	O
audio	O
could	O
simply	O
be	O
clipped	O
with	O
an	O
editing	O
program	O
instead	O
.	O
</s>
<s>
The	O
open	O
source	O
program	O
/	O
library	O
FFmpeg	B-Library
also	O
has	O
CRI	B-Algorithm
ADX	I-Algorithm
support	O
implemented	O
,	O
however	O
,	O
its	O
decoder	O
is	O
hard	O
coded	O
so	O
can	O
only	O
properly	O
decode	O
44100Hz	O
ADXs	O
.	O
</s>
<s>
The	O
CRI	B-Algorithm
ADX	I-Algorithm
specification	O
is	O
not	O
freely	O
available	O
,	O
however	O
the	O
most	O
important	O
elements	O
of	O
the	O
structure	O
have	O
been	O
reverse	O
engineered	O
and	O
documented	O
in	O
various	O
places	O
on	O
the	O
web	O
.	O
</s>
<s>
The	O
information	O
here	O
may	O
be	O
incomplete	O
but	O
should	O
be	O
sufficient	O
to	O
build	O
a	O
working	O
codec	B-General_Concept
or	O
transcoder	B-Algorithm
.	O
</s>
<s>
As	O
a	O
side	O
note	O
,	O
the	O
AFS	O
archive	O
files	O
that	O
CRI	O
ADXs	O
are	O
sometimes	O
packed	O
in	O
are	O
a	O
simple	O
variant	O
of	O
a	O
tarball	B-Application
which	O
uses	O
numerical	O
indices	O
to	O
identify	O
the	O
contents	O
rather	O
than	O
names	O
.	O
</s>
<s>
Source	O
code	O
for	O
an	O
extractor	O
can	O
be	O
found	O
in	O
the	O
ADX	B-Algorithm
archive	O
at	O
.	O
</s>
<s>
The	O
ADX	B-Algorithm
disk	O
format	O
is	O
defined	O
in	O
big-endian	O
.	O
</s>
<s>
CRI	B-Algorithm
ADX	I-Algorithm
encoded	O
audio	O
data	O
is	O
broken	O
into	O
a	O
series	O
of	O
'	O
blocks	O
 '	O
,	O
each	O
containing	O
data	O
for	O
only	O
one	O
channel	O
.	O
</s>
<s>
The	O
scale	O
is	O
a	O
13bit	O
unsigned	B-Algorithm
integer	O
(	O
big-endian	O
like	O
the	O
header	O
)	O
which	O
is	O
essentially	O
the	O
amplification	O
of	O
all	O
the	O
samples	O
in	O
that	O
block	O
.	O
</s>
<s>
This	O
section	O
walks	O
through	O
decoding	O
CRI	B-Algorithm
ADX	I-Algorithm
'	O
version	O
3	O
 '	O
or	O
'	O
version	O
4	O
 '	O
when	O
"	O
Encoding	O
Type	O
"	O
is	O
"	O
Standard	O
CRI	B-Algorithm
ADX	I-Algorithm
"	O
(	O
0x03	O
)	O
.	O
</s>
<s>
All	O
code	O
samples	O
in	O
this	O
section	O
are	O
written	O
using	O
C99	B-Language
.	O
</s>
<s>
Before	O
a	O
'	O
standard	O
 '	O
CRI	B-Algorithm
ADX	I-Algorithm
can	O
be	O
either	O
encoded	O
or	O
decoded	O
,	O
the	O
set	O
of	O
prediction	O
coefficients	O
must	O
be	O
calculated	O
.	O
</s>
<s>
Most	O
of	O
the	O
above	O
code	O
should	O
be	O
straightforward	O
enough	O
for	O
anyone	O
versed	O
in	O
C	B-Language
.	O
The	O
'	O
ADX_header	O
 '	O
pointer	O
refers	O
to	O
the	O
data	O
extracted	O
from	O
the	O
header	O
as	O
outlined	O
earlier	O
,	O
it	O
is	O
assumed	O
to	O
have	O
already	O
been	O
converted	O
to	O
the	O
host	O
Endian	O
.	O
</s>
<s>
The	O
decoded	O
samples	O
will	O
be	O
in	O
host-endian	O
standard	O
interleaved	O
PCM	B-Algorithm
format	O
,	O
i.e.	O
</s>
<s>
CRI	B-Algorithm
ADX	I-Algorithm
supports	O
a	O
simple	O
encryption	O
scheme	O
which	O
XORs	O
values	O
from	O
a	O
linear	B-Algorithm
congruential	I-Algorithm
pseudorandom	O
number	O
generator	O
with	O
the	O
block	O
scale	O
values	O
.	O
</s>
<s>
This	O
method	O
is	O
computationally	O
inexpensive	O
to	O
decrypt	O
(	O
in	O
keeping	O
with	O
CRI	B-Algorithm
ADX	I-Algorithm
's	O
real-time	O
decoding	O
)	O
yet	O
renders	O
the	O
encrypted	O
files	O
unusable	O
.	O
</s>
<s>
The	O
encryption	O
key	O
is	O
a	O
set	O
of	O
three	O
16-bit	O
values	O
:	O
the	O
multiplier	O
,	O
increment	O
,	O
and	O
start	O
values	O
for	O
the	O
linear	B-Algorithm
congruential	I-Algorithm
generator	I-Algorithm
(	O
the	O
modulus	O
is	O
0x8000	O
to	O
keep	O
the	O
values	O
in	O
the	O
15-bit	O
range	O
of	O
valid	O
block	O
scales	O
)	O
.	O
</s>
<s>
Typically	O
all	O
ADX	B-Algorithm
files	O
from	O
a	O
single	O
game	O
will	O
use	O
the	O
same	O
key	O
.	O
</s>
<s>
If	O
an	O
unencrypted	O
version	O
of	O
the	O
same	O
audio	O
is	O
known	O
the	O
random	O
number	O
stream	O
can	O
be	O
easily	O
retrieved	O
and	O
from	O
it	O
the	O
key	O
parameters	O
can	O
be	O
determined	O
,	O
rendering	O
every	O
CRI	B-Algorithm
ADX	I-Algorithm
encrypted	O
with	O
that	O
same	O
key	O
decryptable	O
.	O
</s>
<s>
Even	O
if	O
the	O
encrypted	O
CRI	B-Algorithm
ADX	I-Algorithm
is	O
the	O
only	O
sample	O
available	O
,	O
it	O
is	O
possible	O
to	O
determine	O
a	O
key	O
by	O
assuming	O
that	O
the	O
scale	O
values	O
of	O
the	O
decrypted	O
CRI	B-Algorithm
ADX	I-Algorithm
must	O
fall	O
within	O
a	O
"	O
low	O
range	O
"	O
.	O
</s>
<s>
As	O
noted	O
earlier	O
,	O
AHX	O
is	O
just	O
an	O
implementation	O
of	O
MPEG2	B-Algorithm
audio	O
and	O
the	O
decoding	O
method	O
is	O
basically	O
the	O
same	O
as	O
the	O
standard	O
,	O
it	O
is	O
possible	O
just	O
to	O
demux	O
the	O
stream	O
from	O
the	O
CRI	B-Algorithm
ADX	I-Algorithm
container	O
and	O
feed	O
it	O
through	O
a	O
standard	O
MPEG	O
Audio	O
decoder	O
like	O
mpg123	B-Language
.	O
</s>
<s>
The	O
CRI	B-Algorithm
ADX	I-Algorithm
header	O
's	O
"	O
sample	O
rate	O
"	O
and	O
"	O
total	O
samples	O
"	O
are	O
usually	O
correct	O
if	O
a	O
decoder	O
needs	O
them	O
(	O
so	O
should	O
be	O
set	O
by	O
encoder/muxer	O
implementations	O
)	O
but	O
most	O
of	O
the	O
other	O
fields	O
such	O
as	O
the	O
"	O
block	O
size	O
"	O
and	O
"	O
sample	O
bitdepth	O
"	O
will	O
usually	O
be	O
zero	O
as	O
noted	O
above	O
,	O
the	O
looping	O
functionality	O
is	O
also	O
unavailable	O
.	O
</s>
