2008-05-06 05:35:37 +02:00
|
|
|
#include "meta.h"
|
2008-02-14 23:10:08 +01:00
|
|
|
#include "../util.h"
|
2008-05-06 05:35:37 +02:00
|
|
|
#include "../coding/coding.h"
|
2008-02-14 23:10:08 +01:00
|
|
|
|
|
|
|
/* .rsf - from Metroid Prime */
|
|
|
|
|
2008-05-20 17:18:38 +02:00
|
|
|
VGMSTREAM * init_vgmstream_rsf(STREAMFILE *streamFile) {
|
2008-02-14 23:10:08 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2013-05-27 05:55:50 +02:00
|
|
|
char filename[PATH_LIMIT];
|
2008-02-14 23:10:08 +01:00
|
|
|
|
|
|
|
size_t file_size;
|
|
|
|
|
|
|
|
/* check extension, case insensitive */
|
|
|
|
/* this is all we have to go on, rsf is completely headerless */
|
2008-05-20 17:18:38 +02:00
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
2008-02-14 23:10:08 +01:00
|
|
|
if (strcasecmp("rsf",filename_extension(filename))) goto fail;
|
|
|
|
|
2008-05-20 17:18:38 +02:00
|
|
|
file_size = get_streamfile_size(streamFile);
|
2008-02-14 23:10:08 +01:00
|
|
|
|
2008-04-02 18:07:14 +02:00
|
|
|
{
|
|
|
|
/* extra check: G.721 has no zero nibbles, so we look at
|
|
|
|
* the first few bytes*/
|
|
|
|
int8_t test_byte;
|
|
|
|
off_t i;
|
|
|
|
/* 0x20 is arbitrary, all files are much larger */
|
|
|
|
for (i=0;i<0x20;i++) {
|
2008-05-20 17:18:38 +02:00
|
|
|
test_byte = read_8bit(i,streamFile);
|
2008-04-02 18:07:14 +02:00
|
|
|
if (!(test_byte&0xf) || !(test_byte&0xf0)) goto fail;
|
|
|
|
}
|
|
|
|
/* and also check start of second channel */
|
|
|
|
for (i=(file_size+1)/2;i<(file_size+1)/2+0x20;i++) {
|
2008-05-20 17:18:38 +02:00
|
|
|
test_byte = read_8bit(i,streamFile);
|
2008-04-02 18:07:14 +02:00
|
|
|
if (!(test_byte&0xf) || !(test_byte&0xf0)) goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-14 23:10:08 +01:00
|
|
|
/* build the VGMSTREAM */
|
|
|
|
|
|
|
|
vgmstream = allocate_vgmstream(2,0);
|
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
|
|
|
/* fill in the vital statistics */
|
2008-04-02 18:07:14 +02:00
|
|
|
vgmstream->num_samples = file_size;
|
2008-02-14 23:10:08 +01:00
|
|
|
vgmstream->sample_rate = 32000;
|
|
|
|
|
|
|
|
vgmstream->coding_type = coding_G721;
|
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->meta_type = meta_RSF;
|
|
|
|
|
|
|
|
/* open the file for reading by each channel */
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0;i<2;i++) {
|
2008-05-20 17:18:38 +02:00
|
|
|
vgmstream->ch[i].streamfile = streamFile->open(streamFile,filename,STREAMFILE_DEFAULT_BUFFER_SIZE);
|
2008-02-14 23:10:08 +01:00
|
|
|
|
|
|
|
if (!vgmstream->ch[i].streamfile) goto fail;
|
|
|
|
|
|
|
|
vgmstream->ch[i].channel_start_offset=
|
|
|
|
vgmstream->ch[i].offset=
|
2008-04-02 18:07:14 +02:00
|
|
|
(file_size+1)/2*i;
|
2008-02-14 23:10:08 +01:00
|
|
|
|
|
|
|
|
|
|
|
g72x_init_state(&(vgmstream->ch[i].g72x_state));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
/* clean up anything we may have opened */
|
|
|
|
fail:
|
|
|
|
if (vgmstream) close_vgmstream(vgmstream);
|
|
|
|
return NULL;
|
|
|
|
}
|