SDL audio

This is a discussion on SDL audio within the Game Programming forums, part of the General Programming Boards category; does anybody have any experience with the SDL audio part of their multimedia library? I need some help playing a ...

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738

    SDL audio

    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:

    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;			
    			}
    		}
    	}
    }
    Thanx.
    My Website

    "Circular logic is good because it is."

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    http://www.libsdl.org/intro/usingsound.html
    try this site, it has sdl_audio examples

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems compiling this SDL app
    By Rider in forum C++ Programming
    Replies: 3
    Last Post: 03-27-2007, 12:22 PM
  2. audio programming (from scratch)
    By simpleid in forum C Programming
    Replies: 6
    Last Post: 07-26-2006, 09:32 AM
  3. Port Audio
    By samGwilliam in forum Windows Programming
    Replies: 9
    Last Post: 12-07-2005, 10:43 AM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. sdl in c++
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-07-2002, 07:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21