Correction to CDirectSoundAudioBuffer::VSetVolume

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Correction to CDirectSoundAudioBuffer::VSetVolume

      BEFORE:

      Source Code

      1. float coeff = (float)volume / 100.0f;
      2. float range = (DSBVOLUME_MAX - DSBVOLUME_MIN);
      3. float fvolume = ( range * coeff ) + DSBVOLUME_MIN;


      AFTER:

      Source Code

      1. float coeff = (float)volume / 100.0f;
      2. float logarithmicProportion = coeff >0.1f ? 1+log10(coeff) : 0;
      3. float range = (DSBVOLUME_MAX - MY_DSBVOLUME_MIN);
      4. float fvolume = ( range * logarithmicProportion ) + MY_DSBVOLUME_MIN;


      The major change is the use of log10 to determine the volume gradiation along a logarithmic scale as opposed to a linear scale because DirectSound's SetVolume function takes an input paramater that scales in the same way that decibels are scaled.

      I also use MY_DSBVOLUME_MIN, defined as -5000, instead of the DSBVOLUME_MIN, defined in dsound.h as -10000, because -10000 is just way too silent for a lower bound and I found -5000 to be a better minimum bound for the volume range to avoid an annoying silence for the lower 50% of the volume slider.
    • RE: Correction to CDirectSoundAudioBuffer::VSetVolume

      Great stuff dood - this will be added into the 3rd edition.
      Mr.Mike
      Author, Programmer, Brewer, Patriot