diff options
author | Michael Pavone <pavone@retrodev.com> | 2015-11-13 22:56:59 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2015-11-13 22:56:59 -0800 |
commit | 62fdcbc92ba3c4a71742293d75d853c95eb5f3c7 (patch) | |
tree | dce685f5cf74848f6d6a85f93689cf8dec50e89b /ym2612.c | |
parent | 802454482c2843234a19a06f6acce360e0be3d60 (diff) |
Selecting a second game from the menu now works
Diffstat (limited to 'ym2612.c')
-rw-r--r-- | ym2612.c | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -104,11 +104,15 @@ ym2612_context * log_context = NULL; void ym_finalize_log() { + if (!log_context) { + return; + } for (int i = 0; i < NUM_CHANNELS; i++) { if (log_context->channels[i].logfile) { wave_finalize(log_context->channels[i].logfile); } } + log_context = NULL; } #define BUFFER_INC_RES 1000000000UL @@ -124,6 +128,7 @@ void ym_adjust_master_clock(ym2612_context * context, uint32_t master_clock) void ym_init(ym2612_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t sample_limit, uint32_t options) { + static uint8_t registered_finalize; dfopen(debug_file, "ym_debug.txt", "w"); memset(context, 0, sizeof(*context)); context->audio_buffer = malloc(sizeof(*context->audio_buffer) * sample_limit*2); @@ -157,7 +162,10 @@ void ym_init(ym2612_context * context, uint32_t sample_rate, uint32_t master_clo } if (options & YM_OPT_WAVE_LOG) { log_context = context; - atexit(ym_finalize_log); + if (!registered_finalize) { + atexit(ym_finalize_log); + registered_finalize = 1; + } } if (!did_tbl_init) { //populate sine table @@ -218,6 +226,18 @@ void ym_init(ym2612_context * context, uint32_t sample_rate, uint32_t master_clo } } +void ym_free(ym2612_context *context) +{ + if (context == log_context) { + ym_finalize_log(); + } + free(context->audio_buffer); + //TODO: Figure out how to make this 100% safe + //audio thread could still be using this + free(context->back_buffer); + free(context); +} + #define YM_VOLUME_MULTIPLIER 2 #define YM_VOLUME_DIVIDER 3 #define YM_MOD_SHIFT 1 |