2010-03-21 05:23:18 +01:00
|
|
|
#include "coding.h"
|
|
|
|
#include "../util.h"
|
|
|
|
|
2017-04-29 22:37:15 +02:00
|
|
|
#ifdef VGM_USE_G7221
|
|
|
|
|
2017-10-14 12:41:59 +02:00
|
|
|
g7221_codec_data * init_g7221(int channel_count, int frame_size) {
|
|
|
|
int i;
|
|
|
|
g7221_codec_data *data = NULL;
|
|
|
|
|
|
|
|
data = calloc(channel_count, sizeof(g7221_codec_data)); /* one decoder per channel */
|
|
|
|
if (!data) goto fail;
|
|
|
|
|
|
|
|
for (i = 0; i < channel_count; i++) {
|
|
|
|
data[i].handle = g7221_init(frame_size, 14000); /* Siren 14 == 14khz bandwidth */
|
|
|
|
if (!data[i].handle) goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (data) {
|
|
|
|
for (i = 0; i < channel_count; i++) {
|
|
|
|
g7221_free(data[i].handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(data);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-29 22:37:15 +02:00
|
|
|
void decode_g7221(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing, int32_t samples_to_do, int channel) {
|
2010-03-23 21:57:12 +01:00
|
|
|
VGMSTREAMCHANNEL *ch = &vgmstream->ch[channel];
|
|
|
|
g7221_codec_data *data = vgmstream->codec_data;
|
|
|
|
g7221_codec_data *ch_data = &data[channel];
|
|
|
|
int i;
|
2010-03-21 05:23:18 +01:00
|
|
|
|
|
|
|
if (0 == vgmstream->samples_into_block)
|
|
|
|
{
|
2010-03-23 21:57:12 +01:00
|
|
|
int16_t code_buffer[960/8];
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
outbuf[i*channelspacing] = ch_data->buffer[vgmstream->samples_into_block+i];
|
2010-03-21 05:23:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-29 22:37:15 +02:00
|
|
|
|
|
|
|
void reset_g7221(VGMSTREAM *vgmstream) {
|
|
|
|
g7221_codec_data *data = vgmstream->codec_data;
|
|
|
|
int i;
|
2018-03-10 16:59:00 +01:00
|
|
|
if (!data) return;
|
2017-04-29 22:37:15 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < vgmstream->channels; i++)
|
|
|
|
{
|
|
|
|
g7221_free(data[i].handle);
|
|
|
|
}
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-21 05:23:18 +01:00
|
|
|
#endif
|