diff options
author | 2010-06-26 12:49:46 +0200 | |
---|---|---|
committer | 2010-06-26 12:49:46 +0200 | |
commit | 5888e168c4185d5cd62305acf558cb6a752a17f0 (patch) | |
tree | 6f1278505129be628d9543353345b703cf4463c9 /plugins/ao/eng_dsf | |
parent | c4c49d34513458a2cb73bff87c6fe73b10a2c350 (diff) |
adding reentrant API to ao plugin WIP
Diffstat (limited to 'plugins/ao/eng_dsf')
-rw-r--r-- | plugins/ao/eng_dsf/eng_dsf.c | 89 |
1 files changed, 50 insertions, 39 deletions
diff --git a/plugins/ao/eng_dsf/eng_dsf.c b/plugins/ao/eng_dsf/eng_dsf.c index f6ac91ed..aa636def 100644 --- a/plugins/ao/eng_dsf/eng_dsf.c +++ b/plugins/ao/eng_dsf/eng_dsf.c @@ -28,15 +28,20 @@ #include "arm7core.h" #endif -static corlett_t *c = NULL; -static char psfby[256]; -static uint32 decaybegin, decayend, total_samples; +typedef struct { + corlett_t *c; + char psfby[256]; + uint32 decaybegin, decayend, total_samples; +} dsf_synth_t; void *aica_start(const void *config); void AICA_Update(void *param, INT16 **inputs, INT16 **buf, int samples); -int32 dsf_start(uint8 *buffer, uint32 length) +void *dsf_start(uint8 *buffer, uint32 length) { + dsf_synth_t *s = malloc (sizeof (dsf_synth_t)); + memset (s, 0, sizeof (dsf_synth_t)); + uint8 *file, *lib_decoded, *lib_raw_file; uint32 offset, plength, lengthMS, fadeMS; uint64 file_len, lib_len, lib_raw_length; @@ -48,9 +53,10 @@ int32 dsf_start(uint8 *buffer, uint32 length) memset(dc_ram, 0, 8*1024*1024); // Decode the current SSF - if (corlett_decode(buffer, length, &file, &file_len, &c) != AO_SUCCESS) + if (corlett_decode(buffer, length, &file, &file_len, &s->c) != AO_SUCCESS) { - return AO_FAIL; + dsf_stop (s); + return NULL; } #if DEBUG_LOADER @@ -59,7 +65,7 @@ int32 dsf_start(uint8 *buffer, uint32 length) // Get the library file, if any for (i=0; i<9; i++) { - libfile = i ? c->libaux[i-1] : c->lib; + libfile = i ? s->c->libaux[i-1] : s->c->lib; if (libfile[0] != 0) { uint64 tmp_length; @@ -69,14 +75,16 @@ int32 dsf_start(uint8 *buffer, uint32 length) #endif if (ao_get_lib(libfile, &lib_raw_file, &tmp_length) != AO_SUCCESS) { - return AO_FAIL; + dsf_stop (s); + return NULL; } lib_raw_length = tmp_length; if (corlett_decode(lib_raw_file, lib_raw_length, &lib_decoded, &lib_len, &lib) != AO_SUCCESS) { free(lib_raw_file); - return AO_FAIL; + dsf_stop (s); + return NULL; } // Free up raw file @@ -98,13 +106,13 @@ int32 dsf_start(uint8 *buffer, uint32 length) free(file); // Finally, set psfby/ssfby tag - strcpy(psfby, "n/a"); - if (c) + strcpy(s->psfby, "n/a"); + if (s->c) { for (i = 0; i < MAX_UNKNOWN_TAGS; i++) { - if ((!strcasecmp(c->tag_name[i], "psfby")) || (!strcasecmp(c->tag_name[i], "ssfby"))) - strcpy(psfby, c->tag_data[i]); + if ((!strcasecmp(s->c->tag_name[i], "psfby")) || (!strcasecmp(s->c->tag_name[i], "ssfby"))) + strcpy(s->psfby, s->c->tag_data[i]); } } @@ -127,9 +135,9 @@ int32 dsf_start(uint8 *buffer, uint32 length) dc_hw_init(); // now figure out the time in samples for the length/fade - lengthMS = psfTimeToMS(c->inf_length); - fadeMS = psfTimeToMS(c->inf_fade); - total_samples = 0; + lengthMS = psfTimeToMS(s->c->inf_length); + fadeMS = psfTimeToMS(s->c->inf_fade); + s->total_samples = 0; if (lengthMS == 0) { @@ -138,22 +146,24 @@ int32 dsf_start(uint8 *buffer, uint32 length) if (lengthMS == ~0) { - decaybegin = lengthMS; + s->decaybegin = lengthMS; } else { lengthMS = (lengthMS * 441) / 10; fadeMS = (fadeMS * 441) / 10; - decaybegin = lengthMS; - decayend = lengthMS + fadeMS; + s->decaybegin = lengthMS; + s->decayend = lengthMS + fadeMS; } - return AO_SUCCESS; + return s; } -int32 dsf_gen(int16 *buffer, uint32 samples) -{ +int32 dsf_gen(void *handle, int16 *buffer, uint32 samples) +{ + dsf_synth_t *s = handle; + int i; int16 output[44100/30], output2[44100/30]; int16 *stereo[2]; @@ -177,9 +187,9 @@ int32 dsf_gen(int16 *buffer, uint32 samples) for (i = 0; i < samples; i++) { // process the fade tags - if (total_samples >= decaybegin) + if (s->total_samples >= s->decaybegin) { - if (total_samples >= decayend) + if (s->total_samples >= s->decayend) { // song is done here, signal your player appropriately! // ao_song_done = 1; @@ -188,16 +198,16 @@ int32 dsf_gen(int16 *buffer, uint32 samples) } else { - int32 fader = 256 - (256*(total_samples - decaybegin)/(decayend-decaybegin)); + int32 fader = 256 - (256*(s->total_samples - s->decaybegin)/(s->decayend-s->decaybegin)); output[i] = (output[i] * fader)>>8; output2[i] = (output2[i] * fader)>>8; - total_samples++; + s->total_samples++; } } else { - total_samples++; + s->total_samples++; } *outp++ = output[i]; @@ -207,12 +217,12 @@ int32 dsf_gen(int16 *buffer, uint32 samples) return AO_SUCCESS; } -int32 dsf_stop(void) +int32 dsf_stop(void *handle) { return AO_SUCCESS; } -int32 dsf_command(int32 command, int32 parameter) +int32 dsf_command(void *handle, int32 command, int32 parameter) { switch (command) { @@ -223,34 +233,35 @@ int32 dsf_command(int32 command, int32 parameter) return AO_FAIL; } -int32 dsf_fill_info(ao_display_info *info) +int32 dsf_fill_info(void *handle, ao_display_info *info) { - if (c == NULL) + dsf_synth_t *s = handle; + if (s->c == NULL) return AO_FAIL; strcpy(info->title[1], "Name: "); - sprintf(info->info[1], "%s", c->inf_title); + sprintf(info->info[1], "%s", s->c->inf_title); strcpy(info->title[2], "Game: "); - sprintf(info->info[2], "%s", c->inf_game); + sprintf(info->info[2], "%s", s->c->inf_game); strcpy(info->title[3], "Artist: "); - sprintf(info->info[3], "%s", c->inf_artist); + sprintf(info->info[3], "%s", s->c->inf_artist); strcpy(info->title[4], "Copyright: "); - sprintf(info->info[4], "%s", c->inf_copy); + sprintf(info->info[4], "%s", s->c->inf_copy); strcpy(info->title[5], "Year: "); - sprintf(info->info[5], "%s", c->inf_year); + sprintf(info->info[5], "%s", s->c->inf_year); strcpy(info->title[6], "Length: "); - sprintf(info->info[6], "%s", c->inf_length); + sprintf(info->info[6], "%s", s->c->inf_length); strcpy(info->title[7], "Fade: "); - sprintf(info->info[7], "%s", c->inf_fade); + sprintf(info->info[7], "%s", s->c->inf_fade); strcpy(info->title[8], "Ripper: "); - sprintf(info->info[8], "%s", psfby); + sprintf(info->info[8], "%s", s->psfby); return AO_SUCCESS; } |