| 1 |
# MODIFIED |
| 2 |
|
| 3 |
this is a modified version of adpcm-xq which fixes memory safety issues. |
| 4 |
|
| 5 |
//////////////////////////////////////////////////////////////////////////// |
| 6 |
// **** ADPCM-XQ **** // |
| 7 |
// Xtreme Quality ADPCM Encoder/Decoder // |
| 8 |
// Copyright (c) 2022 David Bryant. // |
| 9 |
// All Rights Reserved. // |
| 10 |
// Distributed under the BSD Software License (see license.txt) // |
| 11 |
//////////////////////////////////////////////////////////////////////////// |
| 12 |
|
| 13 |
While very popular at the end of the last century, ADPCM is no longer a |
| 14 |
common audio encoding format, and is certainly not recommended as a general |
| 15 |
purpose encoder. However, it requires minimal CPU resources for decoding, |
| 16 |
and so still is ideally suited for certain embedded games and applications |
| 17 |
that contain canned audio samples. |
| 18 |
|
| 19 |
This encoder combines two different techniques to achieve higher quality |
| 20 |
than existing ADPCM encoders while remaining fully compatible with standard |
| 21 |
decoders. The first is dynamic noise shaping, which shifts the quantization |
| 22 |
noise up or down in frequency based on the spectrum of the source signal. |
| 23 |
This technique is identical to the algorithm used in WavPack's lossy mode |
| 24 |
and can make any audible quantization noise much less annoying (or, in some |
| 25 |
cases, inaudible). |
| 26 |
|
| 27 |
The other technique is "lookahead" in which the encoder exhaustively |
| 28 |
searches ahead to find the optimum coding sequence based on future samples. |
| 29 |
This process can reduce the quantization noise from about 1 to 6 dB (depending |
| 30 |
on the source) and also reduces or eliminates the harmonic content in the |
| 31 |
noise that sometimes plagues ADPCM. Unfortunately, at its maximum settings |
| 32 |
this can be very slow, but this should be relatively irrelevant if the |
| 33 |
encoder is being used to generate canned samples. |
| 34 |
|
| 35 |
Adpcm-xq consists of two standard C files and builds with a single command |
| 36 |
on most platforms. It has been designed with maximum portability in mind |
| 37 |
and should work correctly even on 16-bit and big-endian architectures |
| 38 |
(WAV files are of course always little-endian). |
| 39 |
|
| 40 |
Linux: |
| 41 |
% gcc -O2 *.c -o adpcm-xq |
| 42 |
|
| 43 |
Darwin/Mac: |
| 44 |
% clang -O2 *.c -o adpcm-xq |
| 45 |
|
| 46 |
MS Visual Studio: |
| 47 |
cl -O2 adpcm-xq.c adpcm-lib.c |
| 48 |
|
| 49 |
Bugs: |
| 50 |
|
| 51 |
1. Unknown RIFF chunk types are correctly parsed on input files, but are not |
| 52 |
passed to the output file. |
| 53 |
|
| 54 |
2. The lookahead feature does not work for the last samples in an ADPCM |
| 55 |
block (i.e. it doesn't utilize samples in the _next_ block). |
| 56 |
|
| 57 |
3. In some situations the lookahead can get very slow or seem to be stuck |
| 58 |
because it needs improved trellis pruning. However the default level 3 |
| 59 |
should always be fine and then the user can simply try increasing levels |
| 60 |
until the time becomes untenable. |
| 61 |
|
| 62 |
4. Pipes are not yet supported. |
| 63 |
|