Difference for arch/win32/digi.c from version 1.5 to 1.6


version 1.5 version 1.6
Line 23
 
Line 23
 #include "newdemo.h"  #include "newdemo.h"
 #include "kconfig.h"  #include "kconfig.h"
 #include "hmpfile.h"  #include "hmpfile.h"
   
   #include "altsound.h"
   
 hmp_file *hmp = NULL;  hmp_file *hmp = NULL;
   
 #ifdef DIGI_SOUND  #ifdef DIGI_SOUND
Line 169
 
Line 172
  return 0;   return 0;
 }  }
   
 /* Find the sound which actually equates to a sound number */  
 int digi_xlat_sound(int soundno)  
 {  
  if ( soundno < 0 ) return -1;  
   
  if ( digi_lomem ) {  
  soundno = AltSounds[soundno];  
  if ( soundno == 255 ) return -1;  
  }  
  return Sounds[soundno];  
 }  
   
 //added 2000/01/15 Matt Mueller -- remove some duplication (and fix a big memory leak, in the kill=0 one case)  //added 2000/01/15 Matt Mueller -- remove some duplication (and fix a big memory leak, in the kill=0 one case)
 static int DS_release_slot(int slot,int kill){  static int DS_release_slot(int slot,int kill){
  if (SoundSlots[slot].lpsb) {   if (SoundSlots[slot].lpsb) {
Line 230
 
Line 221
  int slot;   int slot;
  HRESULT hr;   HRESULT hr;
   
  if (!digi_initialised) return -1;     if (!digi_initialised)
       return -1;
   
  //added on 980905 by adb from original source to add sound kill system   //added on 980905 by adb from original source to add sound kill system
  // play at most digi_max_channel samples, if possible kill sample with low volume   // play at most digi_max_channel samples, if possible kill sample with low volume
Line 255
 
Line 247
  //end edit by adb   //end edit by adb
   
  slot = get_free_slot();   slot = get_free_slot();
  if (slot<0) return -1;     if (slot<0)
       return -1;
   
  SoundSlots[slot].soundno = soundnum;   SoundSlots[slot].soundno = soundnum;
  SoundSlots[slot].samples = GameSounds[soundnum].data;    SoundSlots[slot].samples = Sounddat(soundnum)->data;
  SoundSlots[slot].length = GameSounds[soundnum].length;    SoundSlots[slot].length = Sounddat[soundnum].length;
  SoundSlots[slot].volume = fixmul(digi_volume, volume);   SoundSlots[slot].volume = fixmul(digi_volume, volume);
  SoundSlots[slot].pan = pan;   SoundSlots[slot].pan = pan;
  SoundSlots[slot].position = 0;   SoundSlots[slot].position = 0;
Line 268
 
Line 261
   
  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 = Sounddat(soundnum)->bits;
  waveformat.nChannels = 1;   waveformat.nChannels = 1;
  waveformat.nSamplesPerSec = 11025;    waveformat.nSamplesPerSec = Sounddat(soundnum)->freq;
  waveformat.nBlockAlign =   waveformat.nBlockAlign =
    waveformat.nChannels * (waveformat.wBitsPerSample/8);     waveformat.nChannels * (waveformat.wBitsPerSample/8);
  waveformat.nAvgBytesPerSec =   waveformat.nAvgBytesPerSec =
Line 284
 
Line 277
  dsbd.lpwfxFormat = &waveformat;   dsbd.lpwfxFormat = &waveformat;
   
  hr = IDirectSound_CreateSoundBuffer(lpds, &dsbd, &SoundSlots[slot].lpsb, NULL);   hr = IDirectSound_CreateSoundBuffer(lpds, &dsbd, &SoundSlots[slot].lpsb, NULL);
  if ( hr != DS_OK ) {     if ( hr != DS_OK )
       {
   printf("Createsoundbuffer failed! hr=0x%X\n", (int)hr);    printf("Createsoundbuffer failed! hr=0x%X\n", (int)hr);
   abort();    abort();
  }   }
   
  {   {
   char *ptr1, *ptr2;    char *ptr1, *ptr2;
   int len1, len2;    int len1, len2;
   IDirectSoundBuffer_Lock(SoundSlots[slot].lpsb, 0, GameSounds[soundnum].length,  
        IDirectSoundBuffer_Lock(SoundSlots[slot].lpsb, 0, Sounddat(soundnum)->length,
          (void **)&ptr1, &len1, (void **)&ptr2, &len2, 0);           (void **)&ptr1, &len1, (void **)&ptr2, &len2, 0);
   memcpy(ptr1,GameSounds[soundnum].data, MIN(len1, GameSounds[soundnum].length));       memcpy(ptr1,Sounddat(soundnum)->data, MIN(len1, Sounddat(soundnum)->length));
   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);
 // 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_SetVolume(SoundSlots[slot].lpsb, D1vol2DSvol(SoundSlots[slot].volume));
    
  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 329
 
Line 324
  int slot;   int slot;
  HRESULT hr;   HRESULT hr;
   
  if (!digi_initialised) return -1;     if (!digi_initialised)
       return -1;
  slot = get_free_slot();   slot = get_free_slot();
   
  if (slot<0) return -1;     if (slot<0)
       return -1;
   
  SoundSlots[slot].soundno = SoundObjects[obj].soundnum;   SoundSlots[slot].soundno = SoundObjects[obj].soundnum;
  SoundSlots[slot].samples = GameSounds[SoundObjects[obj].soundnum].data;    SoundSlots[slot].samples = Sounddat(SoundObjects[obj].soundnum)->data;
  SoundSlots[slot].length = GameSounds[SoundObjects[obj].soundnum].length;    SoundSlots[slot].length = Sounddat(SoundObjects[obj].soundnum)->length;
  SoundSlots[slot].volume = fixmul(digi_volume, SoundObjects[obj].volume);   SoundSlots[slot].volume = fixmul(digi_volume, SoundObjects[obj].volume);
  SoundSlots[slot].pan = SoundObjects[obj].pan;   SoundSlots[slot].pan = SoundObjects[obj].pan;
  SoundSlots[slot].position = 0;   SoundSlots[slot].position = 0;
Line 346
 
Line 342
   
  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 = Sounddat(SoundObjects[obj].soundnum)->bits;
  waveformat.nChannels = 1;   waveformat.nChannels = 1;
  waveformat.nSamplesPerSec = 11025;    waveformat.nSamplesPerSec = Sounddat(SoundObjects[obj].soundnum)->freq;
  waveformat.nBlockAlign =   waveformat.nBlockAlign =
  waveformat.nChannels * (waveformat.wBitsPerSample/8);   waveformat.nChannels * (waveformat.wBitsPerSample/8);
  waveformat.nAvgBytesPerSec =   waveformat.nAvgBytesPerSec =
Line 362
 
Line 358
  dsbd.lpwfxFormat = &waveformat;   dsbd.lpwfxFormat = &waveformat;
   
  hr = IDirectSound_CreateSoundBuffer(lpds, &dsbd, &SoundSlots[slot].lpsb, NULL);   hr = IDirectSound_CreateSoundBuffer(lpds, &dsbd, &SoundSlots[slot].lpsb, NULL);
  if ( hr != DS_OK ) {     if ( hr != DS_OK )
       {
   abort();    abort();
  }   }
  {   {
Line 374
 
Line 371
   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));//nope  
  IDirectSoundBuffer_SetVolume(SoundSlots[slot].lpsb,D1vol2DSvol(SoundSlots[slot].volume));   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);
   
Line 398
 
Line 394
  if ( Newdemo_state == ND_STATE_RECORDING )   if ( Newdemo_state == ND_STATE_RECORDING )
  newdemo_record_sound( soundno );   newdemo_record_sound( soundno );
 #endif  #endif
  soundno = digi_xlat_sound(soundno);     if (!digi_initialised)
       return;
  if (!digi_initialised) return;     if (digi_xlat_sound(soundno) < 0 ) return;
   
  if (soundno < 0 ) return;  
   
  digi_start_sound(soundno, max_volume, F0_5);   digi_start_sound(soundno, max_volume, F0_5);
 }  }
Line 417
 
Line 411
  if ( Newdemo_state == ND_STATE_RECORDING )   if ( Newdemo_state == ND_STATE_RECORDING )
  newdemo_record_sound( soundno );   newdemo_record_sound( soundno );
 #endif  #endif
  soundno = digi_xlat_sound(soundno);     if (!digi_initialised)
       return;
  if (!digi_initialised) return;     if (digi_xlat_sound(soundno) < 0 )
       return;
  if (soundno < 0 ) return;  
   
         for (i=0; i < MAX_SOUND_SLOTS; i++)          for (i=0; i < MAX_SOUND_SLOTS; i++)
           if (SoundSlots[i].soundno == soundno) {      if (SoundSlots[i].soundno == soundno)
        {
              SoundSlots[i].playing = 0;               SoundSlots[i].playing = 0;
  DS_release_slot(i,1);   DS_release_slot(i,1);
           }            }
  digi_start_sound(soundno, max_volume, F0_5);  
   
     digi_start_sound(soundno, max_volume, F0_5);
 }  }
   
 void digi_play_sample_3d( int soundno, int angle, int volume, int no_dups ) // Volume from 0-0x7fff  void digi_play_sample_3d( int soundno, int angle, int volume, int no_dups ) // Volume from 0-0x7fff
Line 437
 
Line 431
  no_dups = 1;   no_dups = 1;
   
 #ifdef NEWDEMO  #ifdef NEWDEMO
  if ( Newdemo_state == ND_STATE_RECORDING ) {     if ( Newdemo_state == ND_STATE_RECORDING )
       {
  if ( no_dups )   if ( no_dups )
  newdemo_record_sound_3d_once( soundno, angle, volume );   newdemo_record_sound_3d_once( soundno, angle, volume );
  else   else
  newdemo_record_sound_3d( soundno, angle, volume );   newdemo_record_sound_3d( soundno, angle, volume );
  }   }
 #endif  #endif
  soundno = digi_xlat_sound(soundno);     if (!digi_initialised)
       return;
      if (digi_xlat_sound(soundno) < 0 )
       return;
      if (volume < MIN_VOLUME )
       return;
   
  if (!digi_initialised) return;  
  if (soundno < 0 ) return;  
   
  if (volume < MIN_VOLUME ) return;  
  digi_start_sound(soundno, volume, angle);   digi_start_sound(soundno, volume, angle);
 }  }
   
Line 489
 
Line 485
  }      }  
 }  }
   
 int digi_link_sound_to_object2( int org_soundnum, short objnum, int forever, fix max_volume, fix  max_distance )  int digi_link_sound_to_object2( int soundnum, short objnum, int forever, fix max_volume, fix  max_distance )
 {  {
  int i,volume,pan;   int i,volume,pan;
  object * objp;   object * objp;
  int soundnum;   int soundnum;
   
  soundnum = digi_xlat_sound(org_soundnum);     if ( max_volume < 0 )
       return -1;
  if ( max_volume < 0 ) return -1;     if (!digi_initialised)
 // if ( max_volume > F1_0 ) max_volume = F1_0;      return -1;
      if (digi_xlat_sound(soundnum) < 0 )
  if (!digi_initialised) return -1;      return -1;
  if (soundnum < 0 ) return -1;     if (Sounddat(soundnum)->data==NULL)
  if (GameSounds[soundnum].data==NULL) {      {
  Int3();   Int3();
  return -1;   return -1;
  }   }
  if ((objnum<0)||(objnum>Highest_object_index))   if ((objnum<0)||(objnum>Highest_object_index))
  return -1;   return -1;
   
  if ( !forever ) {     if ( !forever )
       {
  // Hack to keep sounds from building up...   // Hack to keep sounds from building up...
  digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, &Objects[objnum].pos, Objects[objnum].segnum, max_volume,&volume, &pan, max_distance );   digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, &Objects[objnum].pos, Objects[objnum].segnum, max_volume,&volume, &pan, max_distance );
  digi_play_sample_3d( org_soundnum, pan, volume, 0 );        digi_play_sample_3d( soundnum, pan, volume, 0 );
  return -1;   return -1;
  }   }
   
Line 520
 
Line 517
         if (SoundObjects[i].flags==0)          if (SoundObjects[i].flags==0)
             break;              break;
   
  if (i==MAX_SOUND_OBJECTS) {     if (i==MAX_SOUND_OBJECTS)
       {
  mprintf((1, "Too many sound objects!\n" ));   mprintf((1, "Too many sound objects!\n" ));
  return -1;   return -1;
  }   }
Line 536
 
Line 534
  SoundObjects[i].volume = 0;   SoundObjects[i].volume = 0;
  SoundObjects[i].pan = 0;   SoundObjects[i].pan = 0;
  SoundObjects[i].soundnum = soundnum;   SoundObjects[i].soundnum = soundnum;
   
  objp = &Objects[SoundObjects[i].lo_objnum];   objp = &Objects[SoundObjects[i].lo_objnum];
  digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum,    digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum,
                        &objp->pos, objp->segnum, SoundObjects[i].max_volume,                         &objp->pos, objp->segnum, SoundObjects[i].max_volume,
Line 549
 
Line 546
 }  }
   
 int digi_link_sound_to_object( int soundnum, short objnum, int forever, fix max_volume )  int digi_link_sound_to_object( int soundnum, short objnum, int forever, fix max_volume )
 { return digi_link_sound_to_object2( soundnum, objnum, forever, max_volume, 256*F1_0); }  {
     return digi_link_sound_to_object2( soundnum, objnum, forever, max_volume, 256*F1_0);
   }
   
 int digi_link_sound_to_pos2( int org_soundnum, short segnum, short sidenum, vms_vector * pos, int forever, fix max_volume, fix max_distance )  int digi_link_sound_to_pos2( int soundnum, short segnum, short sidenum, vms_vector * pos, int forever, fix max_volume, fix max_distance )
 {  {
  int i, volume, pan;   int i, volume, pan;
  int soundnum;  
   
  soundnum = digi_xlat_sound(org_soundnum);  
   
  if ( max_volume < 0 ) return -1;  
 // if ( max_volume > F1_0 ) max_volume = F1_0;  
   
  if (!digi_initialised) return -1;     if ( max_volume < 0 )
  if (soundnum < 0 ) return -1;      return -1;
  if (GameSounds[soundnum].data==NULL) {     if (!digi_initialised)
       return -1;
      if (digi_sound_xlat(soundnum) < 0)
       return -1;
      if (Sounddat(soundnum)->data==NULL)
       {
  Int3();   Int3();
  return -1;   return -1;
  }   }
   
  if ((segnum<0)||(segnum>Highest_segment_index))   if ((segnum<0)||(segnum>Highest_segment_index))
  return -1;   return -1;
   
  if ( !forever ) {     if ( !forever )
       {
  // Hack to keep sounds from building up...   // Hack to keep sounds from building up...
  digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, pos, segnum, max_volume, &volume, &pan, max_distance );   digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, pos, segnum, max_volume, &volume, &pan, max_distance );
  digi_play_sample_3d( org_soundnum, pan, volume, 0 );        digi_play_sample_3d( soundnum, pan, volume, 0 );
  return -1;   return -1;
  }   }
   
Line 582
 
Line 580
  if (SoundObjects[i].flags==0)   if (SoundObjects[i].flags==0)
  break;   break;
    
  if (i==MAX_SOUND_OBJECTS) {     if (i==MAX_SOUND_OBJECTS)
       {
  mprintf((1, "Too many sound objects!\n" ));   mprintf((1, "Too many sound objects!\n" ));
  return -1;   return -1;
  }   }
Line 620
 
Line 619
 {  {
  int i,killed;   int i,killed;
   
  soundnum = digi_xlat_sound(soundnum);     if (!digi_initialised)
       return;
  if (!digi_initialised) return;  
   
  killed = 0;   killed = 0;
   
  for (i=0; i<MAX_SOUND_OBJECTS; i++ ) {     for (i=0; i<MAX_SOUND_OBJECTS; i++ )
  if ( (SoundObjects[i].flags & SOF_USED) && (SoundObjects[i].flags & SOF_LINK_TO_POS) ) {      if ( (SoundObjects[i].flags & SOF_USED) &&
  if ((SoundObjects[i].lp_segnum == segnum) && (SoundObjects[i].soundnum==soundnum ) && (SoundObjects[i].lp_sidenum==sidenum) ) {           (SoundObjects[i].flags & SOF_LINK_TO_POS) &&
  if ( SoundObjects[i].flags & SOF_PLAYING ) {           (SoundObjects[i].lp_segnum == segnum) &&
            (SoundObjects[i].soundnum==soundnum ) &&
            (SoundObjects[i].lp_sidenum==sidenum) )
        {
           if ( SoundObjects[i].flags & SOF_PLAYING )
            {
          SoundSlots[SoundObjects[i].handle].playing = 0;           SoundSlots[SoundObjects[i].handle].playing = 0;
  DS_release_slot(SoundObjects[i].handle,1);   DS_release_slot(SoundObjects[i].handle,1);
  }   }
  SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound   SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound
  killed++;   killed++;
  }   }
  }  
  }  
  // If this assert happens, it means that there were 2 sounds   // If this assert happens, it means that there were 2 sounds
  // that got deleted. Weird, get John.   // that got deleted. Weird, get John.
  if ( killed > 1 ) {     if ( killed > 1 )
       {
  mprintf( (1, "ERROR: More than 1 sounds were deleted from seg %d\n", segnum ));   mprintf( (1, "ERROR: More than 1 sounds were deleted from seg %d\n", segnum ));
  }   }
 }  }

Legend:
line(s) removed in v.1.5 
line(s) changed
 line(s) added in v.1.6