forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problems with SDL_mixer

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Decinoge



Joined: 12 Nov 2007
Posts: 6

PostPosted: Tue Nov 13, 2007 1:46 pm    Post subject: Problems with SDL_mixer Reply with quote

Hi everyone. I've just finished making the services (display, input and sound) for my application. However, my sound service is giving me no music.
I'll show the code:

Code:


/******************************************************
 *Sound Service Provider: Public Service to the People*
 ******************************************************/
class SoundService{
      public:
      SoundService();
      ~SoundService();
     
      Mix_Chunk* loadSound( std::string filename );
      void playSound( Mix_Chunk* sound );
     
      void loadMusic( std::string filename );
      void playMusic();
      void pauseMusic();
     
      void soundKill();
     
      private:
      bool iMusic;
      bool iSound;
      unsigned long int lastRew;
     
      Mix_Music* music;
};



SoundService::SoundService(){
     int audio_rate = 44100;
     Uint16 audio_format = AUDIO_S16;
     int audio_channels = 1;
     int audio_buffers = 4096;
     
     if ( SDL_InitSubSystem(SDL_INIT_AUDIO) < 0 ) {
          fprintf(stderr, "Unable to initialize SDL_AUDIO: %s\n", SDL_GetError());
          return;
     }
     
     if( Mix_OpenAudio( audio_rate, audio_format, audio_channels, audio_buffers ) == -1 ){
         printf("Oh My Goodness, an error : %s", Mix_GetError());
         iMusic = false; iSound = false;
         return;
     } else {
         Mix_QuerySpec(&audio_rate, &audio_format, &audio_channels);
     }
     
     Mix_AllocateChannels(9);
     iMusic = true; iSound = true;
     lastRew = SDL_GetTicks();
}

SoundService::~SoundService(){ }

Mix_Chunk* SoundService::loadSound( std::string filename ){
     if( !iSound ) return NULL;
     Mix_Chunk* loadedSound = NULL;
     
     loadedSound = Mix_LoadWAV( filename.c_str() );
     
     if( loadedSound == NULL ){
         printf("Oh My Goodness, an error : %s", Mix_GetError());
     }
     
     return loadedSound;
}

void SoundService::playSound( Mix_Chunk* sound ){
     if( !iSound ) return;
     int i;
     for( i = 0; i < 9; i++){
          if( Mix_Playing(i) == 0 ){
              if( Mix_PlayChannel( i, sound, 0 ) == -1){
                  printf("Oh My Goodness, an error : %s", Mix_GetError());
              }
              break;
          }
     }
     
}

void SoundService::loadMusic( std::string filename ){
     if( !iMusic ) return;
     if( Mix_PlayingMusic() == 1 ){
         Mix_HaltMusic();
         Mix_FreeMusic( music );
     } else if( music ){
         Mix_FreeMusic( music );
     }
     
     music = NULL;
     music = Mix_LoadMUS( filename.c_str() );
     
     if( music == NULL ){
         printf("Oh My Goodness, an error : %s", Mix_GetError());
     }
}

void SoundService::playMusic(){
     if( !iMusic ) return;
     if( Mix_PlayingMusic() == 1 ){
         Mix_HaltMusic();
     }
     
     if( Mix_PlayMusic( music, -1 ) == -1 ){
         printf("Oh My Goodness, an error : %s", Mix_GetError());
     }
}

void SoundService::pauseMusic(){
     if( !iMusic ) return;
     if( Mix_PausedMusic() == 0 ){
         Mix_PauseMusic();
     } else {
         Mix_ResumeMusic();
     }
}

void SoundService::soundKill(){
     Mix_CloseAudio();
}


the only thing i do on the main is:

after the while cycle:
soundServ.loadMusic( "music.ogg" );
and
soundServ.playMusic();

and after the while cycle:
soundKill();

i also tryed MP3, but no success. this is realy giving me a hard time, all the sound functions are working (dont mind about my strange playSound()... it has a purpose).

any kind of advices would be great.

stay cool and cya arround.
_________________
none
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group