mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-20 04:21:11 +01:00
Add OKI16 TXTH/GENH decoder [Sweet Legacy (PS2), Hooligan (PS2)]
This commit is contained in:
parent
1f44c2d2de
commit
093fa28a2f
@ -86,6 +86,7 @@ A text file with the above commands must be saved as ".vag.txth" or ".txth", not
|
||||
# - PCFX PC-FX ADPCM
|
||||
# - PCM4 PCM 4-bit signed
|
||||
# - PCM4_U PCM 4-bit unsigned
|
||||
# - OKI16 OKI ADPCM with 16-bit output (not std/VOX/Dialogic 12-bit)
|
||||
codec = (codec string)
|
||||
|
||||
# Codec variations [OPTIONAL, depends on codec]
|
||||
|
@ -171,9 +171,10 @@ void decode_derf(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing,
|
||||
/* circus_decoder */
|
||||
void decode_circus_adpcm(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do);
|
||||
|
||||
/* pcfx_decoder */
|
||||
/* oki_decoder */
|
||||
void decode_pcfx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int mode);
|
||||
size_t pcfx_bytes_to_samples(size_t bytes, int channels);
|
||||
void decode_oki16(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel);
|
||||
size_t oki_bytes_to_samples(size_t bytes, int channels);
|
||||
|
||||
/* ea_mt_decoder*/
|
||||
ea_mt_codec_data *init_ea_mt(int channels, int type);
|
||||
|
@ -1,14 +1,14 @@
|
||||
#include "coding.h"
|
||||
|
||||
|
||||
static const int step_sizes[49] = { /* OKI table */
|
||||
static const int step_sizes[49] = { /* OKI table (subsection of IMA's table) */
|
||||
16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50,
|
||||
55, 60, 66, 73, 80, 88, 97, 107, 118, 130, 143, 157,
|
||||
173, 190, 209, 230, 253, 279, 307, 337, 371, 408, 449,
|
||||
494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, 1552
|
||||
};
|
||||
|
||||
static const int stex_indexes[16] = { /* IMA table */
|
||||
static const int stex_indexes[16] = { /* OKI table (also from IMA) */
|
||||
-1, -1, -1, -1, 2, 4, 6, 8,
|
||||
-1, -1, -1, -1, 2, 4, 6, 8
|
||||
};
|
||||
@ -54,6 +54,26 @@ static void pcfx_expand_nibble(VGMSTREAMCHANNEL * stream, off_t byte_offset, int
|
||||
}
|
||||
}
|
||||
|
||||
static void oki16_expand_nibble(VGMSTREAMCHANNEL * stream, off_t byte_offset, int nibble_shift, int32_t * hist1, int32_t * step_index, int16_t *out_sample) {
|
||||
int code, step, delta;
|
||||
|
||||
code = (read_8bit(byte_offset,stream->streamfile) >> nibble_shift) & 0xf;
|
||||
step = step_sizes[*step_index];
|
||||
|
||||
delta = (code & 0x7);
|
||||
delta = (((delta * 2) + 1) * step) >> 3; /* IMA 'mul' style (standard OKI uses 'shift-add') */
|
||||
if (code & 0x8)
|
||||
delta = -delta;
|
||||
*hist1 += delta;
|
||||
|
||||
/* standard OKI clamps hist to 2047,-2048 here */
|
||||
|
||||
*step_index += stex_indexes[code];
|
||||
if (*step_index < 0) *step_index = 0;
|
||||
if (*step_index > 48) *step_index = 48;
|
||||
|
||||
*out_sample = *hist1;
|
||||
}
|
||||
|
||||
/* PC-FX ADPCM decoding, variation of OKI/Dialogic/VOX ADPCM. Based on mednafen/pcfx-music-dump.
|
||||
* Apparently most ADPCM was made with a buggy encoder, resulting in incorrect sound in real hardware
|
||||
@ -65,7 +85,7 @@ static void pcfx_expand_nibble(VGMSTREAMCHANNEL * stream, off_t byte_offset, int
|
||||
*
|
||||
* PC-FX ISOs don't have a standard filesystem nor file formats (raw data must be custom-ripped),
|
||||
* so it's needs GENH/TXTH. Sample rate can only be base_value divided by 1/2/3/4, where
|
||||
* base_value is approximately ~31468.5 (follows hardware clocks), mono or stereo-interleaved.
|
||||
* base_value is approximately ~31468.5 (follows hardware clocks), mono or interleaved for stereo.
|
||||
*/
|
||||
void decode_pcfx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int mode) {
|
||||
int i, sample_count = 0;
|
||||
@ -86,7 +106,40 @@ void decode_pcfx(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing,
|
||||
stream->adpcm_step_index = step_index;
|
||||
}
|
||||
|
||||
size_t pcfx_bytes_to_samples(size_t bytes, int channels) {
|
||||
/* OKI variation with 16-bit output (vs standard's 12-bit), found in FrontWing's PS2 games (Sweet Legacy, Hooligan).
|
||||
* Reverse engineered from the ELF with help from the folks at hcs. */
|
||||
void decode_oki16(VGMSTREAMCHANNEL * stream, sample * outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int channel) {
|
||||
int i, sample_count = 0;
|
||||
int32_t hist1 = stream->adpcm_history1_32;
|
||||
int step_index = stream->adpcm_step_index;
|
||||
int16_t out_sample;
|
||||
int is_stereo = channelspacing > 1;
|
||||
|
||||
|
||||
/* external interleave */
|
||||
|
||||
/* no header (external setup), pre-clamp for wrong values */
|
||||
if (step_index < 0) step_index=0;
|
||||
if (step_index > 48) step_index=48;
|
||||
|
||||
/* decode nibbles (layout: varies) */
|
||||
for (i = first_sample; i < first_sample + samples_to_do; i++, sample_count += channelspacing) {
|
||||
off_t byte_offset = is_stereo ?
|
||||
stream->offset + i : /* stereo: one nibble per channel */
|
||||
stream->offset + i/2; /* mono: consecutive nibbles (assumed) */
|
||||
int nibble_shift =
|
||||
is_stereo ? (!(channel&1) ? 0:4) : (!(i&1) ? 0:4); /* even = low, odd = high */
|
||||
|
||||
oki16_expand_nibble(stream, byte_offset,nibble_shift, &hist1, &step_index, &out_sample);
|
||||
outbuf[sample_count] = (out_sample);
|
||||
}
|
||||
|
||||
stream->adpcm_history1_32 = hist1;
|
||||
stream->adpcm_step_index = step_index;
|
||||
}
|
||||
|
||||
|
||||
size_t oki_bytes_to_samples(size_t bytes, int channels) {
|
||||
/* 2 samples per byte (2 nibbles) in stereo or mono config */
|
||||
return bytes * 2 / channels;
|
||||
}
|
||||
|
@ -635,6 +635,7 @@ static const coding_info coding_info_list[] = {
|
||||
{coding_ASF, "Argonaut ASF 4-bit ADPCM"},
|
||||
{coding_XMD, "Konami XMD 4-bit ADPCM"},
|
||||
{coding_PCFX, "PC-FX 4-bit ADPCM"},
|
||||
{coding_OKI16, "OKI 4-bit ADPCM (16-bit output)"},
|
||||
|
||||
{coding_SDX2, "Squareroot-delta-exact (SDX2) 8-bit DPCM"},
|
||||
{coding_SDX2_int, "Squareroot-delta-exact (SDX2) 8-bit DPCM with 1 byte interleave"},
|
||||
|
@ -6,33 +6,34 @@
|
||||
|
||||
/* known GENH types */
|
||||
typedef enum {
|
||||
PSX = 0, /* PSX ADPCM */
|
||||
XBOX = 1, /* XBOX IMA ADPCM */
|
||||
NGC_DTK = 2, /* NGC ADP/DTK ADPCM */
|
||||
PCM16BE = 3, /* 16bit big endian PCM */
|
||||
PCM16LE = 4, /* 16bit little endian PCM */
|
||||
PCM8 = 5, /* 8bit PCM */
|
||||
SDX2 = 6, /* SDX2 (3D0 games) */
|
||||
DVI_IMA = 7, /* DVI IMA ADPCM */
|
||||
MPEG = 8, /* MPEG (MP3) */
|
||||
IMA = 9, /* IMA ADPCM */
|
||||
AICA = 10, /* AICA ADPCM (dreamcast) */
|
||||
MSADPCM = 11, /* MS ADPCM (windows) */
|
||||
NGC_DSP = 12, /* NGC DSP (GC) */
|
||||
PCM8_U_int = 13, /* 8bit unsigned PCM (interleaved) */
|
||||
PSX_bf = 14, /* PSX ADPCM bad flagged */
|
||||
MS_IMA = 15, /* Microsoft IMA ADPCM */
|
||||
PCM8_U = 16, /* 8bit unsigned PCM */
|
||||
APPLE_IMA4 = 17, /* Apple Quicktime 4-bit IMA ADPCM */
|
||||
ATRAC3 = 18, /* raw ATRAC3 */
|
||||
ATRAC3PLUS = 19, /* raw ATRAC3PLUS */
|
||||
XMA1 = 20, /* raw XMA1 */
|
||||
XMA2 = 21, /* raw XMA2 */
|
||||
FFMPEG = 22, /* any headered FFmpeg format */
|
||||
AC3 = 23, /* AC3/SPDIF */
|
||||
PCFX = 24, /* PC-FX ADPCM */
|
||||
PCM4 = 25, /* 4bit signed PCM */
|
||||
PCM4_U = 26, /* 4bit unsigned PCM */
|
||||
PSX = 0, /* PS-ADPCM */
|
||||
XBOX = 1, /* XBOX IMA ADPCM */
|
||||
NGC_DTK = 2, /* NGC ADP/DTK ADPCM */
|
||||
PCM16BE = 3, /* 16-bit big endian PCM */
|
||||
PCM16LE = 4, /* 16-bit little endian PCM */
|
||||
PCM8 = 5, /* 8-bit PCM */
|
||||
SDX2 = 6, /* SDX2 (3D0 games) */
|
||||
DVI_IMA = 7, /* DVI IMA ADPCM (high nibble first) */
|
||||
MPEG = 8, /* MPEG (MP3) */
|
||||
IMA = 9, /* IMA ADPCM (low nibble first) */
|
||||
AICA = 10, /* AICA ADPCM (Dreamcast games) */
|
||||
MSADPCM = 11, /* MS ADPCM (Windows games) */
|
||||
NGC_DSP = 12, /* NGC DSP (Nintendo games) */
|
||||
PCM8_U_int = 13, /* 8-bit unsigned PCM (interleaved) */
|
||||
PSX_bf = 14, /* PS-ADPCM with bad flags */
|
||||
MS_IMA = 15, /* Microsoft IMA ADPCM */
|
||||
PCM8_U = 16, /* 8-bit unsigned PCM */
|
||||
APPLE_IMA4 = 17, /* Apple Quicktime 4-bit IMA ADPCM */
|
||||
ATRAC3 = 18, /* Raw ATRAC3 */
|
||||
ATRAC3PLUS = 19, /* Raw ATRAC3PLUS */
|
||||
XMA1 = 20, /* Raw XMA1 */
|
||||
XMA2 = 21, /* Raw XMA2 */
|
||||
FFMPEG = 22, /* Any headered FFmpeg format */
|
||||
AC3 = 23, /* AC3/SPDIF */
|
||||
PCFX = 24, /* PC-FX ADPCM */
|
||||
PCM4 = 25, /* 4-bit signed PCM (3rd and 4th gen games) */
|
||||
PCM4_U = 26, /* 4-bit unsigned PCM (3rd and 4th gen games) */
|
||||
OKI16 = 27, /* OKI ADPCM with 16-bit output (unlike OKI/VOX/Dialogic ADPCM's 12-bit) */
|
||||
} genh_type;
|
||||
|
||||
typedef struct {
|
||||
@ -118,6 +119,7 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
|
||||
case PCFX: coding = coding_PCFX; break;
|
||||
case PCM4: coding = coding_PCM4; break;
|
||||
case PCM4_U: coding = coding_PCM4_U; break;
|
||||
case OKI16: coding = coding_OKI16; break;
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
@ -204,6 +206,10 @@ VGMSTREAM * init_vgmstream_genh(STREAMFILE *streamFile) {
|
||||
vgmstream->codec_config = genh.codec_mode;
|
||||
break;
|
||||
|
||||
case coding_OKI16:
|
||||
vgmstream->layout_type = layout_none;
|
||||
break;
|
||||
|
||||
case coding_MS_IMA:
|
||||
if (!genh.interleave) goto fail; /* creates garbage */
|
||||
|
||||
|
@ -6,33 +6,34 @@
|
||||
|
||||
/* known TXTH types */
|
||||
typedef enum {
|
||||
PSX = 0, /* PSX ADPCM */
|
||||
XBOX = 1, /* XBOX IMA ADPCM */
|
||||
NGC_DTK = 2, /* NGC ADP/DTK ADPCM */
|
||||
PCM16BE = 3, /* 16bit big endian PCM */
|
||||
PCM16LE = 4, /* 16bit little endian PCM */
|
||||
PCM8 = 5, /* 8bit PCM */
|
||||
SDX2 = 6, /* SDX2 (3D0 games) */
|
||||
DVI_IMA = 7, /* DVI IMA ADPCM */
|
||||
MPEG = 8, /* MPEG (MP3) */
|
||||
IMA = 9, /* IMA ADPCM */
|
||||
AICA = 10, /* AICA ADPCM (dreamcast) */
|
||||
MSADPCM = 11, /* MS ADPCM (windows) */
|
||||
NGC_DSP = 12, /* NGC DSP (GC) */
|
||||
PCM8_U_int = 13, /* 8bit unsigned PCM (interleaved) */
|
||||
PSX_bf = 14, /* PSX ADPCM bad flagged */
|
||||
MS_IMA = 15, /* Microsoft IMA ADPCM */
|
||||
PCM8_U = 16, /* 8bit unsigned PCM */
|
||||
APPLE_IMA4 = 17, /* Apple Quicktime 4-bit IMA ADPCM */
|
||||
ATRAC3 = 18, /* raw ATRAC3 */
|
||||
ATRAC3PLUS = 19, /* raw ATRAC3PLUS */
|
||||
XMA1 = 20, /* raw XMA1 */
|
||||
XMA2 = 21, /* raw XMA2 */
|
||||
FFMPEG = 22, /* any headered FFmpeg format */
|
||||
AC3 = 23, /* AC3/SPDIF */
|
||||
PCFX = 24, /* PC-FX ADPCM */
|
||||
PCM4 = 25, /* 4bit signed PCM */
|
||||
PCM4_U = 26, /* 4bit unsigned PCM */
|
||||
PSX = 0, /* PS-ADPCM */
|
||||
XBOX = 1, /* XBOX IMA ADPCM */
|
||||
NGC_DTK = 2, /* NGC ADP/DTK ADPCM */
|
||||
PCM16BE = 3, /* 16-bit big endian PCM */
|
||||
PCM16LE = 4, /* 16-bit little endian PCM */
|
||||
PCM8 = 5, /* 8-bit PCM */
|
||||
SDX2 = 6, /* SDX2 (3D0 games) */
|
||||
DVI_IMA = 7, /* DVI IMA ADPCM (high nibble first) */
|
||||
MPEG = 8, /* MPEG (MP3) */
|
||||
IMA = 9, /* IMA ADPCM (low nibble first) */
|
||||
AICA = 10, /* AICA ADPCM (Dreamcast games) */
|
||||
MSADPCM = 11, /* MS ADPCM (Windows games) */
|
||||
NGC_DSP = 12, /* NGC DSP (Nintendo games) */
|
||||
PCM8_U_int = 13, /* 8-bit unsigned PCM (interleaved) */
|
||||
PSX_bf = 14, /* PS-ADPCM with bad flags */
|
||||
MS_IMA = 15, /* Microsoft IMA ADPCM */
|
||||
PCM8_U = 16, /* 8-bit unsigned PCM */
|
||||
APPLE_IMA4 = 17, /* Apple Quicktime 4-bit IMA ADPCM */
|
||||
ATRAC3 = 18, /* Raw ATRAC3 */
|
||||
ATRAC3PLUS = 19, /* Raw ATRAC3PLUS */
|
||||
XMA1 = 20, /* Raw XMA1 */
|
||||
XMA2 = 21, /* Raw XMA2 */
|
||||
FFMPEG = 22, /* Any headered FFmpeg format */
|
||||
AC3 = 23, /* AC3/SPDIF */
|
||||
PCFX = 24, /* PC-FX ADPCM */
|
||||
PCM4 = 25, /* 4-bit signed PCM (3rd and 4th gen games) */
|
||||
PCM4_U = 26, /* 4-bit unsigned PCM (3rd and 4th gen games) */
|
||||
OKI16 = 27, /* OKI ADPCM with 16-bit output (unlike OKI/VOX/Dialogic ADPCM's 12-bit) */
|
||||
} txth_type;
|
||||
|
||||
typedef struct {
|
||||
@ -180,6 +181,7 @@ VGMSTREAM * init_vgmstream_txth(STREAMFILE *streamFile) {
|
||||
case PCFX: coding = coding_PCFX; break;
|
||||
case PCM4: coding = coding_PCM4; break;
|
||||
case PCM4_U: coding = coding_PCM4_U; break;
|
||||
case OKI16: coding = coding_OKI16; break;
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
@ -280,6 +282,10 @@ VGMSTREAM * init_vgmstream_txth(STREAMFILE *streamFile) {
|
||||
vgmstream->codec_config = txth.codec_mode;
|
||||
break;
|
||||
|
||||
case coding_OKI16:
|
||||
vgmstream->layout_type = layout_none;
|
||||
break;
|
||||
|
||||
case coding_MS_IMA:
|
||||
if (!txth.interleave) goto fail; /* creates garbage */
|
||||
|
||||
@ -614,6 +620,7 @@ static int parse_keyval(STREAMFILE * streamFile_, txth_header * txth, const char
|
||||
else if (0==strcmp(val,"PCFX")) txth->codec = PCFX;
|
||||
else if (0==strcmp(val,"PCM4")) txth->codec = PCM4;
|
||||
else if (0==strcmp(val,"PCM4_U")) txth->codec = PCM4_U;
|
||||
else if (0==strcmp(val,"OKI16")) txth->codec = OKI16;
|
||||
else goto fail;
|
||||
}
|
||||
else if (0==strcmp(key,"codec_mode")) {
|
||||
@ -972,7 +979,8 @@ static int get_bytes_to_samples(txth_header * txth, uint32_t bytes) {
|
||||
case AICA:
|
||||
return aica_bytes_to_samples(bytes, txth->channels);
|
||||
case PCFX:
|
||||
return pcfx_bytes_to_samples(bytes, txth->channels);
|
||||
case OKI16:
|
||||
return oki_bytes_to_samples(bytes, txth->channels);
|
||||
|
||||
/* untested */
|
||||
case SDX2:
|
||||
|
@ -1142,6 +1142,7 @@ int get_vgmstream_samples_per_frame(VGMSTREAM * vgmstream) {
|
||||
case coding_SNDS_IMA:
|
||||
case coding_OTNS_IMA:
|
||||
case coding_UBI_IMA:
|
||||
case coding_OKI16:
|
||||
return 1;
|
||||
case coding_IMA_int:
|
||||
case coding_DVI_IMA_int:
|
||||
@ -1325,6 +1326,7 @@ int get_vgmstream_frame_size(VGMSTREAM * vgmstream) {
|
||||
case coding_ALP_IMA:
|
||||
case coding_FFTA2_IMA:
|
||||
case coding_PCFX:
|
||||
case coding_OKI16:
|
||||
return 0x01;
|
||||
case coding_MS_IMA:
|
||||
case coding_RAD_IMA:
|
||||
@ -2050,6 +2052,12 @@ void decode_vgmstream(VGMSTREAM * vgmstream, int samples_written, int samples_to
|
||||
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, vgmstream->codec_config);
|
||||
}
|
||||
break;
|
||||
case coding_OKI16:
|
||||
for (ch = 0; ch < vgmstream->channels; ch++) {
|
||||
decode_oki16(&vgmstream->ch[ch],buffer+samples_written*vgmstream->channels+ch,
|
||||
vgmstream->channels,vgmstream->samples_into_block,samples_to_do, ch);
|
||||
}
|
||||
break;
|
||||
|
||||
case coding_EA_MT:
|
||||
for (ch = 0; ch < vgmstream->channels; ch++) {
|
||||
|
@ -153,6 +153,7 @@ typedef enum {
|
||||
coding_ASF, /* Argonaut ASF 4-bit ADPCM */
|
||||
coding_XMD, /* Konami XMD 4-bit ADPCM */
|
||||
coding_PCFX, /* PC-FX 4-bit ADPCM */
|
||||
coding_OKI16, /* OKI 4-bit ADPCM with 16-bit output */
|
||||
|
||||
/* others */
|
||||
coding_SDX2, /* SDX2 2:1 Squareroot-Delta-Exact compression DPCM */
|
||||
|
Loading…
x
Reference in New Issue
Block a user