From 89e8a05815e6ded082e3ac0afc4270c9a121e94a Mon Sep 17 00:00:00 2001 From: kanjitalk755 Date: Sat, 6 Feb 2021 13:06:13 +0900 Subject: [PATCH] startup sound --- BasiliskII/src/SDL/audio_sdl.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/BasiliskII/src/SDL/audio_sdl.cpp b/BasiliskII/src/SDL/audio_sdl.cpp index 45286738..588eb1a7 100644 --- a/BasiliskII/src/SDL/audio_sdl.cpp +++ b/BasiliskII/src/SDL/audio_sdl.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #define DEBUG 0 #include "debug.h" @@ -54,6 +55,7 @@ static bool audio_mute = false; // Prototypes static void stream_func(void *arg, uint8 *stream, int stream_len); +static int play_startup(void *arg); /* @@ -166,6 +168,8 @@ void AudioInit(void) // Open and initialize audio device open_audio(); + + SDL_CreateThread(play_startup, "", NULL); } @@ -359,3 +363,23 @@ void audio_set_speaker_mute(bool mute) void audio_set_speaker_volume(uint32 vol) { } + +static int play_startup(void *arg) { + SDL_AudioSpec wav_spec; + Uint8 *wav_buffer; + Uint32 wav_length; + if (SDL_LoadWAV("startup.wav", &wav_spec, &wav_buffer, &wav_length)) { + SDL_AudioSpec desired = { .freq = 44100, .format = AUDIO_S16, .channels = 1, .samples= 4096 }, obtained; + SDL_AudioDeviceID deviceId = SDL_OpenAudioDevice(NULL, 0, &desired, &obtained, 0); + if (deviceId) { + SDL_QueueAudio(deviceId, wav_buffer, wav_length); + SDL_PauseAudioDevice(deviceId, 0); + while (SDL_GetQueuedAudioSize(deviceId)) SDL_Delay(10); + SDL_Delay(500); + SDL_CloseAudioDevice(deviceId); + } + else printf("play_startup: Audio driver failed to initialize\n"); + SDL_FreeWAV(wav_buffer); + } + return 0; +}