Move SDL_CloseAudioDevice() audio.c + rename audio device pause

function.
This commit is contained in:
Sheldon Lee 2024-11-04 22:40:48 +08:00
parent c7b35b705d
commit ebc1a4e1ac
2 changed files with 11 additions and 4 deletions

12
audio.c
View File

@ -18,7 +18,7 @@ int audio_init(audio_state* state)
SDL_zero(recording_spec); SDL_zero(recording_spec);
recording_spec.freq = 44100; recording_spec.freq = 44100;
recording_spec.format = AUDIO_S16; recording_spec.format = AUDIO_S32;
recording_spec.channels = 2; recording_spec.channels = 2;
recording_spec.samples = 4096; recording_spec.samples = 4096;
recording_spec.callback = audio_recording_callback; recording_spec.callback = audio_recording_callback;
@ -26,7 +26,7 @@ int audio_init(audio_state* state)
SDL_zero(playback_spec); SDL_zero(playback_spec);
playback_spec.freq = 44100; playback_spec.freq = 44100;
playback_spec.format = AUDIO_S16; playback_spec.format = AUDIO_S32;
playback_spec.channels = 2; playback_spec.channels = 2;
playback_spec.samples = 4096; playback_spec.samples = 4096;
playback_spec.callback = audio_playback_callback; playback_spec.callback = audio_playback_callback;
@ -84,12 +84,18 @@ int audio_playback_init(audio_state* state)
return 1; 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; int device_id = is_recording ? state->recording_device_id : state->playback_device_id;
SDL_PauseAudioDevice(device_id, is_pause); 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) void audio_buffer_reset(audio_state* state)
{ {
memset(state->recording_buffer, 0, state->recording_buffer_size); memset(state->recording_buffer, 0, state->recording_buffer_size);

View File

@ -16,7 +16,8 @@ int audio_init(audio_state* state);
void audio_destroy(audio_state* state); void audio_destroy(audio_state* state);
int audio_recording_init(audio_state* state, int index); int audio_recording_init(audio_state* state, int index);
int audio_playback_init(audio_state* state); 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); void audio_buffer_reset(audio_state* state);
#endif #endif