Mercurial > repos > blastem
comparison psg.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 | 9c65819afec3 |
children | 6ce36c3f250b |
comparison
equal
deleted
inserted
replaced
1550:b525491b4e5b | 1551:ce1f93be0104 |
---|---|
11 #include <stdio.h> | 11 #include <stdio.h> |
12 #include <math.h> | 12 #include <math.h> |
13 void psg_init(psg_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t samples_frame, uint32_t lowpass_cutoff) | 13 void psg_init(psg_context * context, uint32_t sample_rate, uint32_t master_clock, uint32_t clock_div, uint32_t samples_frame, uint32_t lowpass_cutoff) |
14 { | 14 { |
15 memset(context, 0, sizeof(*context)); | 15 memset(context, 0, sizeof(*context)); |
16 context->audio_buffer = malloc(sizeof(*context->audio_buffer) * samples_frame); | 16 context->audio = render_audio_source(1); |
17 context->back_buffer = malloc(sizeof(*context->audio_buffer) * samples_frame); | 17 context->audio_buffer = render_audio_source_buffer(context->audio); |
18 context->clock_inc = clock_div; | 18 context->clock_inc = clock_div; |
19 context->sample_rate = sample_rate; | 19 context->sample_rate = sample_rate; |
20 context->samples_frame = samples_frame; | 20 context->samples_frame = samples_frame; |
21 double rc = (1.0 / (double)lowpass_cutoff) / (2.0 * M_PI); | 21 double rc = (1.0 / (double)lowpass_cutoff) / (2.0 * M_PI); |
22 double dt = 1.0 / ((double)master_clock / (double)clock_div); | 22 double dt = 1.0 / ((double)master_clock / (double)clock_div); |
28 } | 28 } |
29 } | 29 } |
30 | 30 |
31 void psg_free(psg_context *context) | 31 void psg_free(psg_context *context) |
32 { | 32 { |
33 free(context->audio_buffer); | 33 render_free_source(context->audio); |
34 //TODO: Figure out how to make this 100% safe | |
35 //audio thread could still be using this | |
36 free(context->back_buffer); | |
37 free(context); | 34 free(context); |
38 } | 35 } |
39 | 36 |
40 #define BUFFER_INC_RES 0x40000000UL | 37 #define BUFFER_INC_RES 0x40000000UL |
41 | 38 |
141 tmp += context->accum * (0x10000 - ((context->buffer_fraction << 16) / context->buffer_inc)); | 138 tmp += context->accum * (0x10000 - ((context->buffer_fraction << 16) / context->buffer_inc)); |
142 context->audio_buffer[context->buffer_pos++] = tmp >> 16; | 139 context->audio_buffer[context->buffer_pos++] = tmp >> 16; |
143 | 140 |
144 if (context->buffer_pos == context->samples_frame) { | 141 if (context->buffer_pos == context->samples_frame) { |
145 if (!headless) { | 142 if (!headless) { |
146 render_wait_psg(context); | 143 context->audio_buffer = render_audio_ready(context->audio); |
144 context->buffer_pos = 0; | |
147 } | 145 } |
148 } | 146 } |
149 } | 147 } |
150 context->cycles += context->clock_inc; | 148 context->cycles += context->clock_inc; |
151 } | 149 } |