void SoundSys_Management(void) { int i; int numActive = 0; int num3dUpdates = 0; if(!SoundSwitchedOn) return; /* go through all the active sounds */ for(i=0;i<SOUND_MAXACTIVE;i++) { if(ActiveSounds[i].soundIndex==SID_NOSOUND) continue; /* empty slot */ numActive++; if(PlatSoundHasStopped(i) && !ActiveSounds[i].paused) { Sound_Stop(i); continue; } if(ActiveSounds[i].threedee) { PlatDo3dSound(i); num3dUpdates++; } } HandleFadingLevel(); { int requestedVolume = MUL_FIXED(EffectsSoundVolume,MasterVolumeFadeLevel); if (requestedVolume != GlobalVolume) { SoundSys_ChangeVolume(requestedVolume); } } CheckCDVolume(); PlatUpdatePlayer(); if (ShowDebuggingText.Sounds) { int i = Sound_MaxActive_HW; PrintDebuggingText("Number of Active Sounds %u \n", SoundNumActiveVoices()); //display a list of all sounds being played as well while(i-- > 0) { if(ActiveSounds[i].soundIndex != SID_NOSOUND) { PrintDebuggingText("%s\n",GameSounds[ActiveSounds[i].soundIndex].wavName); } } } if(WARPSPEED_CHEATMODE || JOHNWOO_CHEATMODE || DebuggingCommandsActive) UpdateSoundFrequencies(); }
void SoundSys_StopAll(void) { int i; /* if we're not switched on, should be nothing playing */ if(!SoundSwitchedOn) return; for(i=0;i<SOUND_MAXACTIVE;i++) { if(ActiveSounds[i].soundIndex!=SID_NOSOUND) Sound_Stop(i); } }
void PlacedHierarchyStopSequence(PLACED_HIERARCHY_BEHAV_BLOCK* ph_bhv) { int i; //stop hierarchy from playing ph_bhv->HModelController.Playing=FALSE; //and stop all the sounds for(i=0;i<ph_bhv->num_sounds;i++) { if(ph_bhv->sounds[i].activ_no!=SOUND_NOACTIVEINDEX) { Sound_Stop(ph_bhv->sounds[i].activ_no); } ph_bhv->sounds[i].playing=0; } }
void DeletePlacedHierarchy(PLACED_HIERARCHY_BEHAV_BLOCK* ph_bhv) { int i; if(!ph_bhv) return; for(i=0;i<ph_bhv->num_sounds;i++) { if(ph_bhv->sounds[i].activ_no!=SOUND_NOACTIVEINDEX) { Sound_Stop(ph_bhv->sounds[i].activ_no); } } Dispel_HModel(&ph_bhv->HModelController); }
void Load_SoundState(int* soundHandle) { SOUND_SAVE_BLOCK* block; const char* name; SOUNDINDEX soundIndex; if(!soundHandle) return; block = (SOUND_SAVE_BLOCK*)GetNextBlockIfOfType(SaveBlock_SoundState); if(!block) return ; name = (const char*)(block+1); //stop the current sound if(*soundHandle == SOUND_NOACTIVEINDEX) { Sound_Stop(*soundHandle); } //check the size if(block->header.size != sizeof(*block) + block->fileNameLength) return; soundIndex = GetSoundIndexFromNameAndIndex(name,block->soundIndex); if(soundIndex==SID_NOSOUND) return; { char playOptions[20]="evpP"; if(block->loop) strcat(playOptions,"l"); if(block->marine_ignore) strcat(playOptions,"m"); if(block->reverb_off) strcat(playOptions,"r"); if(block->priority == ASP_Maximum) strcat(playOptions,"h"); if(block->threedee) { strcat(playOptions,"n"); Sound_Play(soundIndex,playOptions,soundHandle,block->volume,block->pitch,block->position,&block->threedeedata); } else { Sound_Play(soundIndex,playOptions,soundHandle,block->volume,block->pitch,block->position); } } }
void Sound::Stop() { if (obj) Sound_Stop(obj); }
/* Patrick 5/6/97 ------------------------------------------------------------- Functions for playing and controlling individual sounds ----------------------------------------------------------------------------*/ void Sound_Play(SOUNDINDEX soundNumber, char *format, ...) { int newIndex; int loop = 0; int *externalRef = NULL; ACTIVESOUNDPRIORITY priority = ASP_Minimum; SOUND3DDATA * p_3ddata = 0; VECTORCH * worldPosn = 0; int volume; int pitch; int marine_ignore; int reverb_off = 0; int soundStartPosition = 0; { extern int PlaySounds; if (!PlaySounds) return; } if(!SoundSwitchedOn) return; /* check soundIndex for bounds, whether it has been loaded, and number of instances */ if((soundNumber<0)||(soundNumber>=SID_MAXIMUM)) return; if(!(GameSounds[soundNumber].loaded)) return; if(!(GameSounds[soundNumber].activeInstances<SOUND_MAXINSTANCES)) return; db_logf5(("About to play sound %i", soundNumber)); /* initialise volume and pitch from game sound data */ volume = GameSounds[soundNumber].volume; pitch = GameSounds[soundNumber].pitch; marine_ignore=0; /* examine the format string: if it is null, ignore it */ if(format) { char *nextChar = format; va_list argPtr; va_start(argPtr,format); while(*nextChar!='\0') { switch(*nextChar) { case('d'): { worldPosn = va_arg(argPtr,VECTORCH*); break; } case('n'): { p_3ddata = va_arg(argPtr,SOUND3DDATA*); break; } case('e'): { externalRef = va_arg(argPtr,int*); break; } case('l'): { loop = 1; priority = ASP_Maximum; break; } case('h'): { priority = ASP_Maximum; break; } case('v'): { volume = va_arg(argPtr,int); if(volume>VOLUME_MAX) volume=VOLUME_MAX; if(volume<VOLUME_MIN) volume=VOLUME_MIN; break; } case('p'): { pitch = va_arg(argPtr,int);; if(pitch>PITCH_MAX) pitch=PITCH_MAX; if(pitch<PITCH_MIN) pitch=PITCH_MIN; break; } case('m'): { marine_ignore=1; break; } case('r'): { reverb_off = 1; break; } case('P'): { soundStartPosition = va_arg(argPtr,int);; break; } default: { break; } } nextChar++; } va_end(argPtr); } /* check for invalid parameter combinations */ if((loop)&&(externalRef==NULL)) { db_log5("SoundPlay bad params."); return; } /* Deal with resource allocation. */ { /* Range of active buffers to search. */ unsigned int min, max; if(GameSounds[soundNumber].flags & SAMPLE_IN_SW) { min = 0; max = SOUND_MAXACTIVE_SW; } else { min = SOUND_MAXACTIVE_SW + 1; max = Sound_MaxActive_HW; } /* find free active sound slot */ newIndex = FindFreeActiveSound(min, max); if(newIndex==SOUND_NOACTIVEINDEX && !(GameSounds[soundNumber].flags & SAMPLE_IN_SW)) { //failed to find a free hardware slot , so try software slot instead. //mainly to cope with cards that can load sounds into hardware , but can't play them there newIndex = FindFreeActiveSound(0, SOUND_MAXACTIVE_SW); } if(newIndex==SOUND_NOACTIVEINDEX) { db_log3("Having to stop another sound."); /* try to find an existing sound with a lower priority */ newIndex = FindLowerPriorityActiveSound(priority, min, max); if(newIndex==SOUND_NOACTIVEINDEX && !(GameSounds[soundNumber].flags & SAMPLE_IN_SW)) { //failed to find a free hardware slot , so try software slot instead. //mainly to cope with cards that can load sounds into hardware , but can't play them there newIndex = FindLowerPriorityActiveSound(priority, 0, SOUND_MAXACTIVE_SW); } if(newIndex==SOUND_NOACTIVEINDEX) { db_log3("Failed to find a lower priority sound."); return; /* give up */ } /* remove it, and use it's slot */ db_log3("Stopping a lower priority sound."); Sound_Stop(newIndex); } else { db_log3("Found a free slot."); } } /* fill out the active sound */ ActiveSounds[newIndex].soundIndex = soundNumber; ActiveSounds[newIndex].priority = priority; ActiveSounds[newIndex].volume = volume; ActiveSounds[newIndex].pitch = pitch; ActiveSounds[newIndex].externalRef = externalRef; ActiveSounds[newIndex].loop = 1; ActiveSounds[newIndex].marine_ignore=marine_ignore; ActiveSounds[newIndex].reverb_off=reverb_off; if(loop) ActiveSounds[newIndex].loop = 1; else ActiveSounds[newIndex].loop = 0; #if 0 fprintf(stderr, "PSND: Play: new = %d. num = %d, p = %d, v = %d, pi = %d, l = %d, mi = %d, rev = %d\n", newIndex, soundNumber, priority, volume, pitch, loop, marine_ignore, reverb_off); fprintf(stderr, "PSND: Play: %d %d %s l:%d\n", newIndex, soundNumber, GameSounds[soundNumber].wavName, loop); #endif if(worldPosn) { VECTORCH zeroPosn = {0,0,0}; ActiveSounds[newIndex].threedeedata.position = *worldPosn; ActiveSounds[newIndex].threedeedata.velocity = zeroPosn; ActiveSounds[newIndex].threedeedata.inner_range = 0; ActiveSounds[newIndex].threedeedata.outer_range = 32000; ActiveSounds[newIndex].threedee = 1; } else if (p_3ddata) { ActiveSounds[newIndex].threedeedata = *p_3ddata; ActiveSounds[newIndex].threedee = 1; } else { VECTORCH zeroPosn = {0,0,0}; ActiveSounds[newIndex].threedeedata.position = zeroPosn; ActiveSounds[newIndex].threedeedata.velocity = zeroPosn; ActiveSounds[newIndex].threedee = 0; } /* try and play the sound */ { int ok = PlatPlaySound(newIndex); if(ok==SOUND_PLATFORMERROR) { /* the sound failed to play: any platform cleanups should have been done, so just bank the sound slot */ ActiveSounds[newIndex] = BlankActiveSound; db_log5("Error: PlatPlaySound failed."); return; } } /* finally, update the game sound instances, and external reference */ GameSounds[soundNumber].activeInstances++; if(externalRef) *externalRef = newIndex; /* only will happen because of savegames */ // if(soundStartPosition && ActiveSounds[newIndex].dsBufferP) // { // //sound starts part of the way in // IDirectSoundBuffer_SetCurrentPosition(ActiveSounds[newIndex].dsBufferP,soundStartPosition); // } #if 0 /* TODO */ if (soundStartPosition) fprintf(stderr, "Sound_Play: sound starts part of the way in (%d)\n", soundStartPosition); #endif }
void LiftDoorBehaveFun(STRATEGYBLOCK* sbptr) { LIFT_DOOR_BEHAV_BLOCK *doorbhv; MORPHCTRL *mctrl; DISPLAYBLOCK* dptr; MODULE *mptr; GLOBALASSERT(sbptr); doorbhv = (LIFT_DOOR_BEHAV_BLOCK*)sbptr->SBdataptr; GLOBALASSERT((doorbhv->bhvr_type == I_BehaviourLiftDoor)); mctrl = doorbhv->PDmctrl; GLOBALASSERT(mctrl); mptr = sbptr->SBmoptr; GLOBALASSERT(mptr); dptr = sbptr->SBdptr; /* update morphing.... */ UpdateMorphing(mctrl); switch(doorbhv->door_state) { case I_door_opening: { mptr->m_flags |= m_flag_open; if(mctrl->ObMorphFlags & mph_flag_finished) { if (doorbhv->SoundHandle!=SOUND_NOACTIVEINDEX) { Sound_Play(SID_DOOREND,"d",&mptr->m_world); Sound_Stop(doorbhv->SoundHandle); } doorbhv->door_state = I_door_open; } break; } case I_door_closing: { if(mctrl->ObMorphFlags & mph_flag_finished) { if (doorbhv->SoundHandle!=SOUND_NOACTIVEINDEX) { Sound_Play(SID_DOOREND,"d",&mptr->m_world); Sound_Stop(doorbhv->SoundHandle); } doorbhv->door_state = I_door_closed; mptr->m_flags &= ~m_flag_open; } else if(AnythingInMyModule(sbptr->SBmoptr)) { if (doorbhv->SoundHandle==SOUND_NOACTIVEINDEX) { Sound_Play(SID_DOORSTART,"d",&mptr->m_world); Sound_Play(SID_DOORMID,"del",&mptr->m_world,&doorbhv->SoundHandle); } OpenDoor(mctrl, doorbhv->door_opening_speed); doorbhv->door_state = I_door_opening; mptr->m_flags |= m_flag_open; } break; } case I_door_open: { mptr->m_flags |= m_flag_open; if(doorbhv->request_state == I_door_closed) { if (doorbhv->SoundHandle==SOUND_NOACTIVEINDEX) { Sound_Play(SID_DOORSTART,"d",&mptr->m_world); Sound_Play(SID_DOORMID,"del",&mptr->m_world,&doorbhv->SoundHandle); } CloseDoor(mctrl, doorbhv->door_closing_speed); doorbhv->door_state = I_door_closing; } break; } case I_door_closed: { mptr->m_flags &= ~m_flag_open; if(doorbhv->request_state == I_door_open) { if (doorbhv->SoundHandle==SOUND_NOACTIVEINDEX) { Sound_Play(SID_DOORSTART,"d",&mptr->m_world); Sound_Play(SID_DOORMID,"del",&mptr->m_world,&doorbhv->SoundHandle); } OpenDoor(mctrl, doorbhv->door_opening_speed); doorbhv->door_state = I_door_opening; mptr->m_flags |= m_flag_open; } break; } default: LOCALASSERT(1==0); } }
void PlacedHierarchyBehaveFun(STRATEGYBLOCK* sbptr) { PLACED_HIERARCHY_BEHAV_BLOCK *ph_bhv; GLOBALASSERT(sbptr); ph_bhv =(PLACED_HIERARCHY_BEHAV_BLOCK*) sbptr->SBdataptr; GLOBALASSERT((ph_bhv->bhvr_type) == I_BehaviourPlacedHierarchy); if(sbptr->SBdptr) { ProveHModel(&ph_bhv->HModelController,sbptr->SBdptr); } else { ProveHModel_Far(&ph_bhv->HModelController,sbptr); } //update sound if(ph_bhv->HModelController.Playing && ph_bhv->current_seq) { int i,j; int timer=ph_bhv->HModelController.sequence_timer; int keyframe_flags=ph_bhv->HModelController.keyframe_flags; if(keyframe_flags) { for(i=0;i<ph_bhv->num_special_track_points;i++) { if(keyframe_flags & ph_bhv->special_track_points[i].track_point_no) { SPECIAL_TRACK_POINT* stp=&ph_bhv->special_track_points[i]; for(j=0;j<stp->num_targets;j++) { TRACK_POINT_TARGET* tpt=&stp->targets[j]; RequestState(tpt->target_sbptr,tpt->request,0); } } } } for(i=0;i<ph_bhv->current_seq->num_sound_times;i++) { PLACED_HIERARCHY_SOUND_TIMES* s_time=&ph_bhv->current_seq->sound_times[i]; if(s_time->sound) { PLACED_HIERARCHY_SOUND* sound=s_time->sound; //not much point in continuing if the sound wasn't loaded anyway if(sound->sound_loaded) { if(timer>=s_time->start_time && timer<s_time->end_time) { //start sound if not already playing if(!sound->playing) { int dist=VectorDistance(&Player->ObWorld,ph_bhv->sound_location); if(dist<=sound->outer_range) //make sure sound is in range { SOUND3DDATA s3d; s3d.position = *ph_bhv->sound_location; s3d.inner_range = sound->inner_range; s3d.outer_range = sound->outer_range; s3d.velocity.vx = 0; s3d.velocity.vy = 0; s3d.velocity.vz = 0; if(s_time->sound->loop) { Sound_Play ((SOUNDINDEX)sound->sound_loaded->sound_num, "nvpel", &s3d,sound->max_volume,sound->pitch,&sound->activ_no); } else { Sound_Play ((SOUNDINDEX)sound->sound_loaded->sound_num, "nvpe", &s3d,sound->max_volume,sound->pitch,&sound->activ_no); } } sound->playing=1; } //otherwise update its position else { int dist=VectorDistance(&Player->ObWorld,ph_bhv->sound_location); if(sound->activ_no!=SOUND_NOACTIVEINDEX) { if(dist<=sound->outer_range) { SOUND3DDATA s3d; s3d.position = *ph_bhv->sound_location; s3d.inner_range = sound->inner_range; s3d.outer_range = sound->outer_range; s3d.velocity.vx = 0; s3d.velocity.vy = 0; s3d.velocity.vz = 0; Sound_UpdateNew3d (sound->activ_no, &s3d); } else { Sound_Stop(sound->activ_no); } } else { if(dist<=sound->outer_range && sound->loop) { SOUND3DDATA s3d; s3d.position = *ph_bhv->sound_location; s3d.inner_range = sound->inner_range; s3d.outer_range = sound->outer_range; s3d.velocity.vx = 0; s3d.velocity.vy = 0; s3d.velocity.vz = 0; Sound_Play ((SOUNDINDEX)sound->sound_loaded->sound_num, "nvpel", &s3d,sound->max_volume,sound->pitch,&sound->activ_no); } } } } else { //stop sound if(sound->activ_no!=SOUND_NOACTIVEINDEX) { Sound_Stop(sound->activ_no); } sound->playing=0; } } } } } }