Add .kno extension [Ciel Nosurge DX (Switch)]

This commit is contained in:
bnnm 2021-03-04 22:28:38 +01:00
parent 9712fc1809
commit ba59200b9a
2 changed files with 33 additions and 31 deletions

View File

@ -251,6 +251,7 @@ static const char* extension_list[] = {
"kcey", //fake extension/header id for .pcm (renamed, to be removed)
"km9",
"kovs", //fake extension/header id for .kvs
"kno",
"kns",
"kraw",
"ktac",

View File

@ -1,44 +1,45 @@
#include "meta.h"
#include "../coding/coding.h"
VGMSTREAM * init_vgmstream_ktss(STREAMFILE *streamFile) {
VGMSTREAM * vgmstream = NULL;
int loop_flag, channel_count, sample_rate;
int8_t version, num_layers, codec_id;
VGMSTREAM* init_vgmstream_ktss(STREAMFILE* sf) {
VGMSTREAM* vgmstream = NULL;
int loop_flag, channels, sample_rate;
int8_t version, tracks, codec_id;
int32_t num_samples, loop_start, loop_length, coef_offset, coef_spacing;
off_t start_offset;
size_t data_size, skip = 0;
if (!check_extensions(streamFile, "kns,ktss"))
/* checks */
/* .kns: Atelier Lydie & Suelle: The Alchemists and the Mysterious Paintings (Switch)
* .kno: Ciel Nosurge DX (Switch)
* .ktss: header id */
if (!check_extensions(sf, "kns,kno,ktss"))
goto fail;
if (read_32bitBE(0x00, streamFile) != 0x4B545353) /* "KTSS" */
if (is_id32be(0x00,sf, "KTSS"))
goto fail;
/* 0x04: data size */
codec_id = read_8bit(0x20, streamFile);
codec_id = read_u8(0x20, sf);
/* 0x01: null, part of codec? */
version = read_8bit(0x22, streamFile);
version = read_u8(0x22, sf);
/* 0x03: same as version? */
start_offset = read_32bitLE(0x24, streamFile) + 0x20;
start_offset = read_u32le(0x24, sf) + 0x20;
// A layered stream/track model seems to be used in Hyrule Warriors (Switch).
// It's also present in other Koei Tecmo KNS but the channel count was always
// explicitly defined in the 0x29 byte and the number of layers was set to 1.
// Here, 10 channel files are set up with 2 channels in 5 layers.
// Super hacky on KT's part and ours to implement but it works.
num_layers = read_8bit(0x28, streamFile);
channel_count = read_8bit(0x29, streamFile) * num_layers;
sample_rate = read_32bitLE(0x2c, streamFile);
/* Layered tracks used in Hyrule Warriors (Switch), like 2*5 = 10 channels
* Other games typically use 1 track. */
tracks = read_u8(0x28, sf);
channels = read_u8(0x29, sf) * tracks;
sample_rate = read_u32le(0x2c, sf);
num_samples = read_32bitLE(0x30, streamFile);
loop_start = read_32bitLE(0x34, streamFile);
loop_length = read_32bitLE(0x38, streamFile);
num_samples = read_s32le(0x30, sf);
loop_start = read_s32le(0x34, sf);
loop_length = read_s32le(0x38, sf);
loop_flag = loop_length > 0;
/* build the VGMSTREAM */
vgmstream = allocate_vgmstream(channel_count, loop_flag);
vgmstream = allocate_vgmstream(channels, loop_flag);
if (!vgmstream) goto fail;
vgmstream->sample_rate = sample_rate;
@ -64,32 +65,32 @@ VGMSTREAM * init_vgmstream_ktss(STREAMFILE *streamFile) {
vgmstream->coding_type = coding_NGC_DSP;
vgmstream->layout_type = layout_interleave;
vgmstream->interleave_block_size = 0x8;
dsp_read_coefs_le(vgmstream, streamFile, coef_offset, coef_spacing);
dsp_read_coefs_le(vgmstream, sf, coef_offset, coef_spacing);
break;
#ifdef VGM_USE_FFMPEG
case 0x9: { /* Opus - Dead or Alive Xtreme 3: Scarlet, Fire Emblem: Three Houses */
opus_config cfg = {0};
start_offset = read_32bitLE(0x40, streamFile); /* after seek table, if any */
data_size = read_32bitLE(0x44, streamFile);
start_offset = read_u32le(0x40, sf); /* after seek table, if any */
data_size = read_u32le(0x44, sf);
/* 0x48: seek table start (0 if no seek table) */
/* 0x4c: number of frames */
/* 0x50: frame size, or 0 if VBR */
/* 0x52: samples per frame */
/* 0x54: sample rate */
cfg.skip = read_32bitLE(0x58, streamFile);
cfg.skip = read_s32le(0x58, sf);
cfg.sample_rate = vgmstream->sample_rate;
cfg.channels = vgmstream->channels;
/* this info seems always included even for stereo streams */
if (vgmstream->channels <= 8) {
int i;
cfg.stream_count = read_8bit(0x5a,streamFile);
cfg.coupled_count = read_8bit(0x5b,streamFile);
cfg.stream_count = read_u8(0x5a,sf);
cfg.coupled_count = read_u8(0x5b,sf);
for (i = 0; i < vgmstream->channels; i++) {
cfg.channel_mapping[i] = read_8bit(0x5c + i,streamFile);
cfg.channel_mapping[i] = read_u8(0x5c + i,sf);
}
}
@ -97,7 +98,7 @@ VGMSTREAM * init_vgmstream_ktss(STREAMFILE *streamFile) {
/* 0x70: seek table (0x02 * frames) if VBR */
/* later games use VBR frames, hence the seek table [Warriors Orochi 4 Ultimate DLC (Switch)] */
vgmstream->codec_data = init_ffmpeg_switch_opus_config(streamFile, start_offset, data_size, &cfg);
vgmstream->codec_data = init_ffmpeg_switch_opus_config(sf, start_offset, data_size, &cfg);
if (!vgmstream->codec_data) goto fail;
vgmstream->coding_type = coding_FFmpeg;
vgmstream->layout_type = layout_none;
@ -115,7 +116,7 @@ VGMSTREAM * init_vgmstream_ktss(STREAMFILE *streamFile) {
break;
}
if (vgmstream->num_samples == 0) {
vgmstream->num_samples = switch_opus_get_samples(start_offset, data_size, streamFile) - skip;
vgmstream->num_samples = switch_opus_get_samples(start_offset, data_size, sf) - skip;
}
break;
}
@ -124,7 +125,7 @@ VGMSTREAM * init_vgmstream_ktss(STREAMFILE *streamFile) {
goto fail;
}
if (!vgmstream_open_stream(vgmstream, streamFile, start_offset))
if (!vgmstream_open_stream(vgmstream, sf, start_offset))
goto fail;
return vgmstream;