audio arrangement that makes more sense
This commit is contained in:
+17
-13
@@ -5,31 +5,35 @@ static unsigned int wav_length; /* length of our sample */
|
|||||||
static unsigned char* wav_buffer; /* buffer containing our audio file */
|
static unsigned char* wav_buffer; /* buffer containing our audio file */
|
||||||
static SDL_AudioSpec wav_spec;
|
static SDL_AudioSpec wav_spec;
|
||||||
static SDL_AudioDeviceID device_id = 0;
|
static SDL_AudioDeviceID device_id = 0;
|
||||||
|
static int cat_audio_playing = 0;
|
||||||
|
|
||||||
void queue(char* file)
|
void cat_stop_audio(void) {
|
||||||
|
SDL_PauseAudioDevice(device_id, 1);
|
||||||
|
SDL_CloseAudioDevice(device_id);
|
||||||
|
SDL_FreeWAV(wav_buffer);
|
||||||
|
cat_audio_playing = 0;
|
||||||
|
/*SDL_Quit();*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void cat_play_wav(char* file)
|
||||||
{
|
{
|
||||||
|
if (cat_audio_playing) cat_stop_audio();
|
||||||
|
cat_audio_playing = 1;
|
||||||
if (SDL_LoadWAV(file, &wav_spec, &wav_buffer, &wav_length) == NULL) {
|
if (SDL_LoadWAV(file, &wav_spec, &wav_buffer, &wav_length) == NULL) {
|
||||||
printf("file is null!!\n");
|
printf("file is null!!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
device_id = SDL_OpenAudioDevice(NULL, 0, &wav_spec, NULL, 0);
|
device_id = SDL_OpenAudioDevice(NULL, 0, &wav_spec, NULL, 0);
|
||||||
SDL_QueueAudio(device_id, wav_buffer, wav_length);
|
SDL_QueueAudio(device_id, wav_buffer, wav_length);
|
||||||
|
SDL_PauseAudioDevice(device_id, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void close_audio(void) {
|
|
||||||
SDL_CloseAudioDevice(device_id);
|
|
||||||
SDL_FreeWAV(wav_buffer);
|
|
||||||
SDL_Quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
SDL_Init(SDL_INIT_EVERYTHING);
|
SDL_Init(SDL_INIT_EVERYTHING);
|
||||||
queue("etc/example.wav");
|
cat_play_wav("etc/example.wav");
|
||||||
SDL_PauseAudioDevice(device_id, 0);
|
SDL_Delay(300);
|
||||||
SDL_Delay(3000);
|
cat_stop_audio();
|
||||||
close_audio();
|
fgetc(stdin);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user