mirror of
https://github.com/vgmstream/vgmstream.git
synced 2024-11-28 08:20:54 +01:00
Fix some Sony .bnk [PS Home Arcade (Vita)]
This commit is contained in:
parent
8ae722b9e9
commit
68f6b13683
@ -1,41 +1,38 @@
|
||||
#include <math.h>
|
||||
#include "meta.h"
|
||||
#include "../coding/coding.h"
|
||||
#include "../util/endianness.h"
|
||||
|
||||
typedef enum { PSX, PCM16, ATRAC9, HEVAG } bnk_codec;
|
||||
|
||||
/* .BNK - Sony's Scream Tool bank format [Puyo Puyo Tetris (PS4), NekoBuro: Cats Block (Vita)] */
|
||||
VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
VGMSTREAM* vgmstream = NULL;
|
||||
off_t start_offset, stream_offset, name_offset = 0;
|
||||
size_t stream_size, interleave = 0;
|
||||
off_t sblk_offset, data_offset;
|
||||
size_t data_size;
|
||||
int channel_count = 0, loop_flag, sample_rate, parts, sblk_version, big_endian;
|
||||
uint32_t start_offset, stream_offset, name_offset = 0;
|
||||
uint32_t sblk_offset, data_offset;
|
||||
uint32_t stream_size, data_size, interleave = 0;
|
||||
int channels = 0, loop_flag, sample_rate, parts, sblk_version, big_endian;
|
||||
int loop_start = 0, loop_end = 0;
|
||||
uint32_t pitch, flags;
|
||||
uint32_t atrac9_info = 0;
|
||||
|
||||
int total_subsongs, target_subsong = sf->stream_index;
|
||||
int32_t (*read_32bit)(off_t,STREAMFILE*) = NULL;
|
||||
int16_t (*read_16bit)(off_t,STREAMFILE*) = NULL;
|
||||
float (*read_f32)(off_t,STREAMFILE*) = NULL;
|
||||
read_u16_t read_u16;
|
||||
read_u32_t read_u32;
|
||||
read_f32_t read_f32;
|
||||
bnk_codec codec;
|
||||
|
||||
|
||||
/* checks */
|
||||
if (!check_extensions(sf, "bnk"))
|
||||
goto fail;
|
||||
|
||||
/* bnk version */
|
||||
if (read_32bitBE(0x00,sf) == 0x00000003) { /* PS3 */
|
||||
read_32bit = read_32bitBE;
|
||||
read_16bit = read_16bitBE;
|
||||
if (read_u32be(0x00,sf) == 0x03) { /* PS3 */
|
||||
read_u32 = read_u32be;
|
||||
read_u16 = read_u16be;
|
||||
read_f32 = read_f32be;
|
||||
big_endian = 1;
|
||||
}
|
||||
else if (read_32bitBE(0x00,sf) == 0x03000000) { /* PS2/Vita/PS4 */
|
||||
read_32bit = read_32bitLE;
|
||||
read_16bit = read_16bitLE;
|
||||
else if (read_u32le(0x00,sf) == 0x03) { /* PS2/Vita/PS4 */
|
||||
read_u32 = read_u32le;
|
||||
read_u16 = read_u16le;
|
||||
read_f32 = read_f32le;
|
||||
big_endian = 0;
|
||||
}
|
||||
@ -43,13 +40,18 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
parts = read_32bit(0x04,sf);
|
||||
/* checks */
|
||||
if (!check_extensions(sf, "bnk"))
|
||||
goto fail;
|
||||
|
||||
|
||||
parts = read_u32(0x04,sf);
|
||||
if (parts < 2 || parts > 3) goto fail;
|
||||
|
||||
sblk_offset = read_32bit(0x08,sf);
|
||||
sblk_offset = read_u32(0x08,sf);
|
||||
/* 0x0c: sklb size */
|
||||
data_offset = read_32bit(0x10,sf);
|
||||
data_size = read_32bit(0x14,sf);
|
||||
data_offset = read_u32(0x10,sf);
|
||||
data_size = read_u32(0x14,sf);
|
||||
/* when sblk_offset >= 0x20: */
|
||||
/* 0x18: ZLSD small footer, rare [Yakuza 6's Puyo Puyo (PS4)] */
|
||||
/* 0x1c: ZLSD size */
|
||||
@ -60,30 +62,30 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
|
||||
|
||||
/* SBlk part: parse header */
|
||||
if (read_32bit(sblk_offset+0x00,sf) != 0x6B6C4253) /* "klBS" (SBlk = sample block?) */
|
||||
if (read_u32(sblk_offset+0x00,sf) != get_id32be("klBS")) /* SBlk = sample block? */
|
||||
goto fail;
|
||||
sblk_version = read_32bit(sblk_offset+0x04,sf);
|
||||
sblk_version = read_u32(sblk_offset+0x04,sf);
|
||||
/* 0x08: possibly when sblk_version=0x0d, 0x03=Vita, 0x06=PS4 */
|
||||
//;VGM_LOG("BNK: sblk_offset=%lx, data_offset=%lx, sblk_version %x\n", sblk_offset, data_offset, sblk_version);
|
||||
|
||||
{
|
||||
int i;
|
||||
off_t table1_offset, table2_offset, table3_offset, table4_offset;
|
||||
size_t section_entries, material_entries, stream_entries;
|
||||
size_t table1_entry_size;
|
||||
off_t table1_suboffset, table2_suboffset;
|
||||
off_t table2_entry_offset = 0, table3_entry_offset = 0;
|
||||
uint32_t table1_offset, table2_offset, table3_offset, table4_offset;
|
||||
uint32_t section_entries, material_entries, stream_entries;
|
||||
uint32_t table1_entry_size;
|
||||
uint32_t table1_suboffset, table2_suboffset;
|
||||
uint32_t table2_entry_offset = 0, table3_entry_offset = 0;
|
||||
int table4_entry_id = -1;
|
||||
off_t table4_entries_offset, table4_names_offset;
|
||||
uint32_t table4_entries_offset, table4_names_offset;
|
||||
|
||||
|
||||
switch(sblk_version) {
|
||||
case 0x01: /* Ratchet & Clank (PS2) */
|
||||
section_entries = (uint16_t)read_16bit(sblk_offset+0x16,sf); /* entry size: ~0x0c */
|
||||
material_entries = (uint16_t)read_16bit(sblk_offset+0x18,sf); /* entry size: ~0x28 */
|
||||
stream_entries = (uint16_t)read_16bit(sblk_offset+0x1a,sf); /* entry size: none (count) */
|
||||
table1_offset = sblk_offset + read_32bit(sblk_offset+0x1c,sf);
|
||||
table2_offset = sblk_offset + read_32bit(sblk_offset+0x20,sf);
|
||||
section_entries = read_u16(sblk_offset+0x16,sf); /* entry size: ~0x0c */
|
||||
material_entries = read_u16(sblk_offset+0x18,sf); /* entry size: ~0x28 */
|
||||
stream_entries = read_u16(sblk_offset+0x1a,sf); /* entry size: none (count) */
|
||||
table1_offset = sblk_offset + read_u32(sblk_offset+0x1c,sf);
|
||||
table2_offset = sblk_offset + read_u32(sblk_offset+0x20,sf);
|
||||
table3_offset = table2_offset; /* mixed table in this version */
|
||||
table4_offset = 0; /* not included */
|
||||
|
||||
@ -95,14 +97,15 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
case 0x03: /* Yu-Gi-Oh! GX - The Beginning of Destiny (PS2) */
|
||||
case 0x04: /* Test banks */
|
||||
case 0x05: /* Ratchet & Clank (PS3) */
|
||||
case 0x08: /* Playstation Home Arcade (Vita) */
|
||||
case 0x09: /* Puyo Puyo Tetris (PS4) */
|
||||
section_entries = (uint16_t)read_16bit(sblk_offset+0x16,sf); /* entry size: ~0x0c */
|
||||
material_entries = (uint16_t)read_16bit(sblk_offset+0x18,sf); /* entry size: ~0x08 */
|
||||
stream_entries = (uint16_t)read_16bit(sblk_offset+0x1a,sf); /* entry size: ~0x18 + variable */
|
||||
table1_offset = sblk_offset + read_32bit(sblk_offset+0x1c,sf);
|
||||
table2_offset = sblk_offset + read_32bit(sblk_offset+0x20,sf);
|
||||
table3_offset = sblk_offset + read_32bit(sblk_offset+0x34,sf);
|
||||
table4_offset = sblk_offset + read_32bit(sblk_offset+0x38,sf);
|
||||
section_entries = read_u16(sblk_offset+0x16,sf); /* entry size: ~0x0c */
|
||||
material_entries = read_u16(sblk_offset+0x18,sf); /* entry size: ~0x08 */
|
||||
stream_entries = read_u16(sblk_offset+0x1a,sf); /* entry size: ~0x18 + variable */
|
||||
table1_offset = sblk_offset + read_u32(sblk_offset+0x1c,sf);
|
||||
table2_offset = sblk_offset + read_u32(sblk_offset+0x20,sf);
|
||||
table3_offset = sblk_offset + read_u32(sblk_offset+0x34,sf);
|
||||
table4_offset = sblk_offset + read_u32(sblk_offset+0x38,sf);
|
||||
|
||||
table1_entry_size = 0x0c;
|
||||
table1_suboffset = 0x08;
|
||||
@ -111,13 +114,13 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
|
||||
case 0x0d: /* Polara (Vita), Crypt of the Necrodancer (Vita) */
|
||||
case 0x0e: /* Yakuza 6's Puyo Puyo (PS4) */
|
||||
table1_offset = sblk_offset + read_32bit(sblk_offset+0x18,sf);
|
||||
table2_offset = sblk_offset + read_32bit(sblk_offset+0x1c,sf);
|
||||
table3_offset = sblk_offset + read_32bit(sblk_offset+0x2c,sf);
|
||||
table4_offset = sblk_offset + read_32bit(sblk_offset+0x30,sf);
|
||||
section_entries = (uint16_t)read_16bit(sblk_offset+0x38,sf); /* entry size: ~0x24 */
|
||||
material_entries = (uint16_t)read_16bit(sblk_offset+0x3a,sf); /* entry size: ~0x08 */
|
||||
stream_entries = (uint16_t)read_16bit(sblk_offset+0x3c,sf); /* entry size: ~0x5c + variable */
|
||||
table1_offset = sblk_offset + read_u32(sblk_offset+0x18,sf);
|
||||
table2_offset = sblk_offset + read_u32(sblk_offset+0x1c,sf);
|
||||
table3_offset = sblk_offset + read_u32(sblk_offset+0x2c,sf);
|
||||
table4_offset = sblk_offset + read_u32(sblk_offset+0x30,sf);
|
||||
section_entries = read_u16(sblk_offset+0x38,sf); /* entry size: ~0x24 */
|
||||
material_entries = read_u16(sblk_offset+0x3a,sf); /* entry size: ~0x08 */
|
||||
stream_entries = read_u16(sblk_offset+0x3c,sf); /* entry size: ~0x5c + variable */
|
||||
|
||||
table1_entry_size = 0x24;
|
||||
table1_suboffset = 0x0c;
|
||||
@ -125,11 +128,11 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
break;
|
||||
|
||||
default:
|
||||
VGM_LOG("BNK: unknown version %x\n", sblk_version);
|
||||
vgm_logi("BNK: unknown version %x (report)\n", sblk_version);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
//;VGM_LOG("BNK: table offsets=%lx, %lx, %lx, %lx\n", table1_offset,table2_offset,table3_offset,table4_offset);
|
||||
//;VGM_LOG("BNK: table offsets=%x, %x, %x, %x\n", table1_offset,table2_offset,table3_offset,table4_offset);
|
||||
//;VGM_LOG("BNK: table entries=%i, %i, %i\n", section_entries,material_entries,stream_entries);
|
||||
|
||||
|
||||
@ -159,7 +162,7 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
*/
|
||||
|
||||
for (i = 0; i < material_entries; i++) {
|
||||
uint8_t table2_type = read_32bit(table2_offset + (i*0x28) + 0x00, sf);
|
||||
uint32_t table2_type = read_u32(table2_offset + (i*0x28) + 0x00, sf);
|
||||
|
||||
if (table2_type != 0x01)
|
||||
continue;
|
||||
@ -179,7 +182,7 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
for (i = 0; i < material_entries; i++) {
|
||||
uint32_t table2_value, table2_subinfo, table2_subtype;
|
||||
|
||||
table2_value = (uint32_t)read_32bit(table2_offset+(i*0x08)+table2_suboffset+0x00,sf);
|
||||
table2_value = read_u32(table2_offset+(i*0x08)+table2_suboffset+0x00,sf);
|
||||
table2_subinfo = (table2_value >> 0) & 0xFFFF;
|
||||
table2_subtype = (table2_value >> 16) & 0xFFFF;
|
||||
if (table2_subtype != 0x100)
|
||||
@ -214,54 +217,31 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
case 0x03:
|
||||
case 0x04:
|
||||
case 0x05:
|
||||
case 0x08:
|
||||
case 0x09:
|
||||
pitch = (uint8_t)read_8bit(table3_offset+table3_entry_offset+0x02,sf);
|
||||
flags = (uint8_t)read_8bit(table3_offset+table3_entry_offset+0x0f,sf);
|
||||
stream_offset = read_32bit(table3_offset+table3_entry_offset+0x10,sf);
|
||||
stream_size = read_32bit(table3_offset+table3_entry_offset+0x14,sf);
|
||||
pitch = read_u8(table3_offset+table3_entry_offset+0x02,sf);
|
||||
flags = read_u8(table3_offset+table3_entry_offset+0x0f,sf);
|
||||
stream_offset = read_u32(table3_offset+table3_entry_offset+0x10,sf);
|
||||
stream_size = read_u32(table3_offset+table3_entry_offset+0x14,sf);
|
||||
|
||||
/* must use some log/formula but whatevs */
|
||||
switch(pitch) {
|
||||
case 0xC6: sample_rate = 50000; break; //?
|
||||
case 0xC4: sample_rate = 48000; break;
|
||||
case 0xC3: sample_rate = 46000; break; //?
|
||||
case 0xC2: sample_rate = 44100; break;
|
||||
case 0xBC: sample_rate = 36000; break; //?
|
||||
case 0xBA: sample_rate = 32000; break; //?
|
||||
case 0xB9: sample_rate = 30000; break; //?
|
||||
case 0xB8: sample_rate = 28000; break; //?
|
||||
case 0xB6: sample_rate = 22050; break;
|
||||
case 0xB4: sample_rate = 18000; break; //?
|
||||
case 0xB2: sample_rate = 16000; break; //?
|
||||
case 0xB0: sample_rate = 15000; break; //?
|
||||
case 0xAF: sample_rate = 14000; break; //?
|
||||
case 0xAE: sample_rate = 13000; break; //?
|
||||
case 0xAD: sample_rate = 12500; break; //?
|
||||
case 0xAC: sample_rate = 12000; break; //?
|
||||
case 0xAB: sample_rate = 11050; break; //?
|
||||
case 0xAA: sample_rate = 11025; break;
|
||||
case 0xA9: sample_rate = 10000; break; //?
|
||||
case 0xA8: sample_rate = 9000; break; //?
|
||||
case 0xA7: sample_rate = 8000; break; //?
|
||||
case 0xA6: sample_rate = 7000; break; //?
|
||||
case 0xA5: sample_rate = 6500; break; //?
|
||||
case 0xA4: sample_rate = 6000; break; //?
|
||||
case 0xA3: sample_rate = 5800; break; //?
|
||||
case 0xA2: sample_rate = 5400; break; //?
|
||||
case 0xA1: sample_rate = 5000; break; //?
|
||||
case 0x9d: sample_rate = 4000; break; //?
|
||||
case 0x9c: sample_rate = 3500; break; //?
|
||||
default:
|
||||
VGM_LOG("BNK: unknown pitch %x\n", pitch);
|
||||
goto fail;
|
||||
/* approximate note-to-hz, not sure about real formula (observed from 0x9a to 0xc6)
|
||||
* using (rate) * 2 ^ ((pitch - note) / 12) but not correct? (may be rounded) */
|
||||
sample_rate = 614.0 * pow(2.0, (float)(pitch - 0x70) / 12.0);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0d:
|
||||
case 0x0e:
|
||||
flags = (uint8_t)read_8bit(table3_offset+table3_entry_offset+0x12,sf);
|
||||
stream_offset = read_32bit(table3_offset+table3_entry_offset+0x44,sf);
|
||||
stream_size = read_32bit(table3_offset+table3_entry_offset+0x48,sf);
|
||||
flags = read_u8 (table3_offset+table3_entry_offset+0x12,sf);
|
||||
stream_offset = read_u32(table3_offset+table3_entry_offset+0x44,sf);
|
||||
stream_size = read_u32(table3_offset+table3_entry_offset+0x48,sf);
|
||||
sample_rate = (int)read_f32(table3_offset+table3_entry_offset+0x4c,sf);
|
||||
break;
|
||||
|
||||
@ -275,12 +255,13 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
switch(sblk_version) {
|
||||
//case 0x03: /* different format? */
|
||||
//case 0x04: /* different format? */
|
||||
case 0x08:
|
||||
case 0x09:
|
||||
case 0x0d:
|
||||
case 0x0e:
|
||||
/* find if this sound has an assigned name in table1 */
|
||||
for (i = 0; i < section_entries; i++) {
|
||||
off_t entry_offset = (uint16_t)read_16bit(table1_offset+(i*table1_entry_size)+table1_suboffset+0x00,sf);
|
||||
uint32_t entry_offset = read_u16(table1_offset+(i*table1_entry_size)+table1_suboffset+0x00,sf);
|
||||
|
||||
/* rarely (ex. Polara sfx) one name applies to multiple materials,
|
||||
* from current entry_offset to next entry_offset (section offsets should be in order) */
|
||||
@ -296,15 +277,15 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
/* 0x0c: table4 size */
|
||||
/* variable: entries */
|
||||
/* variable: names (null terminated) */
|
||||
table4_entries_offset = table4_offset + read_32bit(table4_offset+0x08, sf);
|
||||
table4_entries_offset = table4_offset + read_u32(table4_offset+0x08, sf);
|
||||
table4_names_offset = table4_entries_offset + (0x10*section_entries);
|
||||
//;VGM_LOG("BNK: t4_entries=%lx, t4_names=%lx\n", table4_entries_offset, table4_names_offset);
|
||||
|
||||
/* get assigned name from table4 names */
|
||||
for (i = 0; i < section_entries; i++) {
|
||||
int entry_id = read_32bit(table4_entries_offset+(i*0x10)+0x0c, sf);
|
||||
int entry_id = read_u32(table4_entries_offset+(i*0x10)+0x0c, sf);
|
||||
if (entry_id == table4_entry_id) {
|
||||
name_offset = table4_names_offset + read_32bit(table4_entries_offset+(i*0x10)+0x00, sf);
|
||||
name_offset = table4_names_offset + read_u32(table4_entries_offset+(i*0x10)+0x00, sf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -329,24 +310,24 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
case 0x03:
|
||||
case 0x04:
|
||||
case 0x05:
|
||||
channel_count = 1;
|
||||
channels = 1;
|
||||
|
||||
/* early versions don't have PS-ADPCM size, could check next offset but it's all kind of loopy */
|
||||
if (sblk_version <= 0x03 && stream_size == 0 && (flags & 0x80) == 0) {
|
||||
off_t offset;
|
||||
off_t max_offset = get_streamfile_size(sf);
|
||||
uint32_t offset;
|
||||
uint32_t max_offset = get_streamfile_size(sf);
|
||||
|
||||
stream_size += 0x10;
|
||||
for (offset = data_offset + stream_offset + 0x10; offset < max_offset; offset += 0x10) {
|
||||
|
||||
/* beginning frame (if file loops won't have end frame) */
|
||||
if (read_32bitBE(offset + 0x00, sf) == 0x00000000 && read_32bitBE(offset + 0x04, sf) == 0x00000000)
|
||||
if (read_u32be(offset + 0x00, sf) == 0x00000000 && read_u32be(offset + 0x04, sf) == 0x00000000)
|
||||
break;
|
||||
|
||||
stream_size += 0x10;
|
||||
|
||||
/* end frame */
|
||||
if (read_32bitBE(offset + 0x00, sf) == 0x00077777 && read_32bitBE(offset + 0x04, sf) == 0x77777777)
|
||||
if (read_u32be(offset + 0x00, sf) == 0x00077777 && read_u32be(offset + 0x04, sf) == 0x77777777)
|
||||
break;
|
||||
}
|
||||
|
||||
@ -356,17 +337,17 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
|
||||
/* hack for PS3 files that use dual subsongs as stereo */
|
||||
if (total_subsongs == 2 && stream_size * 2 == data_size) {
|
||||
channel_count = 2;
|
||||
stream_size = stream_size*channel_count;
|
||||
channels = 2;
|
||||
stream_size = stream_size*channels;
|
||||
total_subsongs = 1;
|
||||
}
|
||||
interleave = stream_size / channel_count;
|
||||
interleave = stream_size / channels;
|
||||
|
||||
if (flags & 0x80) {
|
||||
codec = PCM16; /* rare [Wipeout HD (PS3)] */
|
||||
if ((flags & 0x80) && sblk_version <= 3) { /* PS Home Arcade has other flags? */
|
||||
codec = PCM16; /* rare [Wipeout HD (PS3)]-v3 */
|
||||
}
|
||||
else {
|
||||
loop_flag = ps_find_loop_offsets(sf, start_offset, stream_size, channel_count, interleave, &loop_start, &loop_end);
|
||||
loop_flag = ps_find_loop_offsets(sf, start_offset, stream_size, channels, interleave, &loop_start, &loop_end);
|
||||
loop_flag = (flags & 0x40); /* no loops values in sight so may only apply to PS-ADPCM flags */
|
||||
|
||||
codec = PSX;
|
||||
@ -375,54 +356,68 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
//postdata_size = 0x10; /* last frame may be garbage */
|
||||
break;
|
||||
|
||||
case 0x08:
|
||||
case 0x09:
|
||||
type = read_16bit(start_offset+0x00,sf);
|
||||
extradata_size = 0x08 + read_32bit(start_offset+0x04,sf); /* 0x14 for AT9 */
|
||||
type = read_u16(start_offset+0x00,sf);
|
||||
extradata_size = 0x08 + read_u32(start_offset+0x04,sf); /* 0x14 for AT9 */
|
||||
|
||||
switch(type) {
|
||||
case 0x00:
|
||||
channels = 1;
|
||||
codec = PSX;
|
||||
interleave = 0x10;
|
||||
break;
|
||||
|
||||
case 0x01:
|
||||
channels = 1;
|
||||
codec = PCM16;
|
||||
interleave = 0x01;
|
||||
break;
|
||||
|
||||
|
||||
case 0x02: /* ATRAC9 mono */
|
||||
case 0x05: /* ATRAC9 stereo */
|
||||
if (read_32bit(start_offset+0x08,sf) + 0x08 != extradata_size) /* repeat? */
|
||||
if (read_u32(start_offset+0x08,sf) + 0x08 != extradata_size) /* repeat? */
|
||||
goto fail;
|
||||
channel_count = (type == 0x02) ? 1 : 2;
|
||||
channels = (type == 0x02) ? 1 : 2;
|
||||
|
||||
atrac9_info = (uint32_t)read_32bitBE(start_offset+0x0c,sf);
|
||||
atrac9_info = read_u32be(start_offset+0x0c,sf);
|
||||
/* 0x10: null? */
|
||||
loop_length = read_32bit(start_offset+0x14,sf);
|
||||
loop_start = read_32bit(start_offset+0x18,sf);
|
||||
loop_length = read_u32(start_offset+0x14,sf);
|
||||
loop_start = read_u32(start_offset+0x18,sf);
|
||||
loop_end = loop_start + loop_length; /* loop_start is -1 if not set */
|
||||
|
||||
codec = ATRAC9;
|
||||
break;
|
||||
|
||||
default:
|
||||
VGM_LOG("BNK: unknown type %x\n", type);
|
||||
vgm_logi("BNK: unknown type %x (report)\n", type);
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0d:
|
||||
case 0x0e:
|
||||
type = read_16bit(start_offset+0x00,sf);
|
||||
if (read_32bit(start_offset+0x04,sf) != 0x01) /* type? */
|
||||
type = read_u16(start_offset+0x00,sf);
|
||||
if (read_u32(start_offset+0x04,sf) != 0x01) /* type? */
|
||||
goto fail;
|
||||
extradata_size = 0x10 + read_32bit(start_offset+0x08,sf); /* 0x80 for AT9, 0x10 for PCM/PS-ADPCM */
|
||||
extradata_size = 0x10 + read_u32(start_offset+0x08,sf); /* 0x80 for AT9, 0x10 for PCM/PS-ADPCM */
|
||||
/* 0x0c: null? */
|
||||
|
||||
switch(type) {
|
||||
case 0x02: /* ATRAC9 mono */
|
||||
case 0x05: /* ATRAC9 stereo */
|
||||
if (read_32bit(start_offset+0x10,sf) + 0x10 != extradata_size) /* repeat? */
|
||||
if (read_u32(start_offset+0x10,sf) + 0x10 != extradata_size) /* repeat? */
|
||||
goto fail;
|
||||
channel_count = (type == 0x02) ? 1 : 2;
|
||||
channels = (type == 0x02) ? 1 : 2;
|
||||
|
||||
atrac9_info = (uint32_t)read_32bitBE(start_offset+0x14,sf);
|
||||
atrac9_info = read_u32be(start_offset+0x14,sf);
|
||||
/* 0x18: null? */
|
||||
/* 0x1c: channels? */
|
||||
/* 0x20: null? */
|
||||
|
||||
loop_length = read_32bit(start_offset+0x24,sf);
|
||||
loop_start = read_32bit(start_offset+0x28,sf);
|
||||
loop_length = read_u32(start_offset+0x24,sf);
|
||||
loop_start = read_u32(start_offset+0x28,sf);
|
||||
loop_end = loop_start + loop_length; /* loop_start is -1 if not set */
|
||||
|
||||
codec = ATRAC9;
|
||||
@ -431,11 +426,11 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
case 0x01: /* PCM16LE mono? (NekoBuro/Polara sfx) */
|
||||
case 0x04: /* PCM16LE stereo? (NekoBuro/Polara sfx) */
|
||||
/* 0x10: null? */
|
||||
channel_count = read_32bit(start_offset+0x14,sf);
|
||||
channels = read_u32(start_offset+0x14,sf);
|
||||
interleave = 0x02;
|
||||
|
||||
loop_start = read_32bit(start_offset+0x18,sf);
|
||||
loop_length = read_32bit(start_offset+0x1c,sf);
|
||||
loop_start = read_u32(start_offset+0x18,sf);
|
||||
loop_length = read_u32(start_offset+0x1c,sf);
|
||||
loop_end = loop_start + loop_length; /* loop_start is -1 if not set */
|
||||
|
||||
codec = PCM16;
|
||||
@ -443,24 +438,24 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
|
||||
case 0x00: /* PS-ADPCM (test banks) */
|
||||
/* 0x10: null? */
|
||||
channel_count = read_32bit(start_offset+0x14,sf);
|
||||
channels = read_u32(start_offset+0x14,sf);
|
||||
interleave = 0x02;
|
||||
|
||||
loop_start = read_32bit(start_offset+0x18,sf);
|
||||
loop_length = read_32bit(start_offset+0x1c,sf);
|
||||
loop_start = read_u32(start_offset+0x18,sf);
|
||||
loop_length = read_u32(start_offset+0x1c,sf);
|
||||
loop_end = loop_start + loop_length; /* loop_start is -1 if not set */
|
||||
|
||||
codec = HEVAG;
|
||||
break;
|
||||
|
||||
default:
|
||||
VGM_LOG("BNK: unknown type %x\n", type);
|
||||
vgm_logi("BNK: unknown type %x (report)\n", type);
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
VGM_LOG("BNK: unknown data version %x\n", sblk_version);
|
||||
vgm_logi("BNK: unknown data version %x (report)\n", sblk_version);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@ -474,7 +469,7 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
|
||||
|
||||
/* 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;
|
||||
@ -518,7 +513,7 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = interleave;
|
||||
|
||||
vgmstream->num_samples = ps_bytes_to_samples(stream_size,channel_count);
|
||||
vgmstream->num_samples = ps_bytes_to_samples(stream_size,channels);
|
||||
vgmstream->loop_start_sample = loop_start;
|
||||
vgmstream->loop_end_sample = loop_end;
|
||||
break;
|
||||
@ -528,7 +523,7 @@ VGMSTREAM* init_vgmstream_bnk_sony(STREAMFILE* sf) {
|
||||
vgmstream->layout_type = layout_interleave;
|
||||
vgmstream->interleave_block_size = interleave;
|
||||
|
||||
vgmstream->num_samples = ps_bytes_to_samples(stream_size,channel_count);
|
||||
vgmstream->num_samples = ps_bytes_to_samples(stream_size,channels);
|
||||
vgmstream->loop_start_sample = loop_start;
|
||||
vgmstream->loop_end_sample = loop_end;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user