2016-11-12 00:39:40 +01:00
|
|
|
#include "../vgmstream.h"
|
|
|
|
|
|
|
|
#ifdef VGM_USE_VORBIS
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "meta.h"
|
|
|
|
#include <vorbis/vorbisfile.h>
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
#define OGG_DEFAULT_BITSTREAM 0
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
static size_t ov_read_func(void *ptr, size_t size, size_t nmemb, void * datasource) {
|
2016-11-12 00:39:40 +01:00
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
2018-01-10 21:12:23 +01:00
|
|
|
size_t bytes_read, items_read;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-01-11 22:55:23 +01:00
|
|
|
off_t real_offset = ov_streamfile->start + ov_streamfile->offset;
|
|
|
|
size_t max_bytes = size * nmemb;
|
|
|
|
|
|
|
|
/* clamp for virtual filesize */
|
|
|
|
if (max_bytes > ov_streamfile->size - ov_streamfile->offset)
|
|
|
|
max_bytes = ov_streamfile->size - ov_streamfile->offset;
|
|
|
|
|
|
|
|
bytes_read = read_streamfile(ptr, real_offset, max_bytes, ov_streamfile->streamfile);
|
2016-11-12 00:39:40 +01:00
|
|
|
items_read = bytes_read / size;
|
|
|
|
|
2017-01-03 19:03:08 +01:00
|
|
|
/* may be encrypted */
|
2018-01-10 21:12:23 +01:00
|
|
|
if (ov_streamfile->decryption_callback) {
|
|
|
|
ov_streamfile->decryption_callback(ptr, size, items_read, ov_streamfile);
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ov_streamfile->offset += items_read * size;
|
|
|
|
|
|
|
|
return items_read;
|
|
|
|
}
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
static int ov_seek_func(void *datasource, ogg_int64_t offset, int whence) {
|
2016-11-12 00:39:40 +01:00
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
2018-01-10 21:12:23 +01:00
|
|
|
ogg_int64_t base_offset, new_offset;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
|
|
|
switch (whence) {
|
|
|
|
case SEEK_SET:
|
|
|
|
base_offset = 0;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
base_offset = ov_streamfile->offset;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
2018-01-11 22:55:23 +01:00
|
|
|
base_offset = ov_streamfile->size;
|
2016-11-12 00:39:40 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
|
2016-11-12 00:39:40 +01:00
|
|
|
new_offset = base_offset + offset;
|
2018-01-11 22:55:23 +01:00
|
|
|
if (new_offset < 0 || new_offset > ov_streamfile->size) {
|
2018-01-10 21:12:23 +01:00
|
|
|
return -1; /* *must* return -1 if stream is unseekable */
|
2016-11-12 00:39:40 +01:00
|
|
|
} else {
|
|
|
|
ov_streamfile->offset = new_offset;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
static long ov_tell_func(void * datasource) {
|
2016-11-12 00:39:40 +01:00
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
return ov_streamfile->offset;
|
|
|
|
}
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
static int ov_close_func(void * datasource) {
|
|
|
|
/* needed as setting ov_close_func in ov_callbacks to NULL doesn't seem to work
|
|
|
|
* (closing the streamfile is done in free_ogg_vorbis) */
|
2016-11-12 00:39:40 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
static void um3_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* first 0x800 bytes are xor'd */
|
2018-01-10 21:12:23 +01:00
|
|
|
if (ov_streamfile->offset < 0x800) {
|
|
|
|
int num_crypt = 0x800 - ov_streamfile->offset;
|
|
|
|
if (num_crypt > bytes_read)
|
|
|
|
num_crypt = bytes_read;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
for (i = 0; i < num_crypt; i++)
|
|
|
|
((uint8_t*)ptr)[i] ^= 0xff;
|
|
|
|
}
|
|
|
|
}
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
static void kovs_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* first 0x100 bytes are xor'd */
|
2018-01-10 21:12:23 +01:00
|
|
|
if (ov_streamfile->offset < 0x100) {
|
|
|
|
int max_offset = ov_streamfile->offset + bytes_read;
|
|
|
|
if (max_offset > 0x100)
|
|
|
|
max_offset = 0x100;
|
|
|
|
|
|
|
|
for (i = ov_streamfile->offset; i < max_offset; i++) {
|
|
|
|
((uint8_t*)ptr)[i-ov_streamfile->offset] ^= i;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void psychic_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
int i;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* bytes add 0x23 ('#') */
|
2018-04-20 17:02:56 +02:00
|
|
|
for (i = 0; i < bytes_read; i++) {
|
2018-10-04 20:43:23 +02:00
|
|
|
((uint8_t*)ptr)[i] += 0x23;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
}
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-01-10 22:34:14 +01:00
|
|
|
static void sngw_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
|
|
|
char *header_id = "OggS";
|
|
|
|
uint8_t key[4];
|
|
|
|
|
2018-04-12 22:46:18 +02:00
|
|
|
put_32bitBE(key, ov_streamfile->xor_value);
|
2018-01-10 22:34:14 +01:00
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* first "OggS" is changed and bytes are xor'd and nibble-swapped */
|
2018-04-20 17:02:56 +02:00
|
|
|
for (i = 0; i < bytes_read; i++) {
|
|
|
|
if (ov_streamfile->offset+i < 0x04) {
|
|
|
|
((uint8_t*)ptr)[i] = (uint8_t)header_id[(ov_streamfile->offset + i) % 4];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
uint8_t val = ((uint8_t*)ptr)[i] ^ key[(ov_streamfile->offset + i) % 4];
|
|
|
|
((uint8_t*)ptr)[i] = ((val << 4) & 0xf0) | ((val >> 4) & 0x0f);
|
2018-01-10 22:34:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-13 15:22:58 +01:00
|
|
|
static void isd_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
static const uint8_t key[16] = {
|
|
|
|
0xe0,0x00,0xe0,0x00,0xa0,0x00,0x00,0x00,0xe0,0x00,0xe0,0x80,0x40,0x40,0x40,0x00
|
|
|
|
};
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* bytes are xor'd */
|
2018-04-20 17:02:56 +02:00
|
|
|
for (i = 0; i < bytes_read; i++) {
|
|
|
|
((uint8_t*)ptr)[i] ^= key[(ov_streamfile->offset + i) % 16];
|
2018-01-13 15:22:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-17 02:23:45 +01:00
|
|
|
static void l2sd_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
|
|
|
char *header_id = "OggS";
|
|
|
|
|
2018-04-20 17:02:56 +02:00
|
|
|
/* first "OggS" is changed */
|
|
|
|
for (i = 0; i < bytes_read; i++) {
|
|
|
|
if (ov_streamfile->offset+i < 0x04) {
|
|
|
|
((uint8_t*)ptr)[i] = (uint8_t)header_id[(ov_streamfile->offset + i) % 4];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
2018-02-17 02:23:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 19:04:06 +02:00
|
|
|
static void rpgmvo_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
static const uint8_t header[16] = { /* OggS, packet type, granule, stream id(empty) */
|
|
|
|
0x4F,0x67,0x67,0x53,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
|
|
|
};
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* first 0x10 are xor'd, but header can be easily reconstructed
|
2018-04-07 19:04:06 +02:00
|
|
|
* (key is also in (game)/www/data/System.json "encryptionKey") */
|
|
|
|
for (i = 0; i < bytes_read; i++) {
|
|
|
|
if (ov_streamfile->offset+i < 0x10) {
|
|
|
|
((uint8_t*)ptr)[i] = header[(ov_streamfile->offset + i) % 16];
|
|
|
|
|
|
|
|
/* last two bytes are the stream id, get from next OggS */
|
|
|
|
if (ov_streamfile->offset+i == 0x0e)
|
|
|
|
((uint8_t*)ptr)[i] = read_8bit(0x58, ov_streamfile->streamfile);
|
|
|
|
if (ov_streamfile->offset+i == 0x0f)
|
|
|
|
((uint8_t*)ptr)[i] = read_8bit(0x59, ov_streamfile->streamfile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-12 22:46:18 +02:00
|
|
|
static void eno_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* bytes are xor'd */
|
2018-04-12 22:46:18 +02:00
|
|
|
for (i = 0; i < bytes_read; i++) {
|
|
|
|
((uint8_t*)ptr)[i] ^= (uint8_t)ov_streamfile->xor_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-20 17:02:56 +02:00
|
|
|
static void ys8_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* bytes are xor'd and nibble-swapped */
|
2018-04-20 17:02:56 +02:00
|
|
|
for (i = 0; i < bytes_read; i++) {
|
|
|
|
uint8_t val = ((uint8_t*)ptr)[i] ^ ov_streamfile->xor_value;
|
|
|
|
((uint8_t*)ptr)[i] = ((val << 4) & 0xf0) | ((val >> 4) & 0x0f);
|
|
|
|
}
|
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
|
2018-05-19 11:37:21 +02:00
|
|
|
static void gwm_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* bytes are xor'd */
|
2018-05-19 11:37:21 +02:00
|
|
|
for (i = 0; i < bytes_read; i++) {
|
|
|
|
((uint8_t*)ptr)[i] ^= (uint8_t)ov_streamfile->xor_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-30 13:43:12 +02:00
|
|
|
static void mus_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
static const uint8_t key[16] = {
|
|
|
|
0x21,0x4D,0x6F,0x01,0x20,0x4C,0x6E,0x02,0x1F,0x4B,0x6D,0x03,0x20,0x4C,0x6E,0x02
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
|
|
|
char *header_id = "OggS";
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* first "OggS" is changed and bytes are xor'd */
|
2018-06-30 13:43:12 +02:00
|
|
|
for (i = 0; i < bytes_read; i++) {
|
|
|
|
if (ov_streamfile->offset+i < 0x04) { /* if decrypted gives "Mus " */
|
|
|
|
((uint8_t*)ptr)[i] = (uint8_t)header_id[(ov_streamfile->offset + i) % 4];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
((uint8_t*)ptr)[i] ^= key[(ov_streamfile->offset + i) % sizeof(key)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
static void lse_add_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
2018-09-27 23:41:26 +02:00
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
/* bytes are xor'd */
|
2018-09-27 23:41:26 +02:00
|
|
|
for (i = 0; i < bytes_read; i++) {
|
2018-10-04 20:43:23 +02:00
|
|
|
int key = (uint8_t)ov_streamfile->xor_value + ((ov_streamfile->offset + i) % 256);
|
2018-09-27 23:41:26 +02:00
|
|
|
((uint8_t*)ptr)[i] ^= key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
static void lse_ff_ogg_decryption_callback(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
|
|
|
size_t bytes_read = size*nmemb;
|
|
|
|
ogg_vorbis_streamfile * const ov_streamfile = datasource;
|
|
|
|
int i;
|
|
|
|
char *header_id = "OggS";
|
|
|
|
|
|
|
|
/* first "OggS" is changed and bytes are xor'd */
|
|
|
|
for (i = 0; i < bytes_read; i++) {
|
|
|
|
if (ov_streamfile->offset+i < 0x04) {
|
|
|
|
((uint8_t*)ptr)[i] = (uint8_t)header_id[(ov_streamfile->offset + i) % 4];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
((uint8_t*)ptr)[i] ^= 0xFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 15:57:41 +01:00
|
|
|
static const uint32_t xiph_mappings[] = {
|
|
|
|
0,
|
|
|
|
mapping_MONO,
|
|
|
|
mapping_STEREO,
|
|
|
|
mapping_2POINT1_xiph,
|
|
|
|
mapping_QUAD,
|
|
|
|
mapping_5POINT0_xiph,
|
|
|
|
mapping_5POINT1,
|
|
|
|
mapping_7POINT0,
|
|
|
|
mapping_7POINT1,
|
|
|
|
};
|
|
|
|
|
2018-06-30 13:43:12 +02:00
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
/* Ogg Vorbis, by way of libvorbisfile; may contain loop comments */
|
|
|
|
VGMSTREAM * init_vgmstream_ogg_vorbis(STREAMFILE *streamFile) {
|
2018-03-23 16:34:48 +01:00
|
|
|
ogg_vorbis_meta_info_t ovmi = {0};
|
2018-01-10 21:12:23 +01:00
|
|
|
off_t start_offset = 0;
|
|
|
|
|
|
|
|
int is_ogg = 0;
|
|
|
|
int is_um3 = 0;
|
|
|
|
int is_kovs = 0;
|
2018-01-10 22:34:14 +01:00
|
|
|
int is_sngw = 0;
|
2018-01-13 15:22:58 +01:00
|
|
|
int is_isd = 0;
|
2018-04-07 19:04:06 +02:00
|
|
|
int is_rpgmvo = 0;
|
2018-04-12 22:46:18 +02:00
|
|
|
int is_eno = 0;
|
2018-05-19 11:37:21 +02:00
|
|
|
int is_gwm = 0;
|
2018-06-30 13:43:12 +02:00
|
|
|
int is_mus = 0;
|
2018-09-27 23:41:26 +02:00
|
|
|
int is_lse = 0;
|
2018-01-10 21:12:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* check extension */
|
2018-07-27 17:30:58 +02:00
|
|
|
/* .ogg: standard/various, .logg: renamed for plugins
|
|
|
|
* .adx: KID [Remember11 (PC)]
|
2018-03-16 17:43:51 +01:00
|
|
|
* .rof: The Rhythm of Fighters (Mobile)
|
2018-09-09 12:24:28 +02:00
|
|
|
* .acm: Planescape Torment Enhanced Edition (PC)
|
2019-04-07 01:47:07 +02:00
|
|
|
* .sod: Zone 4 (PC)
|
|
|
|
* .aif/laif/aif-Loop: Psychonauts (PC) raw extractions (named) */
|
|
|
|
if (check_extensions(streamFile,"ogg,logg,adx,rof,acm,sod,aif,laif,aif-Loop")) {
|
2018-01-10 21:12:23 +01:00
|
|
|
is_ogg = 1;
|
|
|
|
} else if (check_extensions(streamFile,"um3")) {
|
|
|
|
is_um3 = 1;
|
|
|
|
} else if (check_extensions(streamFile,"kvs,kovs")) { /* .kvs: Atelier Sophie (PC), kovs: header id only? */
|
|
|
|
is_kovs = 1;
|
2018-03-03 01:10:39 +01:00
|
|
|
} else if (check_extensions(streamFile,"sngw")) { /* .sngw: Capcom [Devil May Cry 4 SE (PC), Biohazard 6 (PC)] */
|
2018-01-10 22:34:14 +01:00
|
|
|
is_sngw = 1;
|
2018-01-13 15:22:58 +01:00
|
|
|
} else if (check_extensions(streamFile,"isd")) { /* .isd: Azure Striker Gunvolt (PC) */
|
|
|
|
is_isd = 1;
|
2018-04-07 19:04:06 +02:00
|
|
|
} else if (check_extensions(streamFile,"rpgmvo")) { /* .rpgmvo: RPG Maker MV games (PC) */
|
|
|
|
is_rpgmvo = 1;
|
2018-04-12 22:46:18 +02:00
|
|
|
} else if (check_extensions(streamFile,"eno")) { /* .eno: Metronomicon (PC) */
|
|
|
|
is_eno = 1;
|
2018-05-19 11:37:21 +02:00
|
|
|
} else if (check_extensions(streamFile,"gwm")) { /* .gwm: Adagio: Cloudburst (PC) */
|
|
|
|
is_gwm = 1;
|
2018-07-27 17:30:58 +02:00
|
|
|
} else if (check_extensions(streamFile,"mus")) { /* .mus: Redux - Dark Matters (PC) */
|
2018-06-30 13:43:12 +02:00
|
|
|
is_mus = 1;
|
2018-09-27 23:41:26 +02:00
|
|
|
} else if (check_extensions(streamFile,"lse")) { /* .lse: Labyrinth of Refrain: Coven of Dusk (PC) */
|
|
|
|
is_lse = 1;
|
2018-01-10 21:12:23 +01:00
|
|
|
} else {
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_ogg) {
|
2018-05-19 11:24:20 +02:00
|
|
|
if (read_32bitBE(0x00,streamFile) == 0x2c444430) { /* Psychic Software [Darkwind: War on Wheels (PC)] */
|
2018-03-23 16:34:48 +01:00
|
|
|
ovmi.decryption_callback = psychic_ogg_decryption_callback;
|
2018-10-04 20:43:23 +02:00
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2018-02-17 02:23:45 +01:00
|
|
|
else if (read_32bitBE(0x00,streamFile) == 0x4C325344) { /* "L2SD" [Lineage II Chronicle 4 (PC)] */
|
2018-03-23 16:34:48 +01:00
|
|
|
ovmi.decryption_callback = l2sd_ogg_decryption_callback;
|
2018-10-04 20:43:23 +02:00
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
2018-02-17 02:23:45 +01:00
|
|
|
}
|
2018-10-04 20:43:23 +02:00
|
|
|
else if (read_32bitBE(0x00,streamFile) == 0x048686C5) { /* "OggS" XOR'ed + bitswapped [Ys VIII (PC)] */
|
2018-05-19 11:24:20 +02:00
|
|
|
ovmi.xor_value = 0xF0;
|
2018-04-20 17:02:56 +02:00
|
|
|
ovmi.decryption_callback = ys8_ogg_decryption_callback;
|
2018-10-04 20:43:23 +02:00
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
2018-04-20 17:02:56 +02:00
|
|
|
}
|
2018-10-04 20:43:23 +02:00
|
|
|
else if (read_32bitBE(0x00,streamFile) == 0x4f676753) { /* "OggS" (standard) */
|
2018-05-19 11:24:20 +02:00
|
|
|
ovmi.meta_type = meta_OGG_VORBIS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
goto fail; /* unknown/not Ogg Vorbis (ex. Wwise) */
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_um3) { /* ["Ultramarine3" (???)] */
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x4f676753) { /* "OggS" (optionally encrypted) */
|
2018-03-23 16:34:48 +01:00
|
|
|
ovmi.decryption_callback = um3_ogg_decryption_callback;
|
2018-01-10 21:12:23 +01:00
|
|
|
}
|
2018-10-04 20:43:23 +02:00
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_kovs) { /* Koei Tecmo PC games] */
|
2018-01-10 21:12:23 +01:00
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x4b4f5653) { /* "KOVS" */
|
|
|
|
goto fail;
|
|
|
|
}
|
2018-03-23 16:34:48 +01:00
|
|
|
ovmi.loop_start = read_32bitLE(0x08,streamFile);
|
|
|
|
ovmi.loop_flag = (ovmi.loop_start != 0);
|
|
|
|
ovmi.decryption_callback = kovs_ogg_decryption_callback;
|
2018-05-19 11:24:20 +02:00
|
|
|
ovmi.meta_type = meta_OGG_KOVS;
|
2018-01-10 21:12:23 +01:00
|
|
|
|
|
|
|
start_offset = 0x20;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_sngw) { /* [Capcom's MT Framework PC games] */
|
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x4f676753) { /* "OggS" (optionally encrypted) */
|
2018-04-12 22:46:18 +02:00
|
|
|
ovmi.xor_value = read_32bitBE(0x00,streamFile);
|
2018-03-23 16:34:48 +01:00
|
|
|
ovmi.decryption_callback = sngw_ogg_decryption_callback;
|
2018-01-10 22:34:14 +01:00
|
|
|
}
|
2019-03-24 02:45:03 +01:00
|
|
|
ovmi.disable_reordering = 1; /* must be an MT Framework thing */
|
2018-10-04 20:43:23 +02:00
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
2018-01-10 22:34:14 +01:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_isd) { /* [Gunvolt (PC)] */
|
2018-03-23 16:34:48 +01:00
|
|
|
ovmi.decryption_callback = isd_ogg_decryption_callback;
|
2018-10-04 20:43:23 +02:00
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
2018-01-13 15:22:58 +01:00
|
|
|
|
|
|
|
//todo looping unknown, not in Ogg comments
|
|
|
|
// game has sound/GV_steam.* files with info about sound/stream/*.isd
|
|
|
|
//- .ish: constant id/names
|
|
|
|
//- .isl: unknown table, maybe looping?
|
|
|
|
//- .isf: format table, ordered like file numbers, 0x18 header with:
|
|
|
|
// 0x00(2): ?, 0x02(2): channels, 0x04: sample rate, 0x08: skip samples (in PCM bytes), always 32000
|
|
|
|
// 0x0c(2): PCM block size, 0x0e(2): PCM bps, 0x10: null, 0x18: samples (in PCM bytes)
|
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_rpgmvo) { /* [RPG Maker MV (PC)] */
|
2018-04-07 19:04:06 +02:00
|
|
|
if (read_32bitBE(0x00,streamFile) != 0x5250474D && /* "RPGM" */
|
|
|
|
read_32bitBE(0x00,streamFile) != 0x56000000) { /* "V\0\0\0" */
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
ovmi.decryption_callback = rpgmvo_ogg_decryption_callback;
|
2018-10-04 20:43:23 +02:00
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
2018-04-07 19:04:06 +02:00
|
|
|
|
|
|
|
start_offset = 0x10;
|
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_eno) { /* [Metronomicon (PC)] */
|
2018-04-12 22:46:18 +02:00
|
|
|
/* first byte probably derives into xor key, but this works too */
|
|
|
|
ovmi.xor_value = read_8bit(0x05,streamFile); /* always zero = easy key */
|
|
|
|
ovmi.decryption_callback = eno_ogg_decryption_callback;
|
2018-10-04 20:43:23 +02:00
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
2018-04-07 19:04:06 +02:00
|
|
|
|
2018-05-19 11:24:20 +02:00
|
|
|
start_offset = 0x01;
|
2018-04-20 17:02:56 +02:00
|
|
|
}
|
2018-01-10 22:34:14 +01:00
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_gwm) { /* [Adagio: Cloudburst (PC)] */
|
2018-05-19 11:37:21 +02:00
|
|
|
ovmi.xor_value = 0x5D;
|
|
|
|
ovmi.decryption_callback = gwm_ogg_decryption_callback;
|
2018-10-04 20:43:23 +02:00
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
2018-05-19 11:37:21 +02:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_mus) { /* [Redux - Dark Matters (PC)] */
|
2018-06-30 13:43:12 +02:00
|
|
|
ovmi.decryption_callback = mus_ogg_decryption_callback;
|
2018-10-04 20:43:23 +02:00
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
2018-06-30 13:43:12 +02:00
|
|
|
}
|
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
if (is_lse) { /* [Nippon Ichi PC games] */
|
|
|
|
if (read_32bitBE(0x00,streamFile) == 0xFFFFFFFF) { /* [Operation Abyss: New Tokyo Legacy (PC)] */
|
|
|
|
ovmi.decryption_callback = lse_ff_ogg_decryption_callback;
|
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
|
|
|
}
|
|
|
|
else { /* [Operation Babel: New Tokyo Legacy (PC), Labyrinth of Refrain: Coven of Dusk (PC)] */
|
|
|
|
ovmi.decryption_callback = lse_add_ogg_decryption_callback;
|
|
|
|
ovmi.xor_value = (uint8_t)read_8bit(0x04,streamFile) - 0x04;
|
|
|
|
ovmi.meta_type = meta_OGG_encrypted;
|
|
|
|
/* key is found at file_size-1 but this works too (same key for most files but can vary) */
|
|
|
|
}
|
2018-09-27 23:41:26 +02:00
|
|
|
}
|
|
|
|
|
2018-05-19 11:37:21 +02:00
|
|
|
|
2018-03-23 16:34:48 +01:00
|
|
|
return init_vgmstream_ogg_vorbis_callbacks(streamFile, NULL, start_offset, &ovmi);
|
2016-11-12 00:39:40 +01:00
|
|
|
|
|
|
|
fail:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-23 16:34:48 +01:00
|
|
|
VGMSTREAM * init_vgmstream_ogg_vorbis_callbacks(STREAMFILE *streamFile, ov_callbacks *callbacks_p, off_t start, const ogg_vorbis_meta_info_t *ovmi) {
|
2016-11-12 00:39:40 +01:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
|
|
|
ogg_vorbis_codec_data * data = NULL;
|
2018-01-10 21:12:23 +01:00
|
|
|
OggVorbis_File *ovf = NULL;
|
|
|
|
vorbis_info *vi;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-03-23 16:34:48 +01:00
|
|
|
int loop_flag = ovmi->loop_flag;
|
|
|
|
int32_t loop_start = ovmi->loop_start;
|
|
|
|
int loop_length_found = ovmi->loop_length_found;
|
|
|
|
int32_t loop_length = ovmi->loop_length;
|
|
|
|
int loop_end_found = ovmi->loop_end_found;
|
|
|
|
int32_t loop_end = ovmi->loop_end;
|
|
|
|
size_t stream_size = ovmi->stream_size ?
|
|
|
|
ovmi->stream_size :
|
2018-01-28 00:41:25 +01:00
|
|
|
get_streamfile_size(streamFile) - start;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
|
|
|
ov_callbacks default_callbacks;
|
|
|
|
|
|
|
|
if (!callbacks_p) {
|
2018-01-10 21:12:23 +01:00
|
|
|
default_callbacks.read_func = ov_read_func;
|
|
|
|
default_callbacks.seek_func = ov_seek_func;
|
|
|
|
default_callbacks.close_func = ov_close_func;
|
|
|
|
default_callbacks.tell_func = ov_tell_func;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
|
|
|
callbacks_p = &default_callbacks;
|
|
|
|
}
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
/* test if this is a proper Ogg Vorbis file, with the current (from init_x) STREAMFILE */
|
|
|
|
{
|
2018-07-06 19:37:26 +02:00
|
|
|
OggVorbis_File temp_ovf = {0};
|
|
|
|
ogg_vorbis_streamfile temp_streamfile = {0};
|
2018-01-10 21:12:23 +01:00
|
|
|
|
|
|
|
temp_streamfile.streamfile = streamFile;
|
2018-01-11 22:55:23 +01:00
|
|
|
|
|
|
|
temp_streamfile.start = start;
|
2018-01-10 21:12:23 +01:00
|
|
|
temp_streamfile.offset = 0;
|
2018-01-28 00:41:25 +01:00
|
|
|
temp_streamfile.size = stream_size;
|
2018-01-11 22:55:23 +01:00
|
|
|
|
2018-03-23 16:34:48 +01:00
|
|
|
temp_streamfile.decryption_callback = ovmi->decryption_callback;
|
|
|
|
temp_streamfile.scd_xor = ovmi->scd_xor;
|
|
|
|
temp_streamfile.scd_xor_length = ovmi->scd_xor_length;
|
2018-04-12 22:46:18 +02:00
|
|
|
temp_streamfile.xor_value = ovmi->xor_value;
|
2018-01-10 21:12:23 +01:00
|
|
|
|
|
|
|
/* open the ogg vorbis file for testing */
|
|
|
|
if (ov_test_callbacks(&temp_streamfile, &temp_ovf, NULL, 0, *callbacks_p))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* we have to close this as it has the init_vgmstream meta-reading STREAMFILE */
|
|
|
|
ov_clear(&temp_ovf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* proceed to init codec_data and reopen a STREAMFILE for this stream */
|
|
|
|
{
|
2018-03-23 16:34:48 +01:00
|
|
|
char filename[PATH_LIMIT];
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
data = calloc(1,sizeof(ogg_vorbis_codec_data));
|
|
|
|
if (!data) goto fail;
|
|
|
|
|
2018-03-23 16:34:48 +01:00
|
|
|
streamFile->get_name(streamFile,filename,sizeof(filename));
|
2018-01-10 21:12:23 +01:00
|
|
|
data->ov_streamfile.streamfile = streamFile->open(streamFile,filename, STREAMFILE_DEFAULT_BUFFER_SIZE);
|
|
|
|
if (!data->ov_streamfile.streamfile) goto fail;
|
|
|
|
|
2018-01-11 22:55:23 +01:00
|
|
|
data->ov_streamfile.start = start;
|
2018-01-10 21:12:23 +01:00
|
|
|
data->ov_streamfile.offset = 0;
|
2018-01-28 00:41:25 +01:00
|
|
|
data->ov_streamfile.size = stream_size;
|
2018-01-11 22:55:23 +01:00
|
|
|
|
2018-03-23 16:34:48 +01:00
|
|
|
data->ov_streamfile.decryption_callback = ovmi->decryption_callback;
|
|
|
|
data->ov_streamfile.scd_xor = ovmi->scd_xor;
|
|
|
|
data->ov_streamfile.scd_xor_length = ovmi->scd_xor_length;
|
2018-04-12 22:46:18 +02:00
|
|
|
data->ov_streamfile.xor_value = ovmi->xor_value;
|
2018-01-10 21:12:23 +01:00
|
|
|
|
|
|
|
/* open the ogg vorbis file for real */
|
|
|
|
if (ov_open_callbacks(&data->ov_streamfile, &data->ogg_vorbis_file, NULL, 0, *callbacks_p))
|
|
|
|
goto fail;
|
|
|
|
ovf = &data->ogg_vorbis_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get info from bitstream 0 */
|
|
|
|
data->bitstream = OGG_DEFAULT_BITSTREAM;
|
|
|
|
vi = ov_info(ovf,OGG_DEFAULT_BITSTREAM);
|
|
|
|
|
2019-03-24 02:45:03 +01:00
|
|
|
/* other settings */
|
|
|
|
data->disable_reordering = ovmi->disable_reordering;
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
/* search for loop comments */
|
2016-11-12 00:39:40 +01:00
|
|
|
{
|
|
|
|
int i;
|
2018-01-10 21:12:23 +01:00
|
|
|
vorbis_comment *comment = ov_comment(ovf,OGG_DEFAULT_BITSTREAM);
|
|
|
|
|
|
|
|
for (i = 0; i < comment->comments; i++) {
|
|
|
|
const char * user_comment = comment->user_comments[i];
|
|
|
|
if (strstr(user_comment,"loop_start=")==user_comment || /* PSO4 */
|
|
|
|
strstr(user_comment,"LOOP_START=")==user_comment || /* PSO4 */
|
|
|
|
strstr(user_comment,"COMMENT=LOOPPOINT=")==user_comment ||
|
|
|
|
strstr(user_comment,"LOOPSTART=")==user_comment ||
|
|
|
|
strstr(user_comment,"um3.stream.looppoint.start=")==user_comment ||
|
|
|
|
strstr(user_comment,"LOOP_BEGIN=")==user_comment || /* Hatsune Miku: Project Diva F (PS3) */
|
2018-03-30 03:03:23 +02:00
|
|
|
strstr(user_comment,"LoopStart=")==user_comment || /* Devil May Cry 4 (PC) */
|
2018-03-30 03:10:05 +02:00
|
|
|
strstr(user_comment,"XIPH_CUE_LOOPSTART=")==user_comment) { /* Super Mario Run (Android) */
|
2018-01-10 21:12:23 +01:00
|
|
|
loop_start = atol(strrchr(user_comment,'=')+1);
|
|
|
|
loop_flag = (loop_start >= 0);
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
else if (strstr(user_comment,"LOOPLENGTH=")==user_comment) {/* (LOOPSTART pair) */
|
|
|
|
loop_length = atol(strrchr(user_comment,'=')+1);
|
|
|
|
loop_length_found = 1;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2018-03-03 01:10:39 +01:00
|
|
|
else if (strstr(user_comment,"title=-lps")==user_comment) { /* KID [Memories Off #5 (PC), Remember11 (PC)] */
|
2018-01-10 21:12:23 +01:00
|
|
|
loop_start = atol(user_comment+10);
|
|
|
|
loop_flag = (loop_start >= 0);
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
else if (strstr(user_comment,"album=-lpe")==user_comment) { /* (title=-lps pair) */
|
|
|
|
loop_end = atol(user_comment+10);
|
|
|
|
loop_flag = 1;
|
|
|
|
loop_end_found = 1;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
else if (strstr(user_comment,"LoopEnd=")==user_comment) { /* (LoopStart pair) */
|
|
|
|
if(loop_flag) {
|
|
|
|
loop_length = atol(strrchr(user_comment,'=')+1)-loop_start;
|
|
|
|
loop_length_found = 1;
|
|
|
|
}
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
else if (strstr(user_comment,"LOOP_END=")==user_comment) { /* (LOOP_BEGIN pair) */
|
|
|
|
if(loop_flag) {
|
|
|
|
loop_length = atol(strrchr(user_comment,'=')+1)-loop_start;
|
|
|
|
loop_length_found = 1;
|
|
|
|
}
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
else if (strstr(user_comment,"lp=")==user_comment) {
|
|
|
|
sscanf(strrchr(user_comment,'=')+1,"%d,%d", &loop_start,&loop_end);
|
|
|
|
loop_flag = 1;
|
|
|
|
loop_end_found = 1;
|
2017-02-18 08:04:16 +01:00
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
else if (strstr(user_comment,"LOOPDEFS=")==user_comment) { /* Fairy Fencer F: Advent Dark Force */
|
|
|
|
sscanf(strrchr(user_comment,'=')+1,"%d,%d", &loop_start,&loop_end);
|
|
|
|
loop_flag = 1;
|
|
|
|
loop_end_found = 1;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
else if (strstr(user_comment,"COMMENT=loop(")==user_comment) { /* Zero Time Dilemma (PC) */
|
|
|
|
sscanf(strrchr(user_comment,'(')+1,"%d,%d", &loop_start,&loop_end);
|
|
|
|
loop_flag = 1;
|
|
|
|
loop_end_found = 1;
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
2018-03-30 03:10:05 +02:00
|
|
|
else if (strstr(user_comment, "XIPH_CUE_LOOPEND=") == user_comment) { /* XIPH_CUE_LOOPSTART pair */
|
|
|
|
if (loop_flag) {
|
|
|
|
loop_length = atol(strrchr(user_comment, '=') + 1) - loop_start;
|
|
|
|
loop_length_found = 1;
|
|
|
|
}
|
2018-07-27 17:30:58 +02:00
|
|
|
}
|
2018-07-20 07:14:41 +02:00
|
|
|
else if (strstr(user_comment, "omment=") == user_comment) { /* Air (Android) */
|
|
|
|
sscanf(strstr(user_comment, "=LOOPSTART=") + 11, "%d,LOOPEND=%d", &loop_start, &loop_end);
|
|
|
|
loop_flag = 1;
|
|
|
|
loop_end_found = 1;
|
|
|
|
}
|
2018-07-27 17:30:58 +02:00
|
|
|
else if (strstr(user_comment,"MarkerNum=0002")==user_comment) { /* Megaman X Legacy Collection: MMX1/2/3 (PC) flag */
|
|
|
|
/* uses LoopStart=-1 LoopEnd=-1, then 3 secuential comments: "MarkerNum" + "M=7F(start)" + "M=7F(end)" */
|
|
|
|
loop_flag = 1;
|
|
|
|
}
|
|
|
|
else if (strstr(user_comment,"M=7F")==user_comment) { /* Megaman X Legacy Collection: MMX1/2/3 (PC) start/end */
|
|
|
|
if (loop_flag && loop_start < 0) { /* LoopStart should set as -1 before */
|
|
|
|
sscanf(user_comment,"M=7F%x", &loop_start);
|
|
|
|
}
|
|
|
|
else if (loop_flag && loop_start >= 0) {
|
|
|
|
sscanf(user_comment,"M=7F%x", &loop_end);
|
|
|
|
loop_end_found = 1;
|
|
|
|
}
|
|
|
|
}
|
2018-04-20 17:02:56 +02:00
|
|
|
|
2018-10-04 20:43:23 +02:00
|
|
|
;VGM_LOG("OGG: user_comment=%s\n", user_comment);
|
2016-11-12 00:39:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
|
2016-11-12 00:39:40 +01:00
|
|
|
/* build the VGMSTREAM */
|
2018-01-10 21:12:23 +01:00
|
|
|
vgmstream = allocate_vgmstream(vi->channels,loop_flag);
|
2016-11-12 00:39:40 +01:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
vgmstream->codec_data = data; /* store our fun extra datas */
|
|
|
|
vgmstream->channels = vi->channels;
|
|
|
|
vgmstream->sample_rate = vi->rate;
|
2018-03-23 16:34:48 +01:00
|
|
|
vgmstream->num_streams = ovmi->total_subsongs;
|
2018-01-28 00:41:25 +01:00
|
|
|
vgmstream->stream_size = stream_size;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2018-01-10 21:12:23 +01:00
|
|
|
vgmstream->num_samples = ov_pcm_total(ovf,-1); /* let libvorbisfile find total samples */
|
2016-11-12 00:39:40 +01:00
|
|
|
if (loop_flag) {
|
|
|
|
vgmstream->loop_start_sample = loop_start;
|
|
|
|
if (loop_length_found)
|
|
|
|
vgmstream->loop_end_sample = loop_start+loop_length;
|
|
|
|
else if (loop_end_found)
|
|
|
|
vgmstream->loop_end_sample = loop_end;
|
|
|
|
else
|
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
|
|
|
|
if (vgmstream->loop_end_sample > vgmstream->num_samples)
|
|
|
|
vgmstream->loop_end_sample = vgmstream->num_samples;
|
|
|
|
}
|
2018-01-10 21:12:23 +01:00
|
|
|
|
2018-03-08 23:32:58 +01:00
|
|
|
vgmstream->coding_type = coding_OGG_VORBIS;
|
2018-03-23 16:34:48 +01:00
|
|
|
vgmstream->layout_type = layout_none;
|
|
|
|
vgmstream->meta_type = ovmi->meta_type;
|
2016-11-12 00:39:40 +01:00
|
|
|
|
2019-03-02 15:57:41 +01:00
|
|
|
if (vgmstream->channels <= 8) {
|
|
|
|
vgmstream->channel_layout = xiph_mappings[vgmstream->channels];
|
|
|
|
}
|
|
|
|
|
2016-11-12 00:39:40 +01:00
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2018-01-10 21:12:23 +01:00
|
|
|
/* clean up anything we may have opened */
|
2016-11-12 00:39:40 +01:00
|
|
|
if (data) {
|
2018-01-10 21:12:23 +01:00
|
|
|
if (ovf)
|
|
|
|
ov_clear(&data->ogg_vorbis_file);//same as ovf
|
2016-11-12 00:39:40 +01:00
|
|
|
if (data->ov_streamfile.streamfile)
|
|
|
|
close_streamfile(data->ov_streamfile.streamfile);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
if (vgmstream) {
|
|
|
|
vgmstream->codec_data = NULL;
|
|
|
|
close_vgmstream(vgmstream);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|