From ebc1a4e1ac745041a1bf1842c303491bfbdc3607 Mon Sep 17 00:00:00 2001 From: Sheldon Lee Date: Mon, 4 Nov 2024 22:40:48 +0800 Subject: [PATCH] Move SDL_CloseAudioDevice() audio.c + rename audio device pause function. --- audio.c | 12 +++++++++--- audio.h | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/audio.c b/audio.c index afd43c7..a8b9a7d 100644 --- a/audio.c +++ b/audio.c @@ -18,7 +18,7 @@ int audio_init(audio_state* state) SDL_zero(recording_spec); recording_spec.freq = 44100; - recording_spec.format = AUDIO_S16; + recording_spec.format = AUDIO_S32; recording_spec.channels = 2; recording_spec.samples = 4096; recording_spec.callback = audio_recording_callback; @@ -26,7 +26,7 @@ int audio_init(audio_state* state) SDL_zero(playback_spec); playback_spec.freq = 44100; - playback_spec.format = AUDIO_S16; + playback_spec.format = AUDIO_S32; playback_spec.channels = 2; playback_spec.samples = 4096; playback_spec.callback = audio_playback_callback; @@ -84,12 +84,18 @@ int audio_playback_init(audio_state* state) return 1; } -void audio_playback_pause(audio_state* state, int is_recording, int is_pause) +void audio_device_pause(audio_state* state, int is_recording, int is_pause) { int device_id = is_recording ? state->recording_device_id : state->playback_device_id; SDL_PauseAudioDevice(device_id, is_pause); } +void audio_device_close(audio_state* state, int is_recording) +{ + int device_id = is_recording ? state->recording_device_id : state->playback_device_id; + SDL_CloseAudioDevice(device_id); +} + void audio_buffer_reset(audio_state* state) { memset(state->recording_buffer, 0, state->recording_buffer_size); diff --git a/audio.h b/audio.h index 6cb7fdd..7db625d 100644 --- a/audio.h +++ b/audio.h @@ -16,7 +16,8 @@ int audio_init(audio_state* state); void audio_destroy(audio_state* state); int audio_recording_init(audio_state* state, int index); int audio_playback_init(audio_state* state); -void audio_playback_pause(audio_state* state, int is_recording, int pause); +void audio_device_pause(audio_state* state, int is_recording, int pause); +void audio_device_close(audio_state* state, int is_recording); void audio_buffer_reset(audio_state* state); #endif