Skip to content

Commit

Permalink
Updated VGMStream to r1050-3714-g82dd9a7d
Browse files Browse the repository at this point in the history
  • Loading branch information
kode54 committed May 16, 2021
1 parent 95a6332 commit 7181656
Show file tree
Hide file tree
Showing 5 changed files with 632 additions and 603 deletions.
68 changes: 35 additions & 33 deletions Frameworks/vgmstream/vgmstream/src/coding/mpeg_decoder.c
Expand Up @@ -9,18 +9,18 @@

#define MPEG_DATA_BUFFER_SIZE 0x1000 /* at least one MPEG frame (max ~0x5A1 plus some more in case of free bitrate) */

static mpg123_handle * init_mpg123_handle();
static void decode_mpeg_standard(VGMSTREAMCHANNEL *stream, mpeg_codec_data * data, sample_t * outbuf, int32_t samples_to_do, int channels);
static void decode_mpeg_custom(VGMSTREAM * vgmstream, mpeg_codec_data * data, sample_t * outbuf, int32_t samples_to_do, int channels);
static void decode_mpeg_custom_stream(VGMSTREAMCHANNEL *stream, mpeg_codec_data * data, int num_stream);
static mpg123_handle* init_mpg123_handle();
static void decode_mpeg_standard(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, sample_t* outbuf, int32_t samples_to_do, int channels);
static void decode_mpeg_custom(VGMSTREAM* vgmstream, mpeg_codec_data* data, sample_t* outbuf, int32_t samples_to_do, int channels);
static void decode_mpeg_custom_stream(VGMSTREAMCHANNEL *stream, mpeg_codec_data* data, int num_stream);


/* Inits regular MPEG */
mpeg_codec_data *init_mpeg(STREAMFILE *streamfile, off_t start_offset, coding_t *coding_type, int channels) {
mpeg_codec_data *data = NULL;
mpeg_codec_data* init_mpeg(STREAMFILE* sf, off_t start_offset, coding_t* coding_type, int channels) {
mpeg_codec_data* data = NULL;

/* init codec */
data = calloc(1,sizeof(mpeg_codec_data));
data = calloc(1, sizeof(mpeg_codec_data));
if (!data) goto fail;

data->buffer_size = MPEG_DATA_BUFFER_SIZE;
Expand All @@ -41,14 +41,16 @@ mpeg_codec_data *init_mpeg(STREAMFILE *streamfile, off_t start_offset, coding_t
size_t samples_per_frame;
struct mpg123_frameinfo mi;

//todo read single big buffer then add +1 up to a few max bytes, or just read once only
/* read first frame(s) */
do {
size_t bytes_done;
if (read_streamfile(data->buffer, start_offset+read_offset, data->buffer_size, streamfile) != data->buffer_size)
goto fail;
read_offset+=1;
size_t bytes_read, bytes_done;

/* don't check max as sfx can be smaller than buffer */
bytes_read = read_streamfile(data->buffer, start_offset + read_offset, data->buffer_size, sf);
read_offset += 1;

rc = mpg123_decode(main_m, data->buffer,data->buffer_size, NULL,0, &bytes_done);
rc = mpg123_decode(main_m, data->buffer, bytes_read, NULL,0, &bytes_done);
if (rc != MPG123_OK && rc != MPG123_NEW_FORMAT && rc != MPG123_NEED_MORE) {
VGM_LOG("MPEG: unable to set up mpg123 at start offset\n");
goto fail; //handle MPG123_DONE?
Expand Down Expand Up @@ -111,12 +113,12 @@ mpeg_codec_data *init_mpeg(STREAMFILE *streamfile, off_t start_offset, coding_t


/* Init custom MPEG, with given type and config */
mpeg_codec_data *init_mpeg_custom(STREAMFILE *streamFile, off_t start_offset, coding_t *coding_type, int channels, mpeg_custom_t type, mpeg_custom_config *config) {
mpeg_codec_data *data = NULL;
mpeg_codec_data* init_mpeg_custom(STREAMFILE* sf, off_t start_offset, coding_t* coding_type, int channels, mpeg_custom_t type, mpeg_custom_config* config) {
mpeg_codec_data* data = NULL;
int i, ok;

/* init codec */
data = calloc(1,sizeof(mpeg_codec_data));
data = calloc(1, sizeof(mpeg_codec_data));
if (!data) goto fail;

/* keep around to decode */
Expand All @@ -132,10 +134,10 @@ mpeg_codec_data *init_mpeg_custom(STREAMFILE *streamFile, off_t start_offset, co
case MPEG_EAL31:
case MPEG_EAL31b:
case MPEG_EAL32P:
case MPEG_EAL32S: ok = mpeg_custom_setup_init_ealayer3(streamFile, start_offset, data, coding_type); break;
case MPEG_AWC: ok = mpeg_custom_setup_init_awc(streamFile, start_offset, data, coding_type); break;
case MPEG_EAMP3: ok = mpeg_custom_setup_init_eamp3(streamFile, start_offset, data, coding_type); break;
default: ok = mpeg_custom_setup_init_default(streamFile, start_offset, data, coding_type); break;
case MPEG_EAL32S: ok = mpeg_custom_setup_init_ealayer3(sf, start_offset, data, coding_type); break;
case MPEG_AWC: ok = mpeg_custom_setup_init_awc(sf, start_offset, data, coding_type); break;
case MPEG_EAMP3: ok = mpeg_custom_setup_init_eamp3(sf, start_offset, data, coding_type); break;
default: ok = mpeg_custom_setup_init_default(sf, start_offset, data, coding_type); break;
}
if (!ok)
goto fail;
Expand Down Expand Up @@ -183,12 +185,12 @@ mpeg_codec_data *init_mpeg_custom(STREAMFILE *streamFile, off_t start_offset, co
}


static mpg123_handle * init_mpg123_handle() {
mpg123_handle *m = NULL;
static mpg123_handle* init_mpg123_handle() {
mpg123_handle* m = NULL;
int rc;

/* inits a new mpg123 handle */
m = mpg123_new(NULL,&rc);
m = mpg123_new(NULL, &rc);
if (rc == MPG123_NOT_INITIALIZED) {
/* inits the library if needed */
if (mpg123_init() != MPG123_OK)
Expand Down Expand Up @@ -218,8 +220,8 @@ static mpg123_handle * init_mpg123_handle() {
/* DECODERS */
/************/

void decode_mpeg(VGMSTREAM * vgmstream, sample_t * outbuf, int32_t samples_to_do, int channels) {
mpeg_codec_data * data = (mpeg_codec_data *) vgmstream->codec_data;
void decode_mpeg(VGMSTREAM* vgmstream, sample_t* outbuf, int32_t samples_to_do, int channels) {
mpeg_codec_data* data = vgmstream->codec_data;

if (!data->custom) {
decode_mpeg_standard(&vgmstream->ch[0], data, outbuf, samples_to_do, channels);
Expand All @@ -232,7 +234,7 @@ void decode_mpeg(VGMSTREAM * vgmstream, sample_t * outbuf, int32_t samples_to_do
* Decode anything mpg123 can.
* Feeds raw data and extracts decoded samples as needed.
*/
static void decode_mpeg_standard(VGMSTREAMCHANNEL *stream, mpeg_codec_data * data, sample_t * outbuf, int32_t samples_to_do, int channels) {
static void decode_mpeg_standard(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, sample_t* outbuf, int32_t samples_to_do, int channels) {
int samples_done = 0;
unsigned char *outbytes = (unsigned char *)outbuf;

Expand Down Expand Up @@ -287,7 +289,7 @@ static void decode_mpeg_standard(VGMSTREAMCHANNEL *stream, mpeg_codec_data * dat
* Copies to outbuf when there are samples in all streams and calls decode_mpeg_custom_stream to decode.
. Depletes the stream's sample buffers before decoding more, so it doesn't run out of buffer space.
*/
static void decode_mpeg_custom(VGMSTREAM * vgmstream, mpeg_codec_data * data, sample_t * outbuf, int32_t samples_to_do, int channels) {
static void decode_mpeg_custom(VGMSTREAM* vgmstream, mpeg_codec_data* data, sample_t* outbuf, int32_t samples_to_do, int channels) {
int i, samples_done = 0;

while (samples_done < samples_to_do) {
Expand Down Expand Up @@ -366,7 +368,7 @@ static void decode_mpeg_custom(VGMSTREAM * vgmstream, mpeg_codec_data * data, sa

/* Decodes frames from a stream into the stream's sample buffer, feeding mpg123 buffer data.
* If not enough data to decode (as N data-frames = 1 full-frame) this will exit but be called again. */
static void decode_mpeg_custom_stream(VGMSTREAMCHANNEL *stream, mpeg_codec_data * data, int num_stream) {
static void decode_mpeg_custom_stream(VGMSTREAMCHANNEL* stream, mpeg_codec_data* data, int num_stream) {
size_t bytes_done = 0, bytes_filled, samples_filled;
size_t stream_size = get_streamfile_size(stream->streamfile);
int rc, ok;
Expand Down Expand Up @@ -476,7 +478,7 @@ static void decode_mpeg_custom_stream(VGMSTREAMCHANNEL *stream, mpeg_codec_data
/* UTILS */
/*********/

void free_mpeg(mpeg_codec_data *data) {
void free_mpeg(mpeg_codec_data* data) {
if (!data)
return;

Expand Down Expand Up @@ -528,8 +530,8 @@ void reset_mpeg(mpeg_codec_data* data) {
}

/* seeks to a point */
void seek_mpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
mpeg_codec_data *data = vgmstream->codec_data;
void seek_mpeg(VGMSTREAM* vgmstream, int32_t num_sample) {
mpeg_codec_data* data = vgmstream->codec_data;
if (!data) return;


Expand Down Expand Up @@ -561,7 +563,7 @@ void seek_mpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
}

/* resets mpg123 decoder and its internals without seeking, useful when a new MPEG substream starts */
void flush_mpeg(mpeg_codec_data * data) {
void flush_mpeg(mpeg_codec_data* data) {
if (!data)
return;

Expand Down Expand Up @@ -596,7 +598,7 @@ int mpeg_get_sample_rate(mpeg_codec_data* data) {
return data->sample_rate_per_frame;
}

long mpeg_bytes_to_samples(long bytes, const mpeg_codec_data *data) {
long mpeg_bytes_to_samples(long bytes, const mpeg_codec_data* data) {
/* if not found just return 0 and expect to fail (if used for num_samples) */
if (!data->custom) {
/* We would need to read all VBR frames headers to count samples */
Expand All @@ -619,7 +621,7 @@ long mpeg_bytes_to_samples(long bytes, const mpeg_codec_data *data) {

#if 0
/* disables/enables stderr output, for MPEG known to contain recoverable errors */
void mpeg_set_error_logging(mpeg_codec_data * data, int enable) {
void mpeg_set_error_logging(mpeg_codec_data* data, int enable) {
if (!data->custom) {
mpg123_param(data->m, MPG123_ADD_FLAGS, MPG123_QUIET, !enable);
}
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/vgmstream/vgmstream/src/formats.c
Expand Up @@ -1101,7 +1101,7 @@ static const meta_info meta_info_list[] = {
{meta_CAFF, "Apple Core Audio Format File header"},
{meta_PC_MXST, "Lego Island MxSt Header"},
{meta_SAB, "Sensaura SAB header"},
{meta_MAXIS_XA, "Maxis XAI/XAJ Header"},
{meta_MAXIS_XA, "Maxis XA Header"},
{meta_EXAKT_SC, "assumed Activision / EXAKT SC by extension"},
{meta_WII_BNS, "Nintendo BNS header"},
{meta_WII_WAS, "Sumo Digital iSWS header"},
Expand Down

0 comments on commit 7181656

Please sign in to comment.