Changeset 3050 for trunk/src


Ignore:
Timestamp:
Mar 9, 2000, 5:18:00 PM (25 years ago)
Author:
mike
Message:

Fixed volume/panning calculation

Location:
trunk/src/dsound/new
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/dsound/new/OS2SNDBUFFER.CPP

    r3047 r3050  
    1 /* $Id: OS2SNDBUFFER.CPP,v 1.3 2000-03-08 20:44:09 mike Exp $ */
     1/* $Id: OS2SNDBUFFER.CPP,v 1.4 2000-03-09 16:18:00 mike Exp $ */
    22
    33/*
     
    2020#include <stdlib.h>
    2121#include <string.h>
    22 #include <math.h>
    2322
    2423#define INITGUID
     
    3332#include <misc.h>
    3433
     34#include "DSVolume.h"
    3535
    3636WAVEFORMATEX wfxDefaultPrimaryBuf = { WAVE_FORMAT_PCM,
     
    518518
    519519   dprintf(("DSOUND-OS2IDirectSoundBuffer::SoundBufSetVolume (%d, buf=%X)", lVolume, me));
    520    if (me == NULL) {
    521       return DSERR_INVALIDPARAM;
    522    }
     520   if (me == NULL || lVolume < -10000) {
     521      return DSERR_INVALIDPARAM;
     522   }
     523   // some apps pass positive values in lVolume, that's wrong right?!?
    523524   me->DSvolume = (lVolume > 0) ? 0 : lVolume;
    524525
    525526   /* = (10 ^ (1/10)) = 1dB - but the formula below gives results _very_ similar */
    526527   /* to 'real' DirectSound, indistinguishable for all practical purposes        */
    527    me->volume = 255.0 * pow(4, me->DSvolume / 1000.0);
     528   //me->volume = 255.0 * pow(4, me->DSvolume / 1000.0);
     529
     530   /* Note: for some strange reason the above code sometimes gives erroneous     */
     531   /* results, hence we now use a simple conversion table (in steps of 4/100 dB) */
     532
     533   if (me->DSvolume < -4000)
     534      me->volume = 0;
     535   else
     536      me->volume = VolTable[-me->DSvolume / 4];
     537
    528538   dprintf(("  New volume: %d", me->volume));
    529539
     
    537547
    538548   dprintf(("DSOUND-OS2IDirectSoundBuffer::SoundBufSetPan (%d, buf=%X)", lPan, me));
    539    if (me == NULL) {
     549   if (me == NULL || lPan < -10000 || lPan > 10000) {
    540550      return DSERR_INVALIDPARAM;
    541551   }
     
    546556   }
    547557
    548    /* Note: the formula below is not necessarily mathematically correct but is */
    549    /* experimentally proven to give very good results                          */
    550    me->pan = 255.0 * pow(4, -abs(lPan) / 1000.0);
    551    me->pan = 255 - me->pan;
     558   /* Note: we use very similar code as for volume above   */
    552559   if (lPan < 0)
    553       me->pan = -me->pan;
     560      if (lPan < -4000)
     561         me->pan = -255;
     562      else
     563         me->pan = VolTable[-lPan / 4] - 255;
     564   else
     565      if (lPan > 4000)
     566         me->pan = 255;
     567      else
     568         me->pan = 255 - VolTable[lPan / 4];
     569
     570   dprintf(("  New pan: %d", me->pan));
    554571
    555572   return DS_OK;
  • trunk/src/dsound/new/dsmixer.cpp

    r3027 r3050  
    5757   else
    5858      vol2 = inBuf->volume * (256 + inBuf->pan) / 256;
     59
    5960   len = inBuf->bufferdesc.dwBufferBytes / bytespersample * 1024;
    6061   if ((inBuf->lpfxFormat->nChannels == 2) && (inBuf->lpfxFormat->wBitsPerSample == 16)) {
Note: See TracChangeset for help on using the changeset viewer.