does anybody have any experience with the SDL audio part of their multimedia library? I need some help playing a WAV file....I can load the WAV...but not play it.
If you have experience SDL's audio library...tell me what you did to get a WAV file playing.
Here is some of my code:
Thanx.Code:#include <SDL.h> #include <stdlib.h> int main (int argc, char *argv[]) { SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ); SDL_Surface *screen = SDL_SetVideoMode( 640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN ); atexit(SDL_Quit); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); Uint32 rmask, gmask, bmask, amask; #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif SDL_AudioSpec wav_spec; Uint32 wav_length; Uint8 *wav_buffer; bool opened = true; SDL_LoadWAV("shotgun2.wav", &wav_spec, &wav_buffer, &wav_length); SDL_Rect *myRect = new SDL_Rect; myRect->x = 100; myRect->y = 100; SDL_Surface *bmp = SDL_LoadBMP("tile.bmp"); SDL_Event event; while(1) { SDL_BlitSurface(bmp, 0, screen, myRect); SDL_Flip(screen); SDL_FillRect(screen, 0, 0); while( SDL_PollEvent ( &event ) ) { switch(event.type) { case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_LCTRL: SDL_PauseAudio(0); break; case SDLK_DOWN: myRect->y += 2; break; case SDLK_UP: myRect->y -= 2; break; case SDLK_LEFT: myRect->x -= 2; break; case SDLK_RIGHT: myRect->x += 2; break; case SDLK_ESCAPE: SDL_FreeWAV(wav_buffer); return 0; break; } break; } } } }



LinkBack URL
About LinkBacks


