diff --git a/src/coding/coding.h b/src/coding/coding.h index c11f9408..cd12a8ad 100644 --- a/src/coding/coding.h +++ b/src/coding/coding.h @@ -221,8 +221,8 @@ void free_g7221(VGMSTREAM *vgmstream); /* g719_decoder */ g719_codec_data *init_g719(int channel_count, int frame_size); void decode_g719(VGMSTREAM *vgmstream, sample * outbuf, int channelspacing, int32_t samples_to_do, int channel); -void reset_g719(VGMSTREAM *vgmstream); -void free_g719(VGMSTREAM *vgmstream); +void reset_g719(g719_codec_data * data, int channels); +void free_g719(g719_codec_data * data, int channels); #endif #if defined(VGM_USE_MP4V2) && defined(VGM_USE_FDKAAC) diff --git a/src/coding/g719_decoder.c b/src/coding/g719_decoder.c index f498f9cd..f0a78e13 100644 --- a/src/coding/g719_decoder.c +++ b/src/coding/g719_decoder.c @@ -1,14 +1,15 @@ #include "coding.h" +#include #ifdef VGM_USE_G719 -#define G719_MAX_CODES ((1280/8)) /* in int16, so max frame size is (value/8)*2 (known values: 0xF0=common, 0x140=rare) */ +#define G719_MAX_FRAME_SIZE 0x1000 /* arbitrary max (samples per frame seems to always be 960) */ g719_codec_data *init_g719(int channel_count, int frame_size) { int i; g719_codec_data *data = NULL; - if (frame_size / sizeof(int16_t) > G719_MAX_CODES) + if (frame_size / sizeof(int16_t) > G719_MAX_FRAME_SIZE) goto fail; data = calloc(channel_count, sizeof(g719_codec_data)); /* one decoder per channel */ @@ -17,6 +18,10 @@ g719_codec_data *init_g719(int channel_count, int frame_size) { for (i = 0; i < channel_count; i++) { data[i].handle = g719_init(frame_size); /* Siren 22 == 22khz bandwidth */ if (!data[i].handle) goto fail; + + /* known values: 0xF0=common (sizeof(int16) * 960/8), 0x140=rare (sizeof(int16) * 1280/8) */ + data[i].code_buffer = malloc(sizeof(int16_t) * frame_size); + if (!data[i].code_buffer) goto fail; } return data; @@ -40,9 +45,8 @@ void decode_g719(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing, int int i; if (0 == vgmstream->samples_into_block) { - int16_t code_buffer[G719_MAX_CODES]; - vgmstream->ch[channel].streamfile->read(ch->streamfile, (uint8_t*)code_buffer, ch->offset, vgmstream->interleave_block_size); - g719_decode_frame(ch_data->handle, code_buffer, ch_data->buffer); + read_streamfile((uint8_t*)ch_data->code_buffer, ch->offset, vgmstream->interleave_block_size, ch->streamfile); + g719_decode_frame(ch_data->handle, ch_data->code_buffer, ch_data->buffer); } for (i = 0; i < samples_to_do; i++) { @@ -51,23 +55,22 @@ void decode_g719(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing, int } -void reset_g719(VGMSTREAM *vgmstream) { - g719_codec_data *data = vgmstream->codec_data; +void reset_g719(g719_codec_data * data, int channels) { int i; if (!data) return; - for (i = 0; i < vgmstream->channels; i++) { + for (i = 0; i < channels; i++) { g719_reset(data[i].handle); } } -void free_g719(VGMSTREAM *vgmstream) { - g719_codec_data *data = (g719_codec_data *) vgmstream->codec_data; +void free_g719(g719_codec_data * data, int channels) { int i; if (!data) return; - for (i = 0; i < vgmstream->channels; i++) { + for (i = 0; i < channels; i++) { g719_free(data[i].handle); + free(data[i].code_buffer); } free(data); } diff --git a/src/vgmstream.c b/src/vgmstream.c index 7792bdb6..159dd605 100644 --- a/src/vgmstream.c +++ b/src/vgmstream.c @@ -604,7 +604,7 @@ void reset_vgmstream(VGMSTREAM * vgmstream) { #ifdef VGM_USE_G719 if (vgmstream->coding_type==coding_G719) { - reset_g719(vgmstream); + reset_g719(vgmstream->codec_data, vgmstream->channels); } #endif @@ -789,7 +789,7 @@ void close_vgmstream(VGMSTREAM * vgmstream) { #ifdef VGM_USE_G719 if (vgmstream->coding_type == coding_G719) { - free_g719(vgmstream); + free_g719(vgmstream->codec_data, vgmstream->channels); vgmstream->codec_data = NULL; } #endif diff --git a/src/vgmstream.h b/src/vgmstream.h index a7eda656..17fc75df 100644 --- a/src/vgmstream.h +++ b/src/vgmstream.h @@ -36,10 +36,6 @@ enum { STREAM_NAME_SIZE = 255 }; /* reasonable max */ #include #endif -#ifdef VGM_USE_G719 -#include -#endif - #ifdef VGM_USE_MP4V2 #define MP4V2_NO_STDINT_DEFS #include @@ -1031,7 +1027,8 @@ typedef struct { #ifdef VGM_USE_G719 typedef struct { sample buffer[960]; - g719_handle *handle; + void *handle; + int16_t *code_buffer; } g719_codec_data; #endif