mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-02-06 22:54:26 +01:00
Do some cleanup while we are testing BFSTMs
This commit is contained in:
parent
0c55e49a63
commit
de523dc6a3
@ -1,30 +1,27 @@
|
|||||||
#include "meta.h"
|
#include "meta.h"
|
||||||
#include "../util.h"
|
#include "../util.h"
|
||||||
|
|
||||||
|
/* BCSTM - Nintendo 3DS format */
|
||||||
VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) {
|
VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) {
|
||||||
VGMSTREAM * vgmstream = NULL;
|
VGMSTREAM * vgmstream = NULL;
|
||||||
char filename[PATH_LIMIT];
|
|
||||||
|
|
||||||
coding_t coding_type;
|
coding_t coding_type;
|
||||||
|
|
||||||
off_t info_offset = 0, seek_offset = 0, data_offset = 0;
|
off_t info_offset = 0, seek_offset = 0, data_offset = 0;
|
||||||
uint16_t temp_id;
|
uint16_t temp_id;
|
||||||
int codec_number;
|
int codec_number;
|
||||||
int channel_count;
|
int channel_count, loop_flag;
|
||||||
int loop_flag;
|
|
||||||
int i, ima = 0;
|
int i, ima = 0;
|
||||||
off_t start_offset;
|
off_t start_offset;
|
||||||
int section_count;
|
int section_count;
|
||||||
|
|
||||||
/* check extension, case insensitive */
|
/* check extension, case insensitive */
|
||||||
streamFile->get_name(streamFile, filename, sizeof(filename));
|
if ( !check_extensions(streamFile,"bcstm") )
|
||||||
if (strcasecmp("bcstm", filename_extension(filename)))
|
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
|
||||||
/* check header */
|
/* check header */
|
||||||
if ((uint32_t)read_32bitBE(0, streamFile) != 0x4353544D) /* "CSTM" */
|
if ((uint32_t)read_32bitBE(0, streamFile) != 0x4353544D) /* "CSTM" */
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
if ((uint16_t)read_16bitLE(4, streamFile) != 0xFEFF)
|
if ((uint16_t)read_16bitLE(4, streamFile) != 0xFEFF)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
@ -57,11 +54,12 @@ VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (info_offset == 0) goto fail;
|
||||||
|
if ((uint32_t)read_32bitBE(info_offset, streamFile) != 0x494E464F) /* "INFO" */
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
|
||||||
/* check type details */
|
/* check type details */
|
||||||
if (info_offset == 0) goto fail;
|
|
||||||
codec_number = read_8bit(info_offset + 0x20, streamFile);
|
codec_number = read_8bit(info_offset + 0x20, streamFile);
|
||||||
loop_flag = read_8bit(info_offset + 0x21, streamFile);
|
loop_flag = read_8bit(info_offset + 0x21, streamFile);
|
||||||
channel_count = read_8bit(info_offset + 0x22, streamFile);
|
channel_count = read_8bit(info_offset + 0x22, streamFile);
|
||||||
@ -89,13 +87,12 @@ VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) {
|
|||||||
if (channel_count < 1) goto fail;
|
if (channel_count < 1) goto fail;
|
||||||
|
|
||||||
/* build the VGMSTREAM */
|
/* build the VGMSTREAM */
|
||||||
|
|
||||||
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
vgmstream = allocate_vgmstream(channel_count, loop_flag);
|
||||||
if (!vgmstream) goto fail;
|
if (!vgmstream) goto fail;
|
||||||
|
|
||||||
/* fill in the vital statistics */
|
/* fill in the vital statistics */
|
||||||
vgmstream->num_samples = read_32bitLE(info_offset + 0x2c, streamFile);
|
vgmstream->num_samples = read_32bitLE(info_offset + 0x2c, streamFile);
|
||||||
vgmstream->sample_rate = (uint16_t)read_16bitLE(info_offset + 0x24, streamFile);
|
vgmstream->sample_rate = read_32bitLE(info_offset + 0x24, streamFile);
|
||||||
/* channels and loop flag are set by allocate_vgmstream */
|
/* channels and loop flag are set by allocate_vgmstream */
|
||||||
if (ima) //Shift the loop points back slightly to avoid stupid pops in some IMA streams due to DC offsetting
|
if (ima) //Shift the loop points back slightly to avoid stupid pops in some IMA streams due to DC offsetting
|
||||||
{
|
{
|
||||||
@ -167,33 +164,13 @@ VGMSTREAM * init_vgmstream_bcstm(STREAMFILE *streamFile) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* open the file for reading by each channel */
|
||||||
|
if (!vgmstream_open_stream(vgmstream,streamFile,start_offset))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
/* open the file for reading by each channel */
|
return vgmstream;
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i = 0; i<channel_count; i++) {
|
|
||||||
if (vgmstream->layout_type == layout_interleave_shortblock)
|
|
||||||
vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename,
|
|
||||||
vgmstream->interleave_block_size);
|
|
||||||
else if (vgmstream->layout_type == layout_interleave)
|
|
||||||
vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename,
|
|
||||||
STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
||||||
else
|
|
||||||
vgmstream->ch[i].streamfile = streamFile->open(streamFile, filename,
|
|
||||||
0x1000);
|
|
||||||
|
|
||||||
if (!vgmstream->ch[i].streamfile) goto fail;
|
|
||||||
|
|
||||||
vgmstream->ch[i].channel_start_offset =
|
|
||||||
vgmstream->ch[i].offset =
|
|
||||||
start_offset + i*vgmstream->interleave_block_size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return vgmstream;
|
|
||||||
|
|
||||||
/* clean up anything we may have opened */
|
|
||||||
fail:
|
fail:
|
||||||
if (vgmstream) close_vgmstream(vgmstream);
|
close_vgmstream(vgmstream);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user