decoder/mikmod: static mod_Data object
Don't allocate this object, put it on the stack.
This commit is contained in:
@@ -131,48 +131,46 @@ typedef struct _mod_Data {
|
|||||||
SBYTE audio_buffer[MIKMOD_FRAME_SIZE];
|
SBYTE audio_buffer[MIKMOD_FRAME_SIZE];
|
||||||
} mod_Data;
|
} mod_Data;
|
||||||
|
|
||||||
static mod_Data *mod_open(const char *path)
|
static bool
|
||||||
|
mod_open(mod_Data *data, const char *path)
|
||||||
{
|
{
|
||||||
char *path2;
|
char *path2;
|
||||||
MODULE *moduleHandle;
|
MODULE *moduleHandle;
|
||||||
mod_Data *data;
|
|
||||||
|
|
||||||
path2 = g_strdup(path);
|
path2 = g_strdup(path);
|
||||||
moduleHandle = Player_Load(path2, 128, 0);
|
moduleHandle = Player_Load(path2, 128, 0);
|
||||||
g_free(path2);
|
g_free(path2);
|
||||||
|
|
||||||
if (moduleHandle == NULL)
|
if (moduleHandle == NULL)
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
/* Prevent module from looping forever */
|
/* Prevent module from looping forever */
|
||||||
moduleHandle->loop = 0;
|
moduleHandle->loop = 0;
|
||||||
|
|
||||||
data = g_new(mod_Data, 1);
|
|
||||||
data->moduleHandle = moduleHandle;
|
data->moduleHandle = moduleHandle;
|
||||||
|
|
||||||
Player_Start(data->moduleHandle);
|
Player_Start(data->moduleHandle);
|
||||||
|
|
||||||
return data;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mod_close(mod_Data * data)
|
static void mod_close(mod_Data * data)
|
||||||
{
|
{
|
||||||
Player_Stop();
|
Player_Stop();
|
||||||
Player_Free(data->moduleHandle);
|
Player_Free(data->moduleHandle);
|
||||||
g_free(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mod_decode(struct decoder *decoder, const char *path)
|
mod_decode(struct decoder *decoder, const char *path)
|
||||||
{
|
{
|
||||||
mod_Data *data;
|
mod_Data data;
|
||||||
struct audio_format audio_format;
|
struct audio_format audio_format;
|
||||||
float total_time = 0.0;
|
float total_time = 0.0;
|
||||||
int ret;
|
int ret;
|
||||||
float secPerByte;
|
float secPerByte;
|
||||||
enum decoder_command cmd = DECODE_COMMAND_NONE;
|
enum decoder_command cmd = DECODE_COMMAND_NONE;
|
||||||
|
|
||||||
if (!(data = mod_open(path))) {
|
if (!mod_open(&data, path)) {
|
||||||
g_warning("failed to open mod: %s\n", path);
|
g_warning("failed to open mod: %s\n", path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -187,14 +185,14 @@ mod_decode(struct decoder *decoder, const char *path)
|
|||||||
decoder_initialized(decoder, &audio_format, false, 0);
|
decoder_initialized(decoder, &audio_format, false, 0);
|
||||||
|
|
||||||
while (cmd == DECODE_COMMAND_NONE && Player_Active()) {
|
while (cmd == DECODE_COMMAND_NONE && Player_Active()) {
|
||||||
ret = VC_WriteBytes(data->audio_buffer, MIKMOD_FRAME_SIZE);
|
ret = VC_WriteBytes(data.audio_buffer, MIKMOD_FRAME_SIZE);
|
||||||
total_time += ret * secPerByte;
|
total_time += ret * secPerByte;
|
||||||
cmd = decoder_data(decoder, NULL,
|
cmd = decoder_data(decoder, NULL,
|
||||||
data->audio_buffer, ret,
|
data.audio_buffer, ret,
|
||||||
total_time, 0, NULL);
|
total_time, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
mod_close(data);
|
mod_close(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct tag *modTagDup(const char *file)
|
static struct tag *modTagDup(const char *file)
|
||||||
|
Reference in New Issue
Block a user