| version 1.4 | | version 1.5 |
|---|
| | |
| return Sounds[soundno]; | | return Sounds[soundno]; |
| } | | } |
| | | |
| | | //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){ |
| | | if (SoundSlots[slot].lpsb) { |
| | | unsigned int s; |
| | | IDirectSoundBuffer_GetStatus(SoundSlots[slot].lpsb, &s); |
| | | if (s & DSBSTATUS_PLAYING){ |
| | | if (kill) |
| | | IDirectSoundBuffer_Stop(SoundSlots[slot].lpsb); |
| | | else |
| | | return 0; |
| | | } |
| | | IDirectSoundBuffer_Release(SoundSlots[slot].lpsb); |
| | | SoundSlots[slot].playing = 0; |
| | | SoundSlots[slot].lpsb = NULL; |
| | | return 1; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| static int get_free_slot() | | static int get_free_slot() |
| { | | { |
| int i; | | int i; |
| unsigned int s; | | |
| for (i=0; i<MAX_SOUND_SLOTS; i++) | | for (i=0; i<MAX_SOUND_SLOTS; i++) |
| { | | { |
| if (!SoundSlots[i].playing) return i; | | if (!SoundSlots[i].playing) return i; |
| if (SoundSlots[i].lpsb) { | | if (DS_release_slot(i,0)) |
| IDirectSoundBuffer_GetStatus(SoundSlots[i].lpsb, &s); | | |
| if (!(s & DSBSTATUS_PLAYING)) IDirectSoundBuffer_Release(SoundSlots[i].lpsb); | | |
| SoundSlots[i].playing = 0; | | |
| SoundSlots[i].lpsb = NULL; | | |
| return i; | | return i; |
| } | | } |
| } | | |
| return -1; | | return -1; |
| } | | } |
| | | |
| | |
| 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; |
| if (SoundSlots[i].lpsb) { | | DS_release_slot(i,1); |
| unsigned int s; | | |
| IDirectSoundBuffer_GetStatus(SoundSlots[i].lpsb, &s); | | |
| if (s & DSBSTATUS_PLAYING) IDirectSoundBuffer_Stop(SoundSlots[i].lpsb); | | |
| IDirectSoundBuffer_Release(SoundSlots[i].lpsb); | | |
| SoundSlots[i].playing = 0; | | |
| SoundSlots[i].lpsb = NULL; | | |
| } | | |
| } | | } |
| digi_start_sound(soundno, max_volume, F0_5); | | digi_start_sound(soundno, max_volume, F0_5); |
| | | |
| | |
| if ((SoundObjects[i].lp_segnum == segnum) && (SoundObjects[i].soundnum==soundnum ) && (SoundObjects[i].lp_sidenum==sidenum) ) { | | if ((SoundObjects[i].lp_segnum == segnum) && (SoundObjects[i].soundnum==soundnum ) && (SoundObjects[i].lp_sidenum==sidenum) ) { |
| if ( SoundObjects[i].flags & SOF_PLAYING ) { | | if ( SoundObjects[i].flags & SOF_PLAYING ) { |
| SoundSlots[SoundObjects[i].handle].playing = 0; | | SoundSlots[SoundObjects[i].handle].playing = 0; |
| if (SoundSlots[SoundObjects[i].handle].lpsb) { | | DS_release_slot(SoundObjects[i].handle,1); |
| unsigned int s; | | |
| IDirectSoundBuffer_GetStatus(SoundSlots[SoundObjects[i].handle].lpsb, &s); | | |
| if (s & DSBSTATUS_PLAYING) IDirectSoundBuffer_Stop(SoundSlots[SoundObjects[i].handle].lpsb); | | |
| IDirectSoundBuffer_Release(SoundSlots[SoundObjects[i].handle].lpsb); | | |
| SoundSlots[SoundObjects[i].handle].playing = 0; | | |
| SoundSlots[SoundObjects[i].handle].lpsb = NULL; | | |
| } | | |
| } | | } |
| 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 (SoundObjects[i].lo_objnum == objnum) { | | if (SoundObjects[i].lo_objnum == objnum) { |
| if ( SoundObjects[i].flags & SOF_PLAYING ) { | | if ( SoundObjects[i].flags & SOF_PLAYING ) { |
| SoundSlots[SoundObjects[i].handle].playing = 0; | | SoundSlots[SoundObjects[i].handle].playing = 0; |
| if (SoundSlots[SoundObjects[i].handle].lpsb) { | | DS_release_slot(SoundObjects[i].handle,1); |
| unsigned int s; | | |
| IDirectSoundBuffer_GetStatus(SoundSlots[SoundObjects[i].handle].lpsb, &s); | | |
| if (s & DSBSTATUS_PLAYING) IDirectSoundBuffer_Stop(SoundSlots[SoundObjects[i].handle].lpsb); | | |
| IDirectSoundBuffer_Release(SoundSlots[SoundObjects[i].handle].lpsb); | | |
| SoundSlots[SoundObjects[i].handle].playing = 0; | | |
| SoundSlots[SoundObjects[i].handle].lpsb = NULL; | | |
| } | | |
| } | | } |
| 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++; |
| | |
| // The object that this is linked to is dead, so just end this sound if it is looping. | | // The object that this is linked to is dead, so just end this sound if it is looping. |
| if ( (SoundObjects[i].flags & SOF_PLAYING) && (SoundObjects[i].flags & SOF_PLAY_FOREVER)) { | | if ( (SoundObjects[i].flags & SOF_PLAYING) && (SoundObjects[i].flags & SOF_PLAY_FOREVER)) { |
| SoundSlots[SoundObjects[i].handle].playing = 0; | | SoundSlots[SoundObjects[i].handle].playing = 0; |
| if (SoundSlots[SoundObjects[i].handle].lpsb) { | | DS_release_slot(SoundObjects[i].handle,1); |
| unsigned int s; | | |
| IDirectSoundBuffer_GetStatus(SoundSlots[SoundObjects[i].handle].lpsb, &s); | | |
| if (s & DSBSTATUS_PLAYING) IDirectSoundBuffer_Stop(SoundSlots[SoundObjects[i].handle].lpsb); | | |
| IDirectSoundBuffer_Release(SoundSlots[SoundObjects[i].handle].lpsb); | | |
| SoundSlots[SoundObjects[i].handle].playing = 0; | | |
| SoundSlots[SoundObjects[i].handle].lpsb = NULL; | | |
| } | | |
| } | | } |
| 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 |
| continue; // Go on to next sound... | | continue; // Go on to next sound... |
| | |
| // Sound is too far away, so stop it from playing. | | // Sound is too far away, so stop it from playing. |
| if ((SoundObjects[i].flags & SOF_PLAYING)&&(SoundObjects[i].flags & SOF_PLAY_FOREVER)) { | | if ((SoundObjects[i].flags & SOF_PLAYING)&&(SoundObjects[i].flags & SOF_PLAY_FOREVER)) { |
| SoundSlots[SoundObjects[i].handle].playing = 0; | | SoundSlots[SoundObjects[i].handle].playing = 0; |
| if (SoundSlots[SoundObjects[i].handle].lpsb) { | | DS_release_slot(SoundObjects[i].handle,1); |
| unsigned int s; | | |
| IDirectSoundBuffer_GetStatus(SoundSlots[SoundObjects[i].handle].lpsb, &s); | | |
| if (s & DSBSTATUS_PLAYING) IDirectSoundBuffer_Stop(SoundSlots[SoundObjects[i].handle].lpsb); | | |
| IDirectSoundBuffer_Release(SoundSlots[SoundObjects[i].handle].lpsb); | | |
| SoundSlots[SoundObjects[i].handle].playing = 0; | | |
| SoundSlots[SoundObjects[i].handle].lpsb = NULL; | | |
| } | | |
| SoundObjects[i].flags &= ~SOF_PLAYING; // Mark sound as not playing | | SoundObjects[i].flags &= ~SOF_PLAYING; // Mark sound as not playing |
| } | | } |
| } else { | | } else { |
| | |
| if (digi_sounds_initialized) { | | if (digi_sounds_initialized) { |
| if ( SoundObjects[i].flags & SOF_PLAYING ) { | | if ( SoundObjects[i].flags & SOF_PLAYING ) { |
| SoundSlots[SoundObjects[i].handle].playing=0; | | SoundSlots[SoundObjects[i].handle].playing=0; |
| if (SoundSlots[SoundObjects[i].handle].lpsb) { | | DS_release_slot(SoundObjects[i].handle,1); |
| unsigned int s; | | |
| IDirectSoundBuffer_GetStatus(SoundSlots[SoundObjects[i].handle].lpsb, &s); | | |
| if (s & DSBSTATUS_PLAYING) IDirectSoundBuffer_Stop(SoundSlots[SoundObjects[i].handle].lpsb); | | |
| IDirectSoundBuffer_Release(SoundSlots[SoundObjects[i].handle].lpsb); | | |
| SoundSlots[SoundObjects[i].handle].playing = 0; | | |
| SoundSlots[SoundObjects[i].handle].lpsb = NULL; | | |
| } | | |
| } | | } |
| } | | } |
| 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 |
| | |
| | | |
| void digi_reset_digi_sounds() { | | void digi_reset_digi_sounds() { |
| int i; | | int i; |
| unsigned int s; | | |
| | | |
| for (i=0; i< MAX_SOUND_SLOTS; i++) { | | for (i=0; i< MAX_SOUND_SLOTS; i++) { |
| SoundSlots[i].playing=0; | | SoundSlots[i].playing=0; |
| if (SoundSlots[i].lpsb) { | | DS_release_slot(i,1); |
| IDirectSoundBuffer_GetStatus(SoundSlots[i].lpsb, &s); | | |
| if (s & DSBSTATUS_PLAYING) IDirectSoundBuffer_Stop(SoundSlots[i].lpsb); | | |
| IDirectSoundBuffer_Release(SoundSlots[i].lpsb); | | |
| SoundSlots[i].playing = 0; | | |
| SoundSlots[i].lpsb = NULL; | | |
| } | | |
| | | |
| } | | } |
| | | |
| //added on 980905 by adb to reset sound kill system | | //added on 980905 by adb to reset sound kill system |