sound.cpp: /*Sonido programado por Rodrigo J. Castillo Acuña e-mail: rodrigo.castillo.a@gmail.com SOUND MADE IN CHILE */ #include "sound.h" void CSound::LoadSound(char *dir) { Mix_OpenAudio(44100, AUDIO_S16, 2, 4096); m_Sound = Mix_LoadMUS(dir); } void CSound::PlaySound(int nrepetir) { Mix_PlayMusic(m_Sound, nrepetir); } void CSound::SoundVolume(int volume) { Mix_VolumeMusic(volume); } void CSound::CloseSound() { if(m_Sound) { Mix_HaltMusic(); Mix_FreeMusic(m_Sound); } } void CSound::LoadWav(char *file) { Mix_OpenAudio(44100, AUDIO_S16, 2, 4096); m_Wavsound = Mix_LoadWAV(file); } void CSound::PlayWav(int channel, int repetir) { Mix_PlayChannel (channel,m_Wavsound,repetir); } void CSound::CloseWav(int channelclose) { Mix_HaltChannel(channelclose); Mix_FreeChunk(m_Wavsound); } sound.h: /*Sonido programado por Rodrigo J. Castillo Acuña e-mail: rodrigo.castillo.a@gmail.com SOUND MADE IN CHILE */ #include class CSound { public: Mix_Music *m_Sound; Mix_Chunk *m_Wavsound; void LoadSound(char *dir); void PlaySound(int nrepetir); void SoundVolume(int volume); void CloseSound(); void LoadWav(char *file); void PlayWav(int channel, int repetir); void CloseWav(int channelclose); }; SDLinicio.cpp: #include #include #include "sound.h" using namespace std; int main(int argv, char *argc[]) { SDL_Surface *screen; SDL_Event event; bool done = false; CSound musica; CSound wav; musica.LoadSound("07 Caminar sobre el agua.ogg"); if (SDL_Init(SDL_INIT_VIDEO) < 0) { cout << "No se pudo iniciar SDL:\n" << SDL_GetError(); return 1; } screen = SDL_SetVideoMode(800,600,32,SDL_HWSURFACE); if (screen == NULL) { cout << "No se puede inicializar el modo gráfico: \n" << SDL_GetError(); return 1; } SDL_WM_SetCaption ("Forseu muy alfa... demasiado alfa 0.0.0.0.0.0.0.1 xD aka 4seu ", NULL); atexit(SDL_Quit); musica.PlaySound(-1); while(done == false) { while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_KEYDOWN ) done = true; } } musica.CloseSound(); return 0; }