Clean G719/G7221 a bit and remove innecessary use of stack_alloc

This commit is contained in:
bnnm 2018-08-14 22:20:36 +02:00
parent 985a3aead6
commit 65a69982b6
4 changed files with 30 additions and 40 deletions

View File

@ -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

View File

@ -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

View File

@ -1,6 +1,4 @@
#include "meta.h"
#include "../util.h"
#include "../stack_alloc.h"
#include "../coding/coding.h"
VGMSTREAM * init_vgmstream_ktss(STREAMFILE *streamFile) {

View File

@ -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 */