comparison ym2612.c @ 1551:ce1f93be0104

Small cleanup to audio interface between emulation code and renderer backend
author Michael Pavone <pavone@retrodev.com>
date Wed, 28 Mar 2018 23:36:08 -0700
parents 08bc099a622f
children 6ce36c3f250b
comparison
equal deleted inserted replaced
1550:b525491b4e5b 1551:ce1f93be0104
166 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, uint32_t lowpass_cutoff) 166 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, uint32_t lowpass_cutoff)
167 { 167 {
168 static uint8_t registered_finalize; 168 static uint8_t registered_finalize;
169 dfopen(debug_file, "ym_debug.txt", "w"); 169 dfopen(debug_file, "ym_debug.txt", "w");
170 memset(context, 0, sizeof(*context)); 170 memset(context, 0, sizeof(*context));
171 context->audio_buffer = malloc(sizeof(*context->audio_buffer) * sample_limit*2); 171 context->audio = render_audio_source(2);
172 context->back_buffer = malloc(sizeof(*context->audio_buffer) * sample_limit*2); 172 context->audio_buffer = render_audio_source_buffer(context->audio);
173 context->sample_rate = sample_rate; 173 context->sample_rate = sample_rate;
174 context->clock_inc = clock_div * 6; 174 context->clock_inc = clock_div * 6;
175 ym_adjust_master_clock(context, master_clock); 175 ym_adjust_master_clock(context, master_clock);
176 176
177 double rc = (1.0 / (double)lowpass_cutoff) / (2.0 * M_PI); 177 double rc = (1.0 / (double)lowpass_cutoff) / (2.0 * M_PI);
264 ym_reset(context); 264 ym_reset(context);
265 } 265 }
266 266
267 void ym_free(ym2612_context *context) 267 void ym_free(ym2612_context *context)
268 { 268 {
269 render_free_source(context->audio);
269 if (context == log_context) { 270 if (context == log_context) {
270 ym_finalize_log(); 271 ym_finalize_log();
271 } 272 }
272 free(context->audio_buffer);
273 //TODO: Figure out how to make this 100% safe
274 //audio thread could still be using this
275 free(context->back_buffer);
276 free(context); 273 free(context);
277 } 274 }
278 275
279 #define YM_VOLUME_MULTIPLIER 2 276 #define YM_VOLUME_MULTIPLIER 2
280 #define YM_VOLUME_DIVIDER 3 277 #define YM_VOLUME_DIVIDER 3
647 context->audio_buffer[context->buffer_pos+1] = tmp >> 16; 644 context->audio_buffer[context->buffer_pos+1] = tmp >> 16;
648 645
649 context->buffer_pos += 2; 646 context->buffer_pos += 2;
650 if (context->buffer_pos == context->sample_limit) { 647 if (context->buffer_pos == context->sample_limit) {
651 if (!headless) { 648 if (!headless) {
652 render_wait_ym(context); 649 context->audio_buffer = render_audio_ready(context->audio);
650 context->buffer_pos = 0;
653 } 651 }
654 } 652 }
655 } 653 }
656 context->last_left = left; 654 context->last_left = left;
657 context->last_right = right; 655 context->last_right = right;