diff --git a/src/coding/g719_decoder.c b/src/coding/g719_decoder.c index ab3cb829..78e1f023 100644 --- a/src/coding/g719_decoder.c +++ b/src/coding/g719_decoder.c @@ -1,13 +1,16 @@ #include "coding.h" -#include "../util.h" #ifdef VGM_USE_G719 -#include "../stack_alloc.h" +#define G719_MAX_CODES (960/8) /* max frame 0xF0 uint8s = 0xF0/2 uint16s = 960/8 */ + 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) + goto fail; + data = calloc(channel_count, sizeof(g719_codec_data)); /* one decoder per channel */ if (!data) goto fail; @@ -29,22 +32,20 @@ fail: return NULL; } + void decode_g719(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing, int32_t samples_to_do, int channel) { VGMSTREAMCHANNEL *ch = &vgmstream->ch[channel]; g719_codec_data *data = vgmstream->codec_data; g719_codec_data *ch_data = &data[channel]; int i; - if (0 == vgmstream->samples_into_block) - { - VARDECL(int16_t,code_buffer); - ALLOC(code_buffer, vgmstream->interleave_block_size / 2, int16_t); + 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); } - for (i = 0; i < samples_to_do; i++) - { + for (i = 0; i < samples_to_do; i++) { outbuf[i*channelspacing] = ch_data->buffer[vgmstream->samples_into_block+i]; } } @@ -55,25 +56,20 @@ void reset_g719(VGMSTREAM *vgmstream) { int i; if (!data) return; - for (i = 0; i < vgmstream->channels; i++) - { + for (i = 0; i < vgmstream->channels; i++) { g719_reset(data[i].handle); } } void free_g719(VGMSTREAM *vgmstream) { g719_codec_data *data = (g719_codec_data *) vgmstream->codec_data; + int i; + if (!data) return; - if (data) - { - int i; - - for (i = 0; i < vgmstream->channels; i++) - { - g719_free(data[i].handle); - } - free(data); + for (i = 0; i < vgmstream->channels; i++) { + g719_free(data[i].handle); } + free(data); } #endif diff --git a/src/coding/g7221_decoder.c b/src/coding/g7221_decoder.c index 648a8b57..6915d995 100644 --- a/src/coding/g7221_decoder.c +++ b/src/coding/g7221_decoder.c @@ -1,12 +1,16 @@ #include "coding.h" -#include "../util.h" #ifdef VGM_USE_G7221 +#define G7221_MAX_CODES (960/8) /* max frame 0xF0 uint8s = 0xF0/2 uint16s = 960/8 */ + g7221_codec_data * init_g7221(int channel_count, int frame_size) { int i; g7221_codec_data *data = NULL; + if (frame_size / sizeof(int16_t) > G7221_MAX_CODES) + goto fail; + data = calloc(channel_count, sizeof(g7221_codec_data)); /* one decoder per channel */ if (!data) goto fail; @@ -35,15 +39,13 @@ void decode_g7221(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing, in g7221_codec_data *ch_data = &data[channel]; int i; - if (0 == vgmstream->samples_into_block) - { - int16_t code_buffer[960/8]; + if (0 == vgmstream->samples_into_block) { + int16_t code_buffer[G7221_MAX_CODES]; vgmstream->ch[channel].streamfile->read(ch->streamfile, (uint8_t*)code_buffer, ch->offset, vgmstream->interleave_block_size); g7221_decode_frame(ch_data->handle, code_buffer, ch_data->buffer); } - for (i = 0; i < samples_to_do; i++) - { + for (i = 0; i < samples_to_do; i++) { outbuf[i*channelspacing] = ch_data->buffer[vgmstream->samples_into_block+i]; } } @@ -54,25 +56,20 @@ void reset_g7221(VGMSTREAM *vgmstream) { int i; if (!data) return; - for (i = 0; i < vgmstream->channels; i++) - { + for (i = 0; i < vgmstream->channels; i++) { g7221_reset(data[i].handle); } } void free_g7221(VGMSTREAM *vgmstream) { g7221_codec_data *data = (g7221_codec_data *) vgmstream->codec_data; + int i; + if (!data) return; - if (data) - { - int i; - - for (i = 0; i < vgmstream->channels; i++) - { - g7221_free(data[i].handle); - } - free(data); + for (i = 0; i < vgmstream->channels; i++) { + g7221_free(data[i].handle); } + free(data); } #endif diff --git a/src/meta/ktss.c b/src/meta/ktss.c index 2f2bccc6..76339eb7 100644 --- a/src/meta/ktss.c +++ b/src/meta/ktss.c @@ -1,6 +1,4 @@ #include "meta.h" -#include "../util.h" -#include "../stack_alloc.h" #include "../coding/coding.h" VGMSTREAM * init_vgmstream_ktss(STREAMFILE *streamFile) { diff --git a/src/meta/ngc_dsp_std.c b/src/meta/ngc_dsp_std.c index c310ae9b..2c3e3718 100644 --- a/src/meta/ngc_dsp_std.c +++ b/src/meta/ngc_dsp_std.c @@ -1,8 +1,7 @@ #include "meta.h" #include "../layout/layout.h" #include "../coding/coding.h" -#include "../util.h" -#include "../stack_alloc.h" + /* If these variables are packed properly in the struct (one after another) * then this is actually how they are laid out in the file, albeit big-endian */