how to get sound in sdl

i am usin SDL and i was wondering what i need to use to input a sound file when a certain key is down?!! eg


1
2
3
4
5
6
7
8

if(IsKeyDown(KEY_ESCAPE))
{
 playsound() or what ever the syntax is!;

}




If you are using only SDL, it's more complicated than you might think. You have to set up a callback and feed SDL audio samples as it requires it.

There is a secondary support library called SDL_Mixer that you might want to get, as it supposedly wraps the process a bit more and makes it easier to do simple tasks like that.

Although I've never used SDL_Mixer so I couldn't really help you with it.
all i wanted was an short song loop at the intro screen e.g

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

bool Title()
{
      playsound();
}

do{

switch(currentstate)

	case 1 Title:
		bKeepPlaying = title();
		break;

 
}while
Last edited on
There is no "playsound" or equivilent function in SDL. It requires you to set up a separate callback function and manually mix raw audio samples into an output buffer. The minimal code to do it would be around ~25 lines.

I'm too tired now to write up the code necessary to do it for you, and I'm kind of assuming a big block of code is not what you're looking for anyway.


That said, SDL_Mixer probably does have a single function you can call, so I recommend you look it up and get that add-on if you're using SDL.
Last edited on
i just wanted to know how to do it =D and the amount of code is not a problem i will look it up though =D thanks for the help
Here's a basic example of how to do it with SDL:

http://www.libsdl.org/docs/html/guideaudioexamples.html
Topic archived. No new replies allowed.