diff --git a/audio.c b/audio.c new file mode 100644 index 0000000..0c25178 --- /dev/null +++ b/audio.c @@ -0,0 +1,35 @@ +#include +#include + +static unsigned int wav_length; /* length of our sample */ +static unsigned char* wav_buffer; /* buffer containing our audio file */ +static SDL_AudioSpec wav_spec; +static SDL_AudioDeviceID device_id = 0; + +void queue(char* file) +{ + if (SDL_LoadWAV(file, &wav_spec, &wav_buffer, &wav_length) == NULL) { + printf("file is null!!\n"); + return; + } + device_id = SDL_OpenAudioDevice(NULL, 0, &wav_spec, NULL, 0); + SDL_QueueAudio(device_id, wav_buffer, wav_length); +} + + +void close_audio(void) { + SDL_CloseAudioDevice(device_id); + SDL_FreeWAV(wav_buffer); + SDL_Quit(); +} + + +int main(int argc, char** argv) { + SDL_Init(SDL_INIT_EVERYTHING); + queue("example.wav"); + SDL_PauseAudioDevice(device_id, 0); + SDL_Delay(3000); + close_audio(); + return 0; +} + diff --git a/example.wav b/example.wav new file mode 100644 index 0000000..56de6de Binary files /dev/null and b/example.wav differ diff --git a/makefile b/makefile index 4b605ed..4b9d5d4 100644 --- a/makefile +++ b/makefile @@ -4,3 +4,7 @@ all: run: all bin/cfhfg + +audio: + cc -o bin/audio audio.c -lSDL2 + bin/audio