#include "SDL.h" #include "SDL_audio.h" void PlaySound(char* file); int main() { extern void mixaudio(void *unused, Uint8 *stream, int len); SDL_AudioSpec fmt; /* Set 16-bit stereo audio at 22Khz */ fmt.freq = 22050; fmt.format = AUDIO_S16; fmt.channels = 2; fmt.samples = 512; /* A good value for games */ fmt.callback = mixaudio; fmt.userdata = NULL; /* Open the audio device and start playing sound! */ if ( SDL_OpenAudio(&fmt, NULL) < 0 ) { fprintf(stderr, "Unable to open audio: %sn", SDL_GetError()); exit(1); } PlaySound("PicWinStudios.wav"); SDL_CloseAudio();//closes the audio and setting the fmt to null return 0; } #define NUM_SOUNDS 2 struct sample { Uint8 *data; Uint32 dpos; Uint32 dlen; } sounds[NUM_SOUNDS]; void PlaySound(char *file) { int index; SDL_AudioSpec wave; Uint8 *data; Uint32 dlen; SDL_AudioCVT cvt; /* Look for an empty (or finished) sound slot */ for ( index=0; index len) { amount = len; } SDL_MixAudio(stream, &sounds[i].data[sounds[i].dpos], amount, SDL_MIX_MAXVOLUME); sounds[i].dpos += amount; } }