It is currently Sun Apr 23, 2017 8:54 am

All times are UTC - 5 hours




 Page 1 of 1 [ 3 posts ] 
Author Message
 Post subject: OpenAL VMK 10 - Cleanup
PostPosted: Tue Sep 14, 2010 4:30 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
I've dedicated this video to do some cleanup work. A few variable name and function name changes. Near the end of the video I rewrite one function to allow us to easily change the master volume, or the volume of a source or stream.


Offline
 Profile  
 
 Post subject: Setting The Master Volume
PostPosted: Thu Sep 16, 2010 5:15 am 

Joined: Sat Aug 16, 2008 7:58 am
Posts: 447
I have noticed that after creating the new function in the AudioManager class to change the volume it requires 3 paramaters. First one being the change in volume the second being the type and finally the third being the ID to the source you want to change.

Here is the function that was added
bool AudioManager::SetVolume( float fVolumeGain, Type type, int iID ) const;


Looking at the switch statement inside the function and look at the second two cases for the two types of sources it checks to see if the source's ID is valid, if so it then calls the alSourcef() function which uses that ID then changes the gain / volume to that source. However if we look at the very first case LISTENER it does not use an ID in anyway. Why am I bringing this up. It should be fairly simple. When I call this function in my main.cpp file to change the volume of any of the 3, this is what I have noticed.

The function takes 3 params which we have already seen, but if you are to use the type (second param) as a Listener, for this function to work correctly I simply used "0" for the 3rd parameter. Here is my code in main.cpp, otherwise if you are using SOURCE or STREAM as your type for the second param, then you do need to specify which ID to use.

// ---------------------------------------------------------------------------------------------- //
// Name: main()
// Desc: Main Entry Into The Program
// ---------------------------------------------------------------------------------------------- //
int main(int argc, char** argv)
{
   AudioManager Audio;
   if ( !Audio.Initialize() )
   {
      return 1;
   }
   
   
   
   Audio.SetVolume( 1.0f, Audio.LISTENER, 0 );
   Audio.CreateSource( AUDIO_TEST, "Audio/Testing.ogg" );

   Audio.CreateStream( STREAM_MUSIC, "Audio/music.ogg" );
   Audio.SetVolume( 0.1f, Audio.STREAM, STREAM_MUSIC );
   Audio.StartStream( STREAM_MUSIC );
   
   Audio.SetVolume( 0.2f, Audio.SOURCE, AUDIO_TEST );
   Audio.Play( AUDIO_TEST );


   while ( Audio.IsPlaying( AUDIO_TEST ) )
   {
      Sleep( 100 );
   }
      
   return 0;

} // Main


If you were having trouble using this function to change the "Master Volume", I hope this explanation works for you! :)


Offline
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2010 7:43 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1094
Location: Ontario Canada
Thanks for the comment skilz80. I forgot to mention this in the video. When I first made this function it was defined this way:

bool AudioManager::SetVolume( float fVolumeGain, Type type, int iID = 0 ) const;


That is why iID is last and not first as with all the other functions in the AudioManager. But after doing it this way, I realized the function was prone to errors because people could set the second parameter and forget to specify a value for the third parameter and not realize this (no compiler error).

All this will be moot though once you complete the next VMK since this function's signature changes in VMK 11.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


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

Jump to:  

cron