This commit is contained in:
NishiOwO 2025-04-21 18:23:55 +09:00
parent 52b61b5210
commit d080c8f0ad
No known key found for this signature in database
GPG Key ID: 27EF69B208EB9343
3 changed files with 44 additions and 20 deletions

View File

@ -258,6 +258,7 @@ gf_bool_t jar_mod_load(jar_mod_context_t* modctx, void* mod_data, int mod_data_s
mulong jar_mod_current_samples(jar_mod_context_t* modctx);
mulong jar_mod_max_samples(jar_mod_context_t* modctx);
void jar_mod_seek_start(jar_mod_context_t* ctx);
gf_bool_t jar_mod_reset(jar_mod_context_t* modctx);
#ifdef __cplusplus
}
@ -1280,7 +1281,7 @@ void jar_mod_fillbuffer(jar_mod_context_t* modctx, gf_int16_t* outbuffer, unsign
}
/*resets internals for mod context*/
static gf_bool_t jar_mod_reset(jar_mod_context_t* modctx) {
gf_bool_t jar_mod_reset(jar_mod_context_t* modctx) {
if(modctx) {
memclear(&modctx->song, 0, sizeof(modctx->song));
memclear(&modctx->sampledata, 0, sizeof(modctx->sampledata));
@ -1355,18 +1356,22 @@ mulong jar_mod_current_samples(jar_mod_context_t* modctx) {
/* Works, however it is very slow, this data should be cached to ensure it is run only once per file */
mulong jar_mod_max_samples(jar_mod_context_t* ctx) {
mulong len;
mulong lastcount = ctx->loopcount;
mulong lastcount = ctx->loopcount;
#if 0
mulong samplenb = ctx->samplenb;
muint tablepos = ctx->tablepos;
muint patternpos = ctx->patternpos;
#endif
while(ctx->loopcount <= lastcount) jar_mod_fillbuffer(ctx, NULL, 1, 0);
len = ctx->samplenb;
jar_mod_seek_start(ctx);
#if 0
ctx->samplenb = samplenb;
ctx->tablepos = tablepos;
ctx->patternpos = patternpos;
#endif
return len;
}

View File

@ -258,6 +258,8 @@ gf_uint64_t jar_xm_get_latest_trigger_of_channel(jar_xm_context_t*, gf_uint16_t)
*/
gf_uint64_t jar_xm_get_remaining_samples(jar_xm_context_t*);
void jar_xm_reset(jar_xm_context_t* ctx);
#ifdef __cplusplus
}
#endif
@ -488,6 +490,10 @@ struct jar_xm_context_s {
jar_xm_module_t module;
gf_uint32_t rate;
gf_uint16_t default_tempo;
gf_uint16_t default_bpm;
float default_global_volume;
gf_uint16_t tempo;
gf_uint16_t bpm;
float global_volume;
@ -627,8 +633,9 @@ int jar_xm_create_context_safe(jar_xm_context_t** ctxp, const char* moddata, siz
ctx->channels = (jar_xm_channel_context_t*)mempool;
mempool += ctx->module.num_channels * sizeof(jar_xm_channel_context_t);
ctx->global_volume = 1.f;
ctx->amplification = .25f; /* XXX: some bad modules may still clip. Find out something better. */
ctx->default_global_volume = 1.f;
ctx->global_volume = 1.f;
ctx->amplification = .25f; /* XXX: some bad modules may still clip. Find out something better. */
#if JAR_XM_RAMPING
ctx->volume_ramp = (1.f / 128.f);
@ -897,8 +904,10 @@ char* jar_xm_load_module(jar_xm_context_t* ctx, const char* moddata, size_t modd
flags = READ_U32(offset + 14);
mod->frequency_type = (flags & (1 << 0)) ? jar_xm_LINEAR_FREQUENCIES : jar_xm_AMIGA_FREQUENCIES;
ctx->tempo = READ_U16(offset + 16);
ctx->bpm = READ_U16(offset + 18);
ctx->default_tempo = READ_U16(offset + 16);
ctx->default_bpm = READ_U16(offset + 18);
ctx->tempo = ctx->default_tempo;
ctx->bpm = ctx->default_bpm;
READ_MEMCPY(mod->pattern_table, offset + 20, PATTERN_ORDER_TABLE_LENGTH);
offset += header_size;
@ -1396,6 +1405,9 @@ static void jar_xm_post_pattern_change(jar_xm_context_t* ctx) {
/* Loop if necessary */
if(ctx->current_table_index >= ctx->module.length) {
ctx->current_table_index = ctx->module.restart_position;
ctx->tempo = ctx->default_tempo;
ctx->bpm = ctx->default_bpm;
ctx->global_volume = ctx->default_global_volume;
}
}
@ -2454,13 +2466,8 @@ void jar_xm_generate_samples(jar_xm_context_t* ctx, float* output, size_t numsam
}
gf_uint64_t jar_xm_get_remaining_samples(jar_xm_context_t* ctx) {
gf_uint64_t total = 0;
gf_uint8_t currentLoopCount = jar_xm_get_loop_count(ctx);
gf_uint16_t current_tick = ctx->current_tick;
gf_uint8_t current_row = ctx->current_row;
gf_uint8_t current_table_index = ctx->current_table_index;
gf_uint16_t extra_ticks = ctx->extra_ticks;
float remaining_samples_in_tick = ctx->remaining_samples_in_tick;
gf_uint64_t total = 0;
gf_uint8_t currentLoopCount = jar_xm_get_loop_count(ctx);
jar_xm_set_max_loop_count(ctx, 0);
@ -2470,15 +2477,25 @@ gf_uint64_t jar_xm_get_remaining_samples(jar_xm_context_t* ctx) {
jar_xm_tick(ctx);
}
ctx->loop_count = currentLoopCount;
ctx->current_tick = current_tick;
ctx->current_row = current_row;
ctx->current_table_index = current_table_index;
ctx->extra_ticks = extra_ticks;
ctx->remaining_samples_in_tick = remaining_samples_in_tick;
ctx->loop_count = currentLoopCount;
return total;
}
void jar_xm_reset(jar_xm_context_t* ctx) {
gf_uint16_t i;
for(i = 0; i < jar_xm_get_number_of_channels(ctx); i++) {
jar_xm_cut_note(&ctx->channels[i]);
}
ctx->generated_samples = 0;
ctx->current_row = 0;
ctx->current_table_index = 0;
ctx->current_tick = 0;
ctx->tempo = ctx->default_tempo;
ctx->bpm = ctx->default_bpm;
ctx->global_volume = ctx->default_global_volume;
}
/*--------------------------------------------*/
/*FILE LOADER - TODO - NEEDS TO BE CLEANED UP*/
/*--------------------------------------------*/

View File

@ -22,7 +22,7 @@
const char* gf_audio_mod_sig[] = {"M!K!", "M.K.", "FLT4", "FLT8", "4CHN", "6CHN", "8CHN", "10CH", "12CH", "14CH", "16CH", "18CH", "20CH", "22CH", "24CH", "26CH", "28CH", "30CH", "32CH"};
void gf_audio_callback(ma_device* dev, void* output, const void* input, ma_uint32 frame) {
ma_uint32 i;
ma_uint32 i;
gf_audio_t* audio = dev->pUserData;
ma_int16* out = (ma_int16*)output;
float* tmp = malloc(sizeof(*tmp) * frame * 2);
@ -134,6 +134,7 @@ gf_audio_id_t gf_audio_load(gf_audio_t* audio, const void* data, size_t size) {
decoder.samples = jar_xm_get_remaining_samples(decoder.xm);
decoder.used = -1;
hmputs(audio->decoder, decoder);
jar_xm_reset(decoder.xm);
ma_mutex_unlock(audio->mutex);
return decoder.key;
}
@ -146,6 +147,7 @@ gf_audio_id_t gf_audio_load(gf_audio_t* audio, const void* data, size_t size) {
decoder.samples = jar_mod_max_samples(decoder.mod);
decoder.used = -1;
hmputs(audio->decoder, decoder);
jar_mod_reset(decoder.mod);
ma_mutex_unlock(audio->mutex);
return decoder.key;
}