How do I play a sound file with SDL?
I've downloaded the library files but SDL/SDL_mixer.h (that most of the tutorials include) doesn't exist. So, how do I install it?
As I said mixer.h doesn't exist but, If it is helpful, the default code is this:
Code:
#include "stdlib.h"
#include "SDL/SDL.h"
#include "SDL/SDL_mixer.h"
int main(int argc, char *argv[])
{
SDL_Surface *screen;
Mix_Chunk *sound = NULL;
int channel;
int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16SYS;
int audio_channels = 2;
int audio_buffers = 4096;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0) {
printf("Unable to initialize audio: %s\n", Mix_GetError());
exit(1);
}
sound = Mix_LoadWAV("sound.wav");
if(sound == NULL) {
printf("Unable to load WAV file: %s\n", Mix_GetError());
}
screen = SDL_SetVideoMode(320, 240, 0, SDL_ANYFORMAT);
if (screen == NULL) {
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}
channel = Mix_PlayChannel(-1, sound, 0);
if(channel == -1) {
printf("Unable to play WAV file: %s\n", Mix_GetError());
}
while(Mix_Playing(channel) != 0);
Mix_FreeChunk(sound);
Mix_CloseAudio();
SDL_Quit();
return 0;
}
Hi All,
I was wondering if someone could clarify the best way to display mpeg video with SDL in MinGW.
After scouring the internet it seems there is not a lot of information regarding this subject (or at least not up to date) and libraries that are available for this purpose.
Any help/... (1 Reply)
I would like to be able to shell out to the command line and play sounds.
After installing "sox" I can now do this using the play command. Is there a way to stop the playing once it starts? (5 Replies)
hi, i've just downloaded a test game to try compiling it with the gcc compiler in Solaris, the problem was that ./configure command return this error *** Could not run SDL test program, checking why...
*** The test program compiled, but did not run. This usually means
*** that the run-time linker... (0 Replies)
Hi,
I am working on SDL open-source API's on Debian Linux for my game development project. I am not sure whether posting SDL related queries here is correct. I would like to know what is the difference between:
SDL_SetVideoMode() and SDL_VideoModeOK() functions (0 Replies)
I get a:
Requirements:
SDL
when I'm browsing (www.happypenguin.org) for games.
According to wikipedia SDL can be:
where some are more likely than others. However, which one is it? I got an error because of SDL last time I tried and want to make it right before I try... (0 Replies)