mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-26 14:51:50 +01:00
commit
afecc953f3
@ -431,11 +431,11 @@ static void ms_audio_parse_header(STREAMFILE *streamFile, int xma_version, int64
|
|||||||
/* full packet skip, no new frames start in this packet (prev frames can end here)
|
/* full packet skip, no new frames start in this packet (prev frames can end here)
|
||||||
* standardized to some value */
|
* standardized to some value */
|
||||||
if (*packet_skip_count == 0x7FF) { /* XMA1, 11b */
|
if (*packet_skip_count == 0x7FF) { /* XMA1, 11b */
|
||||||
VGM_LOG("MS_SAMPLES: XMA1 full packet_skip at %"PRIx64"\n", offset_b/8);
|
VGM_LOG("MS_SAMPLES: XMA1 full packet_skip\n");// at %"PRIx64"\n", offset_b/8);
|
||||||
*packet_skip_count = 0x800;
|
*packet_skip_count = 0x800;
|
||||||
}
|
}
|
||||||
else if (*packet_skip_count == 0xFF) { /* XMA2, 8b*/
|
else if (*packet_skip_count == 0xFF) { /* XMA2, 8b*/
|
||||||
VGM_LOG("MS_SAMPLES: XMA2 full packet_skip at %"PRIx64"\n", offset_b/8);
|
VGM_LOG("MS_SAMPLES: XMA2 full packet_skip\n");// at %"PRIx64"\n", offset_b/8);
|
||||||
*packet_skip_count = 0x800;
|
*packet_skip_count = 0x800;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,11 +292,16 @@ static uint32_t read_ubits(uint8_t bits, uint32_t offset, uint8_t *buf) {
|
|||||||
}
|
}
|
||||||
static int read_sbits(uint8_t bits, uint32_t offset, uint8_t *buf) {
|
static int read_sbits(uint8_t bits, uint32_t offset, uint8_t *buf) {
|
||||||
uint32_t val = read_ubits(bits, offset, buf);
|
uint32_t val = read_ubits(bits, offset, buf);
|
||||||
|
int outval;
|
||||||
if (val >> (bits - 1) == 1) { /* upper bit = sign */
|
if (val >> (bits - 1) == 1) { /* upper bit = sign */
|
||||||
uint32_t mask = (1 << (bits - 1)) - 1;
|
uint32_t mask = (1 << (bits - 1)) - 1;
|
||||||
return -(val & mask);
|
outval = (int)(val & mask);
|
||||||
|
outval = -outval;
|
||||||
}
|
}
|
||||||
return val;
|
else {
|
||||||
|
outval = (int)val;
|
||||||
|
}
|
||||||
|
return outval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_dequantization(float* scales) {
|
static void init_dequantization(float* scales) {
|
||||||
@ -339,7 +344,7 @@ static void unpack_frame(uint8_t *buf, int buf_size, float *freq1, float *freq2,
|
|||||||
if (cb_bits > 0 && ev_bits > 0) {
|
if (cb_bits > 0 && ev_bits > 0) {
|
||||||
pos = 0;
|
pos = 0;
|
||||||
for (i = 0; i < RELIC_CRITICAL_BAND_COUNT - 1; i++) {
|
for (i = 0; i < RELIC_CRITICAL_BAND_COUNT - 1; i++) {
|
||||||
if (bit_offset >= 8*buf_size)
|
if (bit_offset >= 8u*buf_size)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
move = read_ubits(cb_bits, bit_offset, buf);
|
move = read_ubits(cb_bits, bit_offset, buf);
|
||||||
@ -361,7 +366,7 @@ static void unpack_frame(uint8_t *buf, int buf_size, float *freq1, float *freq2,
|
|||||||
/* read first part */
|
/* read first part */
|
||||||
pos = 0;
|
pos = 0;
|
||||||
for (i = 0; i < RELIC_MAX_FREQ; i++) {
|
for (i = 0; i < RELIC_MAX_FREQ; i++) {
|
||||||
if (bit_offset >= 8*buf_size)
|
if (bit_offset >= 8u*buf_size)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
move = read_ubits(ei_bits, bit_offset, buf);
|
move = read_ubits(ei_bits, bit_offset, buf);
|
||||||
@ -385,7 +390,7 @@ static void unpack_frame(uint8_t *buf, int buf_size, float *freq1, float *freq2,
|
|||||||
else {
|
else {
|
||||||
pos = 0;
|
pos = 0;
|
||||||
for (i = 0; i < RELIC_MAX_FREQ; i++) {
|
for (i = 0; i < RELIC_MAX_FREQ; i++) {
|
||||||
if (bit_offset >= 8*buf_size)
|
if (bit_offset >= 8u*buf_size)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
move = read_ubits(ei_bits, bit_offset, buf);
|
move = read_ubits(ei_bits, bit_offset, buf);
|
||||||
@ -437,7 +442,7 @@ static void copy_samples(relic_codec_data* data, sample_t* outbuf, int32_t sampl
|
|||||||
for (ch = 0; ch < ichs; ch++) {
|
for (ch = 0; ch < ichs; ch++) {
|
||||||
for (s = 0; s < samples; s++) {
|
for (s = 0; s < samples; s++) {
|
||||||
double d64_sample = data->wave_cur[ch][skip + s];
|
double d64_sample = data->wave_cur[ch][skip + s];
|
||||||
int pcm_sample = clamp16(d64_sample);
|
int pcm_sample = clamp16((int32_t)d64_sample);
|
||||||
|
|
||||||
/* f32 in PCM 32767.0 .. -32768.0 format, original code
|
/* f32 in PCM 32767.0 .. -32768.0 format, original code
|
||||||
* does some custom double-to-int rint() though */
|
* does some custom double-to-int rint() though */
|
||||||
|
@ -1,56 +1,56 @@
|
|||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "../coding/coding.h"
|
#include "../coding/coding.h"
|
||||||
|
|
||||||
typedef enum { IDSP, OPUS, } nus3audio_codec;
|
typedef enum { IDSP, OPUS, RIFF, } nus3audio_codec;
|
||||||
|
|
||||||
/* .nus3audio - Namco's newest newest audio container [Super Smash Bros. Ultimate (Switch)] */
|
/* .nus3audio - Namco's newest newest audio container [Super Smash Bros. Ultimate (Switch)] */
|
||||||
VGMSTREAM * init_vgmstream_nus3audio(STREAMFILE *streamFile) {
|
VGMSTREAM* init_vgmstream_nus3audio(STREAMFILE* sf) {
|
||||||
VGMSTREAM* vgmstream = NULL;
|
VGMSTREAM* vgmstream = NULL;
|
||||||
STREAMFILE *temp_streamFile = NULL;
|
STREAMFILE* temp_sf = NULL;
|
||||||
off_t subfile_offset = 0, name_offset = 0;
|
off_t subfile_offset = 0, name_offset = 0;
|
||||||
size_t subfile_size = 0;
|
size_t subfile_size = 0;
|
||||||
nus3audio_codec codec;
|
nus3audio_codec codec;
|
||||||
const char* fake_ext = NULL;
|
const char* fake_ext = NULL;
|
||||||
int total_subsongs, target_subsong = streamFile->stream_index;
|
int total_subsongs, target_subsong = sf->stream_index;
|
||||||
|
|
||||||
|
|
||||||
/* checks */
|
/* checks */
|
||||||
if (!check_extensions(streamFile, "nus3audio"))
|
if (!check_extensions(sf, "nus3audio"))
|
||||||
goto fail;
|
goto fail;
|
||||||
if (read_32bitBE(0x00,streamFile) != 0x4E555333) /* "NUS3" */
|
if (read_u32be(0x00,sf) != 0x4E555333) /* "NUS3" */
|
||||||
goto fail;
|
goto fail;
|
||||||
if (read_32bitLE(0x04,streamFile) + 0x08 != get_streamfile_size(streamFile))
|
if (read_u32le(0x04,sf) + 0x08 != get_streamfile_size(sf))
|
||||||
goto fail;
|
goto fail;
|
||||||
if (read_32bitBE(0x08,streamFile) != 0x41554449) /* "AUDI" */
|
if (read_u32be(0x08,sf) != 0x41554449) /* "AUDI" */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
|
||||||
/* parse existing chunks */
|
/* parse existing chunks */
|
||||||
{
|
{
|
||||||
off_t offset = 0x0c;
|
off_t offset = 0x0c;
|
||||||
size_t file_size = get_streamfile_size(streamFile);
|
size_t file_size = get_streamfile_size(sf);
|
||||||
uint32_t codec_id = 0;
|
uint32_t codec_id = 0;
|
||||||
|
|
||||||
total_subsongs = 0;
|
total_subsongs = 0;
|
||||||
|
|
||||||
while (offset < file_size) {
|
while (offset < file_size) {
|
||||||
uint32_t chunk_id = (uint32_t)read_32bitBE(offset+0x00, streamFile);
|
uint32_t chunk_id = read_u32be(offset+0x00, sf);
|
||||||
size_t chunk_size = (size_t)read_32bitLE(offset+0x04, streamFile);
|
size_t chunk_size = read_u32le(offset+0x04, sf);
|
||||||
|
|
||||||
switch(chunk_id) {
|
switch(chunk_id) {
|
||||||
case 0x494E4458: /* "INDX": audio index */
|
case 0x494E4458: /* "INDX": audio index */
|
||||||
total_subsongs = read_32bitLE(offset+0x08 + 0x00,streamFile);
|
total_subsongs = read_u32le(offset+0x08 + 0x00,sf);
|
||||||
if (target_subsong == 0) target_subsong = 1;
|
if (target_subsong == 0) target_subsong = 1;
|
||||||
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
|
if (target_subsong < 0 || target_subsong > total_subsongs || total_subsongs < 1) goto fail;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x4E4D4F46: /* "NMOF": name offsets (absolute, inside TNNM) */
|
case 0x4E4D4F46: /* "NMOF": name offsets (absolute, inside TNNM) */
|
||||||
name_offset = read_32bitLE(offset+0x08 + 0x04*(target_subsong-1),streamFile);
|
name_offset = read_u32le(offset+0x08 + 0x04*(target_subsong-1),sf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x41444F46: /* "ADOF": audio offsets (absolute, inside PACK) */
|
case 0x41444F46: /* "ADOF": audio offsets (absolute, inside PACK) */
|
||||||
subfile_offset = read_32bitLE(offset+0x08 + 0x08*(target_subsong-1) + 0x00,streamFile);
|
subfile_offset = read_u32le(offset+0x08 + 0x08*(target_subsong-1) + 0x00,sf);
|
||||||
subfile_size = read_32bitLE(offset+0x08 + 0x08*(target_subsong-1) + 0x04,streamFile);
|
subfile_size = read_u32le(offset+0x08 + 0x08*(target_subsong-1) + 0x04,sf);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x544E4944: /* "TNID": tone ids? */
|
case 0x544E4944: /* "TNID": tone ids? */
|
||||||
@ -69,7 +69,7 @@ VGMSTREAM * init_vgmstream_nus3audio(STREAMFILE *streamFile) {
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
codec_id = read_32bitBE(subfile_offset, streamFile);
|
codec_id = read_u32be(subfile_offset, sf);
|
||||||
switch(codec_id) {
|
switch(codec_id) {
|
||||||
case 0x49445350: /* "IDSP" */
|
case 0x49445350: /* "IDSP" */
|
||||||
codec = IDSP;
|
codec = IDSP;
|
||||||
@ -79,6 +79,10 @@ VGMSTREAM * init_vgmstream_nus3audio(STREAMFILE *streamFile) {
|
|||||||
codec = OPUS;
|
codec = OPUS;
|
||||||
fake_ext = "opus";
|
fake_ext = "opus";
|
||||||
break;
|
break;
|
||||||
|
case 0x52494646: /* "RIFF" [Gundam Versus (PS4)] */
|
||||||
|
codec = RIFF;
|
||||||
|
fake_ext = "wav";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
VGM_LOG("NUS3AUDIO: unknown codec %x\n", codec_id);
|
VGM_LOG("NUS3AUDIO: unknown codec %x\n", codec_id);
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -86,17 +90,21 @@ VGMSTREAM * init_vgmstream_nus3audio(STREAMFILE *streamFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
temp_streamFile = setup_subfile_streamfile(streamFile, subfile_offset,subfile_size, fake_ext);
|
temp_sf = setup_subfile_streamfile(sf, subfile_offset, subfile_size, fake_ext);
|
||||||
if (!temp_streamFile) goto fail;
|
if (!temp_sf) goto fail;
|
||||||
|
|
||||||
/* init the VGMSTREAM */
|
/* init the VGMSTREAM */
|
||||||
switch(codec) {
|
switch(codec) {
|
||||||
case IDSP:
|
case IDSP:
|
||||||
vgmstream = init_vgmstream_idsp_namco(temp_streamFile);
|
vgmstream = init_vgmstream_idsp_namco(temp_sf);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
break;
|
break;
|
||||||
case OPUS:
|
case OPUS:
|
||||||
vgmstream = init_vgmstream_opus_nus3(temp_streamFile);
|
vgmstream = init_vgmstream_opus_nus3(temp_sf);
|
||||||
|
if (!vgmstream) goto fail;
|
||||||
|
break;
|
||||||
|
case RIFF:
|
||||||
|
vgmstream = init_vgmstream_riff(temp_sf);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -105,13 +113,13 @@ VGMSTREAM * init_vgmstream_nus3audio(STREAMFILE *streamFile) {
|
|||||||
|
|
||||||
vgmstream->num_streams = total_subsongs;
|
vgmstream->num_streams = total_subsongs;
|
||||||
if (name_offset) /* null-terminated */
|
if (name_offset) /* null-terminated */
|
||||||
read_string(vgmstream->stream_name,STREAM_NAME_SIZE, name_offset,streamFile);
|
read_string(vgmstream->stream_name,STREAM_NAME_SIZE, name_offset,sf);
|
||||||
|
|
||||||
close_streamfile(temp_streamFile);
|
close_streamfile(temp_sf);
|
||||||
return vgmstream;
|
return vgmstream;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
close_streamfile(temp_streamFile);
|
close_streamfile(temp_sf);
|
||||||
close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -195,16 +195,10 @@ VGMSTREAM * init_vgmstream_zsnd(STREAMFILE *streamFile) {
|
|||||||
name_offset = 0;
|
name_offset = 0;
|
||||||
name_size = 0;
|
name_size = 0;
|
||||||
|
|
||||||
//TODO: possibly pitch: sample_rate = round10(pitch * 44100 / 4096);
|
/* pitch value, with 0x1000=44100 (voices vary quite a bit, ex. X-Men Legends 2) */
|
||||||
switch(sample_rate) {
|
sample_rate = round10(sample_rate * 44100.0 / 4096.0);
|
||||||
case 0x0800: sample_rate = 22050; break;
|
/* there may be some rounding for lower values, ex 0x45A = 11993.99 ~= 12000, though not all:
|
||||||
case 0x0687: sample_rate = 18000; break;
|
* 0x1000 = 44100, 0x0800 = 22050, 0x0687 ~= 18000, 0x05ce ~= 16000, 0x045a ~= 12000, 0x0400 = 11025 */
|
||||||
case 0x05ce: sample_rate = 16000; break;
|
|
||||||
case 0x0400: sample_rate = 11025; break;
|
|
||||||
default:
|
|
||||||
VGM_LOG("ZSND: unknown sample_rate %x at %x\n", sample_rate, (uint32_t)header2_offset);
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x47435542: /* "GCUB" (also for Wii) */
|
case 0x47435542: /* "GCUB" (also for Wii) */
|
||||||
|
@ -247,6 +247,11 @@ static STREAMFILE *wasf_open(WINAMP_STREAMFILE *streamFile, const char *const fi
|
|||||||
if (!filename)
|
if (!filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
#if !defined (__ANDROID__) && !defined (_MSC_VER)
|
||||||
|
/* When enabling this for MSVC it'll seemingly work, but there are issues possibly related to underlying
|
||||||
|
* IO buffers when using dup(), noticeable by re-opening the same streamfile with small buffer sizes
|
||||||
|
* (reads garbage). This reportedly causes issues in Android too */
|
||||||
|
|
||||||
streamFile->stdiosf->get_name(streamFile->stdiosf, name, PATH_LIMIT);
|
streamFile->stdiosf->get_name(streamFile->stdiosf, name, PATH_LIMIT);
|
||||||
/* if same name, duplicate the file descriptor we already have open */ //unsure if all this is needed
|
/* if same name, duplicate the file descriptor we already have open */ //unsure if all this is needed
|
||||||
if (streamFile->infile_ref && !strcmp(name,filename)) {
|
if (streamFile->infile_ref && !strcmp(name,filename)) {
|
||||||
@ -264,6 +269,7 @@ static STREAMFILE *wasf_open(WINAMP_STREAMFILE *streamFile, const char *const fi
|
|||||||
|
|
||||||
/* on failure just close and try the default path (which will probably fail a second time) */
|
/* on failure just close and try the default path (which will probably fail a second time) */
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* STREAMFILEs carry char/UTF8 names, convert to wchar for Winamp */
|
/* STREAMFILEs carry char/UTF8 names, convert to wchar for Winamp */
|
||||||
wa_char_to_ichar(wpath,PATH_LIMIT, filename);
|
wa_char_to_ichar(wpath,PATH_LIMIT, filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user