Esempio n. 1
0
int digi_start_sound_object(int obj)
{
 int slot;

 if (!digi_initialised) return -1;
 LOCK();
 slot = get_free_slot();

 if (slot<0) { UNLOCK(); return -1; }


 SoundSlots[slot].soundno = SoundObjects[obj].soundnum;
 SoundSlots[slot].samples = Sounddat(SoundObjects[obj].soundnum)->data;
 SoundSlots[slot].length = Sounddat(SoundObjects[obj].soundnum)->length;
 SoundSlots[slot].volume = fixmul(digi_volume, SoundObjects[obj].volume);
 SoundSlots[slot].pan = SoundObjects[obj].pan;
 SoundSlots[slot].position = 0;
 SoundSlots[slot].looped = (SoundObjects[obj].flags & SOF_PLAY_FOREVER);
 SoundSlots[slot].playing = 1;

 SoundObjects[obj].signature = next_signature++;
 SoundObjects[obj].handle = slot;

 SoundObjects[obj].flags |= SOF_PLAYING;
 //added on 980905 by adb to add sound kill system from original sos digi.c
 reset_sounds_on_channel(slot);
 //end edit by adb
 
 UNLOCK();
 return 0;
}
Esempio n. 2
0
int digi_start_sound(int soundnum, fix volume, fix pan, int unknown1, int unknown2, int unknown3, int unknown4)
{
 int ntries;
 int slot;

 if (!digi_initialised) return -1;

 //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
 ntries = 0;

TryNextChannel:
 if ( (SampleHandles[next_handle] >= 0) && (SoundSlots[SampleHandles[next_handle]].playing)  )
 {
  if ( (SoundSlots[SampleHandles[next_handle]].volume > digi_volume) && (ntries<digi_max_channels) )
  {
   //mprintf(( 0, "Not stopping loud sound %d.\n", next_handle ));
   next_handle++;
   if ( next_handle >= digi_max_channels )
    next_handle = 0;
   ntries++;
   goto TryNextChannel;
  }
  //mprintf(( 0, "[SS:%d]", next_handle ));
  SoundSlots[SampleHandles[next_handle]].playing = 0;
  SampleHandles[next_handle] = -1;
 }
 //end edit by adb

 slot = get_free_slot();
 if (slot<0) return -1;

 SoundSlots[slot].soundno = soundnum;
 SoundSlots[slot].samples = GameSounds[soundnum].data;
 SoundSlots[slot].length = GameSounds[soundnum].length;
 SoundSlots[slot].volume = fixmul(digi_volume, volume);
 SoundSlots[slot].pan = pan;
 SoundSlots[slot].position = 0;
 SoundSlots[slot].looped = 0;
 SoundSlots[slot].playing = 1;

 //added on 980905 by adb to add sound kill system from original sos digi.c
 reset_sounds_on_channel(slot);
 SampleHandles[next_handle] = slot;
 next_handle++;
 if ( next_handle >= digi_max_channels )
  next_handle = 0;
 //end edit by adb

 return slot;
}
Esempio n. 3
0
int digi_start_sound(int soundnum, fix volume, fix pan)
{
 int ntries;
 int slot;

 if (!digi_initialised) return -1;
 LOCK();
 //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
 ntries = 0;

TryNextChannel:
 if ( (SampleHandles[next_handle] >= 0) && (SoundSlots[SampleHandles[next_handle]].playing)  )
 {
  if ( (SoundSlots[SampleHandles[next_handle]].volume > digi_volume) && (ntries<digi_max_channels) )
  {
   next_handle++;
   if ( next_handle >= digi_max_channels )
    next_handle = 0;
   ntries++;
   goto TryNextChannel;
  }
  SoundSlots[SampleHandles[next_handle]].playing = 0;
  SampleHandles[next_handle] = -1;
 }
 //end edit by adb

 slot = get_free_slot();
 if (slot<0) return -1;

 SoundSlots[slot].soundno = soundnum;
 SoundSlots[slot].samples = Sounddat(soundnum)->data;
 SoundSlots[slot].length = Sounddat(soundnum)->length;
 SoundSlots[slot].volume = fixmul(digi_volume, volume);
 SoundSlots[slot].pan = pan;
 SoundSlots[slot].position = 0;
 SoundSlots[slot].looped = 0;
 SoundSlots[slot].playing = 1;

 //added on 980905 by adb to add sound kill system from original sos digi.c
 reset_sounds_on_channel(slot);
 SampleHandles[next_handle] = slot;
 next_handle++;
 if ( next_handle >= digi_max_channels )
  next_handle = 0;
 //end edit by adb
 UNLOCK();
 return slot;
}
Esempio n. 4
0
int digi_start_sound_object(int obj)
{
 int slot;
 HRESULT hr;

   if (!digi_initialised)
    return -1;
  slot = get_free_slot();

   if (slot<0)
    return -1;

  SoundSlots[slot].soundno = SoundObjects[obj].soundnum;
  SoundSlots[slot].samples = Sounddat(SoundObjects[obj].soundnum)->data;
  SoundSlots[slot].length = Sounddat(SoundObjects[obj].soundnum)->length;
  SoundSlots[slot].volume = fixmul(digi_volume, SoundObjects[obj].volume);
  SoundSlots[slot].pan = SoundObjects[obj].pan;
  SoundSlots[slot].position = 0;
  SoundSlots[slot].looped = (SoundObjects[obj].flags & SOF_PLAY_FOREVER);
  SoundSlots[slot].playing = 1;

  memset(&waveformat, 0, sizeof(waveformat));
  waveformat.wFormatTag=WAVE_FORMAT_PCM;
  waveformat.wBitsPerSample = Sounddat(SoundObjects[obj].soundnum)->bits;
  waveformat.nChannels = 1;
  waveformat.nSamplesPerSec = Sounddat(SoundObjects[obj].soundnum)->freq;
  waveformat.nBlockAlign =
  waveformat.nChannels * (waveformat.wBitsPerSample/8);
  waveformat.nAvgBytesPerSec =
  waveformat.nSamplesPerSec * waveformat.nBlockAlign;

  memset(&dsbd, 0, sizeof(dsbd));
  dsbd.dwSize = sizeof(dsbd);
  dsbd.dwFlags = (DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME) | DSBCAPS_GETCURRENTPOSITION2;
  dsbd.dwReserved=0;
  dsbd.dwBufferBytes = SoundSlots[slot].length;
  dsbd.lpwfxFormat = &waveformat;

  hr = IDirectSound_CreateSoundBuffer(lpds, &dsbd, &SoundSlots[slot].lpsb, NULL);
   if ( hr != DS_OK )
    {
      abort();
    }
   {
    char *ptr1, *ptr2;
    DWORD len1, len2;
     IDirectSoundBuffer_Lock(SoundSlots[slot].lpsb, 0, SoundSlots[slot].length,
                             (void **)&ptr1, &len1, (void **)&ptr2, &len2, 0);
     memcpy(ptr1, SoundSlots[slot].samples, MIN(len1,(int)SoundSlots[slot].length));
     IDirectSoundBuffer_Unlock(SoundSlots[slot].lpsb, (void *)ptr1, len1, (void *)ptr2, len2);
   }
  IDirectSoundBuffer_SetPan(SoundSlots[slot].lpsb, ((int)(f2fl(SoundSlots[slot].pan) * 20000))-10000);
  IDirectSoundBuffer_SetVolume(SoundSlots[slot].lpsb,D1vol2DSvol(SoundSlots[slot].volume));
  IDirectSoundBuffer_Play(SoundSlots[slot].lpsb, 0, 0, SoundSlots[slot].looped?DSBPLAY_LOOPING:0);

  SoundObjects[obj].signature = next_signature++;
  SoundObjects[obj].handle = slot;

  SoundObjects[obj].flags |= SOF_PLAYING;
  //added on 980905 by adb to add sound kill system from original sos digi.c
  reset_sounds_on_channel(slot);
  //end edit by adb
 
  return 0;
}
Esempio n. 5
0
int digi_start_sound(int soundnum, fix volume, fix pan)
{
 int ntries;
 int slot;
 HRESULT hr;

   if (!digi_initialised)
    return -1;

  //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
  ntries = 0;

TryNextChannel:
   if ( (SampleHandles[next_handle] >= 0) && (SoundSlots[SampleHandles[next_handle]].playing)  )
    {
       if ( (SoundSlots[SampleHandles[next_handle]].volume > digi_volume) && (ntries<digi_max_channels) )
        {
         //mprintf(( 0, "Not stopping loud sound %d.\n", next_handle ));
          next_handle++;
           if ( next_handle >= digi_max_channels )
            next_handle = 0;
          ntries++;
          goto TryNextChannel;
        }
      //mprintf(( 0, "[SS:%d]", next_handle ));
      DS_release_slot(SampleHandles[next_handle],1);
      SampleHandles[next_handle] = -1;
    }
  //end edit by adb

  slot = get_free_slot();
   if (slot<0)
    return -1;

  SoundSlots[slot].soundno = soundnum;
  SoundSlots[slot].samples = Sounddat(soundnum)->data;
  SoundSlots[slot].length = Sounddat(soundnum)->length;
  SoundSlots[slot].volume = fixmul(digi_volume, volume);
  SoundSlots[slot].pan = pan;
  SoundSlots[slot].position = 0;
  SoundSlots[slot].looped = 0;
  SoundSlots[slot].playing = 1;

  memset(&waveformat, 0, sizeof(waveformat));
  waveformat.wFormatTag=WAVE_FORMAT_PCM;
  waveformat.wBitsPerSample = Sounddat(soundnum)->bits;
  waveformat.nChannels = 1;
  waveformat.nSamplesPerSec = Sounddat(soundnum)->freq;
  waveformat.nBlockAlign =
    waveformat.nChannels * (waveformat.wBitsPerSample/8);
  waveformat.nAvgBytesPerSec =
    waveformat.nSamplesPerSec * waveformat.nBlockAlign;

  memset(&dsbd, 0, sizeof(dsbd));
  dsbd.dwSize = sizeof(dsbd);
  dsbd.dwFlags = (DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLPAN|DSBCAPS_CTRLVOLUME) | DSBCAPS_GETCURRENTPOSITION2;
  dsbd.dwReserved=0;
  dsbd.dwBufferBytes = SoundSlots[slot].length;
  dsbd.lpwfxFormat = &waveformat;

  hr = IDirectSound_CreateSoundBuffer(lpds, &dsbd, &SoundSlots[slot].lpsb, NULL);
   if ( hr != DS_OK )
    {
      printf("Createsoundbuffer failed! hr=0x%X\n", (int)hr);
      abort();
    }

   {
    char *ptr1, *ptr2;
    DWORD len1, len2;
     IDirectSoundBuffer_Lock(SoundSlots[slot].lpsb, 0, Sounddat(soundnum)->length,
                             (void **)&ptr1, &len1, (void **)&ptr2, &len2, 0);
     memcpy(ptr1,Sounddat(soundnum)->data, MIN((int) len1, Sounddat(soundnum)->length));
     IDirectSoundBuffer_Unlock(SoundSlots[slot].lpsb, ptr1, len1, ptr2, len2);
   }

  IDirectSoundBuffer_SetPan(SoundSlots[slot].lpsb, ((int)(f2fl(pan) * 20000.0))-10000);
  IDirectSoundBuffer_SetVolume(SoundSlots[slot].lpsb, D1vol2DSvol(SoundSlots[slot].volume));
  IDirectSoundBuffer_Play(SoundSlots[slot].lpsb, 0, 0, 0);

   //added on 980905 by adb to add sound kill system from original sos digi.c
   reset_sounds_on_channel(slot);
   SampleHandles[next_handle] = slot;
   next_handle++;
    if ( next_handle >= digi_max_channels )
     next_handle = 0;
 //end edit by adb

  return slot;
}