commit 9c8ae9482561f1205530505f36b8747dad2c492f
parent 1d7c96dd3da43be25504ec0f5c5ac6c845658d22
Author: Bad Diode <bd@badd10de.dev>
Date: Thu, 19 Oct 2023 12:06:47 +0200
Change sdl audio to not play until the first pitch is sent
Diffstat:
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/devices/audio.c b/src/devices/audio.c
@@ -15,7 +15,6 @@ WITH REGARD TO THIS SOFTWARE.
*/
#define SOUND_TIMER (AUDIO_BUFSIZE / SAMPLE_FREQUENCY * 1000.0f)
-#define N_CHANNELS 4
#define XFADE_SAMPLES 100
#define INTERPOL_METHOD 1
@@ -54,7 +53,7 @@ typedef struct AudioChannel {
float vol_r;
} AudioChannel;
-AudioChannel channel[N_CHANNELS];
+AudioChannel channel[POLYPHONY];
const float tuning[109] = {
0.00058853f, 0.00062352f, 0.00066060f, 0.00069988f, 0.00074150f,
@@ -117,10 +116,10 @@ note_on(AudioChannel *channel, Uint16 duration, Uint8 *data, Uint16 len, Uint8 v
sample.data = data;
sample.len = len;
sample.pos = 0;
- sample.env.a = attack * 62.0f;
- sample.env.d = decay * 62.0f;
+ sample.env.a = attack * 64.0f;
+ sample.env.d = decay * 64.0f;
sample.env.s = sustain / 16.0f;
- sample.env.r = release * 62.0f;
+ sample.env.r = release * 64.0f;
if (loop) {
sample.loop = len;
} else {
@@ -238,7 +237,7 @@ audio_handler(void *ctx, Uint8 *out_stream, int len) {
memset(stream, 0x00, len);
int n;
- for (n = 0; n < N_CHANNELS; n++) {
+ for (n = 0; n < POLYPHONY; n++) {
Uint8 device = (3 + n) << 4;
Uxn *u = (Uxn *)ctx;
Uint8 *addr = &u->dev[device];
diff --git a/src/uxnemu.c b/src/uxnemu.c
@@ -90,6 +90,7 @@ audio_deo(int instance, Uint8 *d, Uint8 port, Uxn *u)
SDL_LockAudioDevice(audio_id);
audio_start(instance, d, u);
SDL_UnlockAudioDevice(audio_id);
+ SDL_PauseAudioDevice(audio_id, 0);
}
}
@@ -266,7 +267,7 @@ emu_init(Uxn *u)
deadline_interval = ms_interval * TIMEOUT_MS;
exec_deadline = SDL_GetPerformanceCounter() + deadline_interval;
screen_resize(WIDTH, HEIGHT);
- SDL_PauseAudioDevice(audio_id, 0);
+ SDL_PauseAudioDevice(audio_id, 1);
return 1;
}