Mercurial > sdl-ios-xcode
comparison test/loopwave.c @ 1463:0394f8ebc42d
*** empty log message ***
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 03 Mar 2006 04:43:42 +0000 |
parents | be9c9c8f6d53 |
children | 14717b52abc0 |
comparison
equal
deleted
inserted
replaced
1462:c17d82103614 | 1463:0394f8ebc42d |
---|---|
2 /* Program to load a wave file and loop playing it using SDL sound */ | 2 /* Program to load a wave file and loop playing it using SDL sound */ |
3 | 3 |
4 /* loopwaves.c is much more robust in handling WAVE files -- | 4 /* loopwaves.c is much more robust in handling WAVE files -- |
5 This is only for simple WAVEs | 5 This is only for simple WAVEs |
6 */ | 6 */ |
7 #include "SDL_config.h" | |
7 | 8 |
8 #include <stdio.h> | 9 #include <stdio.h> |
9 #include <stdlib.h> | 10 #include <stdlib.h> |
11 | |
12 #if HAVE_SIGNAL_H | |
10 #include <signal.h> | 13 #include <signal.h> |
14 #endif | |
11 | 15 |
12 #include "SDL.h" | 16 #include "SDL.h" |
13 #include "SDL_audio.h" | 17 #include "SDL_audio.h" |
14 | 18 |
15 struct { | 19 struct { |
63 /* Load the SDL library */ | 67 /* Load the SDL library */ |
64 if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) { | 68 if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) { |
65 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | 69 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); |
66 return(1); | 70 return(1); |
67 } | 71 } |
68 | |
69 if ( argv[1] == NULL ) { | 72 if ( argv[1] == NULL ) { |
70 fprintf(stderr, "Usage: %s <wavefile>\n", argv[0]); | 73 argv[1] = "sample.wav"; |
71 quit(1); | |
72 } | 74 } |
73 | |
74 /* Load the wave file into memory */ | 75 /* Load the wave file into memory */ |
75 if ( SDL_LoadWAV(argv[1], | 76 if ( SDL_LoadWAV(argv[1], |
76 &wave.spec, &wave.sound, &wave.soundlen) == NULL ) { | 77 &wave.spec, &wave.sound, &wave.soundlen) == NULL ) { |
77 fprintf(stderr, "Couldn't load %s: %s\n", | 78 fprintf(stderr, "Couldn't load %s: %s\n", |
78 argv[1], SDL_GetError()); | 79 argv[1], SDL_GetError()); |
79 quit(1); | 80 quit(1); |
80 } | 81 } |
82 | |
81 wave.spec.callback = fillerup; | 83 wave.spec.callback = fillerup; |
82 | 84 #if HAVE_SIGNAL_H |
83 /* Set the signals */ | 85 /* Set the signals */ |
84 #ifdef SIGHUP | 86 #ifdef SIGHUP |
85 signal(SIGHUP, poked); | 87 signal(SIGHUP, poked); |
86 #endif | 88 #endif |
87 signal(SIGINT, poked); | 89 signal(SIGINT, poked); |
88 #ifdef SIGQUIT | 90 #ifdef SIGQUIT |
89 signal(SIGQUIT, poked); | 91 signal(SIGQUIT, poked); |
90 #endif | 92 #endif |
91 signal(SIGTERM, poked); | 93 signal(SIGTERM, poked); |
94 #endif /* HAVE_SIGNAL_H */ | |
92 | 95 |
93 /* Initialize fillerup() variables */ | 96 /* Initialize fillerup() variables */ |
94 if ( SDL_OpenAudio(&wave.spec, NULL) < 0 ) { | 97 if ( SDL_OpenAudio(&wave.spec, NULL) < 0 ) { |
95 fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); | 98 fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); |
96 SDL_FreeWAV(wave.sound); | 99 SDL_FreeWAV(wave.sound); |