Difference for arch/win32/digi.c from version 1.2 to 1.3


version 1.2 version 1.3
Line 9
 
Line 9
 #include <mmsystem.h>  #include <mmsystem.h>
 #include <dsound.h>  #include <dsound.h>
   
   #include <math.h>
   
 #include "error.h"  #include "error.h"
 #include "mono.h"  #include "mono.h"
 #include "fix.h"  #include "fix.h"
Line 100
 
Line 102
 int digi_last_midi_song_loop = 0;  int digi_last_midi_song_loop = 0;
   
 static int digi_initialised = 0;  static int digi_initialised = 0;
   static int digi_atexit_initialised=0;
   
 static int digi_sounds_initialized = 0;  static int digi_sounds_initialized = 0;
   
Line 125
 
Line 128
 {  {
  HRESULT hr;   HRESULT hr;
   
    if (!digi_initialised && g_hWnd){
   
  memset(&waveformat, 0, sizeof(waveformat));   memset(&waveformat, 0, sizeof(waveformat));
  waveformat.wFormatTag=WAVE_FORMAT_PCM;   waveformat.wFormatTag=WAVE_FORMAT_PCM;
  waveformat.wBitsPerSample=8;   waveformat.wBitsPerSample=8;
Line 135
 
Line 140
  waveformat.nAvgBytesPerSec =   waveformat.nAvgBytesPerSec =
  waveformat.nSamplesPerSec * waveformat.nBlockAlign;   waveformat.nSamplesPerSec * waveformat.nBlockAlign;
   
   
   if ((hr = DirectSoundCreate(NULL, &lpds, NULL)) != DS_OK)    if ((hr = DirectSoundCreate(NULL, &lpds, NULL)) != DS_OK)
    return -1;     return -1;
   
Line 154
 
Line 158
  dsbd.lpwfxFormat = &waveformat;   dsbd.lpwfxFormat = &waveformat;
   
  digi_initialised = 1;   digi_initialised = 1;
   }
   
    if (!digi_atexit_initialised){
  atexit(digi_close);   atexit(digi_close);
    digi_atexit_initialised=1;
    }
  return 0;   return 0;
 }  }
   
Line 188
 
Line 197
  return -1;   return -1;
 }  }
   
   int D1vol2DSvol(fix d1v){
   //multiplying by 1.5 doesn't help.  DirectSound uses dB for volume, rather than a linear scale like d1 wants.
   //I had to pull out a math book, but here is the code to fix it :)  -Matt Mueller
   //log x=y  <==>  x=a^y 
   //   a
    if (d1v<=0)
    return -10000;
    else
   // return log2(f2fl(d1v))*1000;//no log2? hm.
    return log(f2fl(d1v))/log(2)*1000.0;
   }
   
 int digi_start_sound(int soundnum, fix volume, fix pan)  int digi_start_sound(int soundnum, fix volume, fix pan)
 {  {
  int ntries;   int ntries;
Line 261
 
Line 282
   IDirectSoundBuffer_Unlock(SoundSlots[slot].lpsb, ptr1, len1, ptr2, len2);    IDirectSoundBuffer_Unlock(SoundSlots[slot].lpsb, ptr1, len1, ptr2, len2);
  }   }
  IDirectSoundBuffer_SetPan(SoundSlots[slot].lpsb, ((int)(f2fl(pan) * 20000.0))-10000);   IDirectSoundBuffer_SetPan(SoundSlots[slot].lpsb, ((int)(f2fl(pan) * 20000.0))-10000);
  /* The actual volume (attenuation) scale is 0 - -10000, but we scale the volume  // IDirectSoundBuffer_SetVolume(SoundSlots[slot].lpsb, MIN(((int)(f2fl(SoundSlots[slot].volume) * 15000.0)) - 10000, 0));//nope
     up by 1.5 x because otherwise sounds fall off too quickly. */   IDirectSoundBuffer_SetVolume(SoundSlots[slot].lpsb, D1vol2DSvol(SoundSlots[slot].volume));
  IDirectSoundBuffer_SetVolume(SoundSlots[slot].lpsb, MIN(((int)(f2fl(SoundSlots[slot].volume) * 15000.0)) - 10000, 0));  
  IDirectSoundBuffer_Play(SoundSlots[slot].lpsb, 0, 0, 0);   IDirectSoundBuffer_Play(SoundSlots[slot].lpsb, 0, 0, 0);
   
  //added on 980905 by adb to add sound kill system from original sos digi.c   //added on 980905 by adb to add sound kill system from original sos digi.c
Line 338
 
Line 359
   IDirectSoundBuffer_Unlock(SoundSlots[slot].lpsb, (void *)ptr1, len1, (void *)ptr2, len2);    IDirectSoundBuffer_Unlock(SoundSlots[slot].lpsb, (void *)ptr1, len1, (void *)ptr2, len2);
  }   }
  IDirectSoundBuffer_SetPan(SoundSlots[slot].lpsb, ((int)(f2fl(SoundSlots[slot].pan) * 20000))-10000);   IDirectSoundBuffer_SetPan(SoundSlots[slot].lpsb, ((int)(f2fl(SoundSlots[slot].pan) * 20000))-10000);
  IDirectSoundBuffer_SetVolume(SoundSlots[slot].lpsb, MIN(((int)(f2fl(SoundSlots[slot].volume) * 15000.0)) - 10000, 0));  // IDirectSoundBuffer_SetVolume(SoundSlots[slot].lpsb, MIN(((int)(f2fl(SoundSlots[slot].volume) * 15000.0)) - 10000, 0));//nope
    IDirectSoundBuffer_SetVolume(SoundSlots[slot].lpsb,D1vol2DSvol(SoundSlots[slot].volume));
  IDirectSoundBuffer_Play(SoundSlots[slot].lpsb, 0, 0, SoundSlots[slot].looped?DSBPLAY_LOOPING:0);   IDirectSoundBuffer_Play(SoundSlots[slot].lpsb, 0, 0, SoundSlots[slot].looped?DSBPLAY_LOOPING:0);
   
  SoundObjects[obj].signature = next_signature++;   SoundObjects[obj].signature = next_signature++;

Legend:
line(s) removed in v.1.2 
line(s) changed
 line(s) added in v.1.3