Simplified Mixer Control: Volume
Previous  Top  Next


The GetGenericVolume and SetGenericVolume methods enable you to set the volume controls in a mixer without having to think too hard about the architecture of a particular mixer. These functions therefore can help if you are creating an application that has to work across many different mixer types.

Suppose you wish to get the master volume control values for the playback destination of a mixer. Typically (after selecting the mixer to work on), the code you could write might be something like:



errorCode = MC.GetGenericVolume( MSSMIX_DEST_GENERIC_PLAYBACK, MSSMIX_SOURCE_MASTERCONTROLS, leftVolume, rightVolume )
If
 errorCode<>MSSMERR_NOERROR Then
    ' The function failed, so handle the error

End
 If



Note that you can specify any destination and source type, you don't have to use the generic destination type if you don't want to.

If the method succeeds, the volumes are returned in leftVolume and rightVolume as values between 0 and 100 (percentage values). If the specified source or destination is monophonic, then the same volume will be returned in both parameters.

If the method fails, the most likely causes are:
·There is no volume control for the destination and source type you specified.  
·There is more than one destination and source combination in the mixer that meets the type you specified.  

The second problem is more common than you might think. For example, we have come across mixer drivers where ALL of the sources for a particular destination have been given the type MSSMIX_SOURCE_UNDEFINED! Don't forget that the mixer architecture is defined by the driver software - so it is sometimes difficult to predict how the architecture will work.

Now, to set the volume you can simply use the SetGenericVolume method:



errorCode = MC.SetGenericVolume( MSSMIX_DEST_GENERIC_PLAYBACK, MSSMIX_SOURCE_MASTERCONTROLS, newLeftVolume, newRightVolume )
If
 errorCode<>MSSMERR_NOERROR Then
    ' The function failed, so handle the error

End
 If



The new volumes are specified as values between 0 and 100. If the function succeeds, the volumes actually set may not be exactly the same as the volumes you tried to set (but they will hopefully be close): you can use the GetGenericVolume method to check if you like. If the specified source or destination is monophonic, then the volume will be set to the average of the left and right volumes requested.

If the SetGenericVolume method fails, then the cause is most likely the same as the for GetGenericVolume (see above). The simplified functions are useful in many cases, but they cannot unfortunately cope with all the possible mixer architectures that may be defined.