Bug in CDirectSoundAudioBuffer::VPlay

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

    • Bug in CDirectSoundAudioBuffer::VPlay

      It manifests as the inability to change the volume of sounds.

      Inside CDirectSoundAudioBuffer::VPlay:

      Source Code

      1. pDSB->SetVolume( volume );

      should be changed to

      Source Code

      1. // convert volume from 0-100 into range for DirectX
      2. float coeff = (float)volume / 100.0f;
      3. float range = (DSBVOLUME_MAX - DSBVOLUME_MIN);
      4. float fvolume = ( range * coeff ) + DSBVOLUME_MIN;
      5. pDSB->SetVolume( static_cast<LONG>(fvolume) );


      CDirectSoundAudioBuffer::VSetVolume is already doing this.

      There is something else that you must do to be able to set volume of sounds:
      Inside 'CDirectSoundAudio::VInitAudioBuffer', where you specify 'DSBUFFERDESC dsbd', set 'dsbd.dwFlags' to 'DSBCAPS_CTRLVOLUME' to enable volume changing capabilities.

      Also, inside 'CDirectSoundAudio::SetPrimaryBufferFormat', do the same with 'DSBUFFERDESC dsbd' by setting 'dsbd.dwFlags' to 'DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLVOLUME'.

      The post was edited 3 times, last by Kain ().