/*
 *  call-seq:
 *    volume = new_vol
 *
 *  Set the new #volume level of the sound.
 *  0.0 is totally silent, 1.0 is full volume.
 * 
 *  Volume cannot be set while the sound is fading in or out.
 *  Be sure to check #fading? or rescue from SDLError when
 *  using this method.
 *
 *  May raise::  SDLError if the sound is fading in or out.
 *      
 */
static VALUE rg_sound_setvolume( VALUE self, VALUE volume )
{
        RG_Sound *sound;
        Data_Get_Struct(self,  RG_Sound, sound);

        /* Change channel volume if Sound is currently assigned to a channel */
        if( _rg_sound_channel_check(sound) )
        {
                /* But only if it's not fading right now. */
                if( Mix_FadingChannel(sound->channel) == MIX_NO_FADING )
                {
                        sound->volume = NUM2DBL(volume);
                        Mix_Volume( sound->channel, (int)(MIX_MAX_VOLUME * sound->volume) );
                }
                else
                {
                        rb_raise(eSDLError, "cannot set Sound volume while fading");
                }
        }
        else
        {
                /* Save it for later. */
                sound->volume = NUM2DBL(volume);
        }

        return volume;
}