#include <unistd.h>
#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;    
    
	//Initialize BOTH SDL video and SDL audio
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) != 0)
	{
  printf("Unable to initialize SDL: %s\n", SDL_GetError());
  return 1;
	}
	
	//Initialize SDL_mixer with our chosen audio settings
	if(Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, AUDIO_S16, MIX_DEFAULT_CHANNELS, 512) != 0)
	{
  printf("Unable to initialize audio: %s\n", Mix_GetError());
  exit(1);
	}
	
	//Load our WAV file from disk
	sound = Mix_LoadWAV("sound.wav");
	if(sound == NULL)
	{
  printf("Unable to load WAV file: %s\n", Mix_GetError());
	}
	
	//Set the video mode to anything, just need a window
	screen = SDL_SetVideoMode(320, 240, 0, SDL_SWSURFACE);
	if (screen == NULL) {
  printf("Unable to set video mode: %s\n", SDL_GetError());
  return 1;
	}
	
	//Play our sound file, and capture the channel on which it is played
	channel = Mix_PlayChannel(-1, sound, 0);
	if(channel == -1) {
  printf("Unable to play WAV file: %s\n", Mix_GetError());
	}
	
	//Wait until the sound has stopped playing
	while(Mix_Playing(channel) != 0);
	
	//Release the memory allocated to our sound
	Mix_FreeChunk(sound);
	
	//Need to make sure that SDL_mixer and SDL have a chance to clean up
	Mix_CloseAudio();
#ifdef GP2X
	chdir("/usr/gp2x");
	execl("gp2xmenu","gp2xmenu",NULL);
#endif
	SDL_Quit();	
	return 0;
}