/* ================ idSound::Event_Trigger this will toggle the idle idSound on and off ================ */ void idSound::Event_Trigger( idEntity *activator ) { if ( wait > 0.0f ) { if ( timerOn ) { timerOn = false; CancelEvents( &EV_Speaker_Timer ); } else { timerOn = true; DoSound( true ); PostEventSec( &EV_Speaker_Timer, wait + gameLocal.random.CRandomFloat() * random ); } } else { if ( gameLocal.isMultiplayer ) { if ( refSound.referenceSound && ( gameLocal.time < playingUntilTime ) ) { DoSound( false ); } else { DoSound( true ); } } else { if ( refSound.referenceSound && refSound.referenceSound->CurrentlyPlaying() ) { DoSound( false ); } else { DoSound( true ); } } } }
/* =============== idSound::UpdateChangableSpawnArgs =============== */ void idSound::UpdateChangeableSpawnArgs( const idDict *source ) { idEntity::UpdateChangeableSpawnArgs( source ); if( source ) { FreeSoundEmitter( true ); spawnArgs.Copy( *source ); idSoundEmitter *saveRef = refSound.referenceSound; gameEdit->ParseSpawnArgsToRefSound( &spawnArgs, &refSound ); refSound.referenceSound = saveRef; idVec3 origin; idMat3 axis; if( GetPhysicsToSoundTransform( origin, axis ) ) { refSound.origin = GetPhysics()->GetOrigin() + origin * axis; } else { refSound.origin = GetPhysics()->GetOrigin(); } spawnArgs.GetFloat( "random", "0", random ); spawnArgs.GetFloat( "wait", "0", wait ); if( ( wait > 0.0f ) && ( random >= wait ) ) { random = wait - 0.001; gameLocal.DWarning( "speaker '%s' at (%s) has random >= wait", name.c_str(), GetPhysics()->GetOrigin().ToString( 0 ) ); } if( !refSound.waitfortrigger && ( wait > 0.0f ) ) { timerOn = true; DoSound( false ); CancelEvents( &EV_Speaker_Timer ); PostEventSec( &EV_Speaker_Timer, wait + gameLocal.random.CRandomFloat() * random ); } else if( !refSound.waitfortrigger && !( refSound.referenceSound && refSound.referenceSound->CurrentlyPlaying() ) ) { // start it if it isn't already playing, and we aren't waitForTrigger DoSound( true ); timerOn = false; } } }
global void RestoreAllSounds() { Sound *sn; Obj *soundObj; Handle sHandle; int soundId; /* For every node on the sound list, load the resource in * the s_number property. If the sState property of the node * is non-zero, restart the sound using the SRestore function * in MIDI.S */ sn = (Sound *) Native(FirstNode(&soundList)); while(sn) { soundObj = (Obj *) Native(GetKey(Pseudo(sn))); soundId = GetProperty (soundObj, s_number); if(sn->sSample) { /* put sample stuff here */ } else { if(soundId) { ResLoad(RES_SOUND,soundId); } if(sn->sState) { sHandle = ResLoad(RES_SOUND,soundId); CriticalHandle(sHandle,TRUE); ResLock(RES_SOUND,soundId,TRUE); SetProperty(soundObj,s_handle,(uint) Pseudo(sHandle)); sn->sPointer = (char far *) sHandle; DoSound(SRestore,(char far *) sn); // if(sn->sSample) { // LockHandle(sHandle); // } UpdateCues(soundObj); } } sn = (Sound *) Native(NextNode(Pseudo(sn))); } /* Reset the default reverb mode */ DoSound(SSetReverb,reverbDefault); }
/* ================ idSound::Event_Off ================ */ void idSound::Event_Off( void ) { if ( timerOn ) { timerOn = false; CancelEvents( &EV_Speaker_Timer ); } DoSound( false ); }
/* ================ idSound::Event_On ================ */ void idSound::Event_On( void ) { if ( wait > 0.0f ) { timerOn = true; PostEventSec( &EV_Speaker_Timer, wait + gameLocal.random.CRandomFloat() * random ); } DoSound( true ); }
global void KillAllSounds() { Sound *sn; Handle theHandle; /* Stop and delete each node in the sound list */ while(!EmptyList(&soundList)) { sn = (Sound *) Native(FirstNode(&soundList)); if (sn->sSample) { audArgs.count = 2; audArgs.func = STOP; audArgs.arg2 = sn->sNumber; KDoAudio ((word *)&audArgs); } else { DoSound(SEnd,(char far *) sn); ResLock(RES_SOUND,sn->sNumber,FALSE); if(theHandle = (Handle) Native(GetProperty((Obj *) Native(sn->sKey), s_handle))) { if ((int)theHandle != 1) { CriticalHandle(theHandle,FALSE); UnlockHandle(theHandle); } } } DeleteNode(&soundList,Pseudo(sn)); } }
global void KRestartGame() { /* Get rid of our internal stuff. */ static int varyList[] = {1,PALVARYKILL}; DoSound(SProcess,FALSE); gameRestarted = 1; gameStarted = FALSE; /* Turn off PalVary */ if (palVaryOn) { palVaryOn = FALSE; palettePercent = 0; KPalVary(varyList); } KillAllSounds(); DisposeAllScripts(); DisposeLastCast(); /* SetDebug(FALSE); */ /* free all memory */ ResUnLoad(RES_MEM, ALL_IDS); /* Restore the heap and saved vars to what they were before the call * to PMachine. */ RestartHeap(); /* Regenerate the 'patchable resources' table */ InitPatches(); InitMenu(); DoSound(SProcess,TRUE); DoSound(SSetReverb,0); reverbDefault = 0; /* Now restore the stack and restart the PMachine. */ longjmp(restartBuf, 1); }
global void TermSndDrv() { KillAllSounds(); DoSound(STerminate); #ifdef AMIGA if(dummysoundbank) { FreeMem(dummysoundbank,dsoundsize); dummysoundbank = NULL; } #endif }
/* =============== idSound::SetSound =============== */ void idSound::SetSound( const char *sound, int channel ) { const idSoundShader *shader = declManager->FindSound( sound ); if ( shader != refSound.shader ) { FreeSoundEmitter( true ); } gameEdit->ParseSpawnArgsToRefSound(&spawnArgs, &refSound); refSound.shader = shader; // start it if it isn't already playing, and we aren't waitForTrigger if ( !refSound.waitfortrigger && !(refSound.referenceSound && refSound.referenceSound->CurrentlyPlaying() ) ) { DoSound( true ); } }
void SoundCallback(void *userdata, Uint8 * stream, int len) { int i; memset(stream, 0, len); for (i = 0; i < SND_COUNT; i++) { if (snd[i].playFlag && snd[i].exists) { DoSound(i, len, stream); return; } } }
int main(){ u16 i; SSTOP = 0; //For me it sounds like the modulation data reduces the background noise for(i = 0; i <= 0x7C; i++) { MODDATA[i << 2] = kModData[i]; } for(i=0;i<32;i++)WAVEDATA1[i<<2] = TRUMPET[i];//Instrument for(i=0;i<32;i++)WAVEDATA2[i<<2] = PIANO[i];//Instrument for(i=0;i<32;i++)WAVEDATA3[i<<2] = VIOLIN[i];//Instrument vbInit(); SSTOP = 1; SND_REGS[0].SxEV0 = 0xFC; // No fadeout; volume is constant. SND_REGS[0].SxEV1 = 0x02; // Repeat it forever. SND_REGS[0].SxRAM = 0x00; SND_REGS[0].SxFQH = 0x00; SND_REGS[0].SxFQL = 0x00; SND_REGS[0].SxLRV = 0x33; SND_REGS[1].SxEV0 = 0xFC; // No fadeout; volume is constant. SND_REGS[1].SxEV1 = 0x02; // Repeat it forever. SND_REGS[1].SxRAM = 0x00; SND_REGS[1].SxFQH = 0x00; SND_REGS[1].SxFQL = 0x00; SND_REGS[1].SxLRV = 0x33; SND_REGS[2].SxEV0 = 0xFC; // No fadeout; volume is constant. SND_REGS[2].SxEV1 = 0x02; // Repeat it forever. SND_REGS[2].SxRAM = 0x00; SND_REGS[2].SxFQH = 0x00; SND_REGS[2].SxFQL = 0x00; SND_REGS[2].SxLRV = 0x33; while(1){ while(!(vbReadPad() & K_ANY)); DoSound(52); } }
/* ================ idSound::Event_Timer ================ */ void idSound::Event_Timer( void ) { DoSound( true ); PostEventSec( &EV_Speaker_Timer, wait + gameLocal.random.CRandomFloat() * random ); }
bool KX_KetsjiEngine::NextFrame() { double timestep = 1.0/m_ticrate; double framestep = timestep; // static hidden::Clock sClock; m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(),true); //float dt = sClock.getTimeMicroseconds() * 0.000001f; //sClock.reset(); if (m_bFixedTime) m_clockTime += timestep; else { // m_clockTime += dt; m_clockTime = m_kxsystem->GetTimeInSeconds(); } double deltatime = m_clockTime - m_frameTime; if (deltatime<0.f) { printf("problem with clock\n"); deltatime = 0.f; m_clockTime = 0.f; m_frameTime = 0.f; } // Compute the number of logic frames to do each update (fixed tic bricks) int frames =int(deltatime*m_ticrate+1e-6); // if (frames>1) // printf("****************************************"); // printf("dt = %f, deltatime = %f, frames = %d\n",dt, deltatime,frames); // if (!frames) // PIL_sleep_ms(1); KX_SceneList::iterator sceneit; if (frames>m_maxPhysicsFrame) { // printf("framedOut: %d\n",frames); m_frameTime+=(frames-m_maxPhysicsFrame)*timestep; frames = m_maxPhysicsFrame; } bool doRender = frames>0; if (frames > m_maxLogicFrame) { framestep = (frames*timestep)/m_maxLogicFrame; frames = m_maxLogicFrame; } while (frames) { m_frameTime += framestep; for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit) // for each scene, call the proceed functions { KX_Scene* scene = *sceneit; /* Suspension holds the physics and logic processing for an * entire scene. Objects can be suspended individually, and * the settings for that preceed the logic and physics * update. */ m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); m_sceneconverter->resetNoneDynamicObjectToIpo();//this is for none dynamic objects with ipo scene->UpdateObjectActivity(); if (!scene->IsSuspended()) { // if the scene was suspended recalcutlate the delta tu "curtime" m_suspendedtime = scene->getSuspendedTime(); if (scene->getSuspendedTime()!=0.0) scene->setSuspendedDelta(scene->getSuspendedDelta()+m_clockTime-scene->getSuspendedTime()); m_suspendeddelta = scene->getSuspendedDelta(); m_logger->StartLog(tc_network, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_NETWORK); scene->GetNetworkScene()->proceed(m_frameTime); //m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); //SG_SetActiveStage(SG_STAGE_NETWORK_UPDATE); //scene->UpdateParents(m_frameTime); m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_PHYSICS1); // set Python hooks for each scene #ifndef DISABLE_PYTHON PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment()); #endif KX_SetActiveScene(scene); scene->GetPhysicsEnvironment()->endFrame(); // Update scenegraph after physics step. This maps physics calculations // into node positions. //m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); //SG_SetActiveStage(SG_STAGE_PHYSICS1_UPDATE); //scene->UpdateParents(m_frameTime); // Process sensors, and controllers m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_CONTROLLER); scene->LogicBeginFrame(m_frameTime); // Scenegraph needs to be updated again, because Logic Controllers // can affect the local matrices. m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_CONTROLLER_UPDATE); scene->UpdateParents(m_frameTime); // Process actuators // Do some cleanup work for this logic frame m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_ACTUATOR); scene->LogicUpdateFrame(m_frameTime, true); scene->LogicEndFrame(); // Actuators can affect the scenegraph m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_ACTUATOR_UPDATE); scene->UpdateParents(m_frameTime); m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_PHYSICS2); scene->GetPhysicsEnvironment()->beginFrame(); // Perform physics calculations on the scene. This can involve // many iterations of the physics solver. scene->GetPhysicsEnvironment()->proceedDeltaTime(m_frameTime,timestep,framestep);//m_deltatimerealDeltaTime); m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_PHYSICS2_UPDATE); scene->UpdateParents(m_frameTime); if (m_game2ipo) { m_sceneconverter->WritePhysicsObjectToAnimationIpo(++m_currentFrame); } scene->setSuspendedTime(0.0); } // suspended else if(scene->getSuspendedTime()==0.0) scene->setSuspendedTime(m_clockTime); DoSound(scene); m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true); } // update system devices m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); if (m_keyboarddevice) m_keyboarddevice->NextFrame(); if (m_mousedevice) m_mousedevice->NextFrame(); if (m_networkdevice) m_networkdevice->NextFrame(); // scene management ProcessScheduledScenes(); frames--; } bool bUseAsyncLogicBricks= false;//true; if (bUseAsyncLogicBricks) { // Logic update sub frame: this will let some logic bricks run at the // full frame rate. for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit) // for each scene, call the proceed functions { KX_Scene* scene = *sceneit; if (!scene->IsSuspended()) { // if the scene was suspended recalcutlate the delta tu "curtime" m_suspendedtime = scene->getSuspendedTime(); if (scene->getSuspendedTime()!=0.0) scene->setSuspendedDelta(scene->getSuspendedDelta()+m_clockTime-scene->getSuspendedTime()); m_suspendeddelta = scene->getSuspendedDelta(); // set Python hooks for each scene #ifndef DISABLE_PYTHON PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment()); #endif KX_SetActiveScene(scene); m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_PHYSICS1); scene->UpdateParents(m_clockTime); // Perform physics calculations on the scene. This can involve // many iterations of the physics solver. m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true); scene->GetPhysicsEnvironment()->proceedDeltaTime(m_clockTime,timestep,timestep); // Update scenegraph after physics step. This maps physics calculations // into node positions. m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_PHYSICS2); scene->UpdateParents(m_clockTime); // Do some cleanup work for this logic frame m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); scene->LogicUpdateFrame(m_clockTime, false); // Actuators can affect the scenegraph m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true); SG_SetActiveStage(SG_STAGE_ACTUATOR); scene->UpdateParents(m_clockTime); scene->setSuspendedTime(0.0); } // suspended else if(scene->getSuspendedTime()==0.0) scene->setSuspendedTime(m_clockTime); DoSound(scene); m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true); } } m_previousClockTime = m_clockTime; // Start logging time spend outside main loop m_logger->StartLog(tc_outside, m_kxsystem->GetTimeInSeconds(), true); return doRender; }
global bool InitSoundDriver() { int patchNum; Handle patchHandle; /* Load sound driver */ #ifdef IBM if((soundDrv = LoadHandle(soundDriver)) == (Handle)NULL) { RAlert(E_CANT_FIND, soundDriver); return (FALSE); } LockHandle(soundDrv); #endif #ifdef AMIGA if(!(bseg = (struct Segment *) LoadSeg(soundDriver))) { RAlert(E_CANT_FIND, soundDriver); return (FALSE); } drvHandle = (unsigned char far *) (((ulong) bseg << 2) + 4); soundDrv = (Handle) &drvHandle; if((DoSound(SPatchReq,(void far *) *(soundDrv), (int far *) &numberOfVoices, (int far *) &numberOfDACs, (int far *) &devID) & 0x7f) == 5) { if(dummysoundbank) { int bankFile; long bankIndex = 0, bankSize; if((bankFile = open("patch.005")) == NULL) { RAlert(E_NO_PATCH); return (FALSE); } read(bankFile,&bankSize,2); bankSize = dsoundsize; while(bankSize > 1024) { read(bankFile,(dummysoundbank + bankIndex),1024); bankSize -= 1024; bankIndex += 1024; } if(bankSize) { read(bankFile,(dummysoundbank + bankIndex),bankSize); } close(bankFile); } else { UnLoadSeg(bseg); if(!(bseg = (struct Segment *) LoadSeg("amiga3v.drv"))) { RAlert(E_CANT_FIND,soundDriver); return (FALSE); } drvHandle = (unsigned char far *) (((ulong) bseg << 2) + 4); soundDrv = (Handle) &drvHandle; } } else { if(dummysoundbank) { FreeMem(dummysoundbank,dsoundsize); dummysoundbank = NULL; } } seglist[segcount++] = bseg; #endif /* Load patch (if one is needed) * If bit 7 of the patch number is set, then the patch * will need to be locked permanently in hunk */ patchNum = DoSound(SPatchReq,(void far *) *(soundDrv), (int far *) &numberOfVoices, (int far *) &numberOfDACs, (int far *) &devID); #ifdef AMIGA if((patchNum & 0x7f) == 5) { /* This Kludge is temporary, until */ patchNum = -1; /* the Amiga interpreter is capable of*/ } /* handling 64k+ resources */ #endif if(patchNum != -1) { if ((patchNum&0x7f) == 10) patchHandle = DoLoad(RES_PATCH,(patchNum & 0x7f)); else patchHandle = ResLoad(RES_PATCH,(patchNum & 0x7f)); if(patchNum & 0x80) { ResLock(RES_PATCH,(patchNum & 0x7f),TRUE); LockHandle(patchHandle); } } /* Initialize sound driver */ #ifdef IBM if(DoSound(SInit,(char far *) *(patchHandle),0) == -1) { DisposeHandle(soundDrv); RAlert(E_NO_MUSIC); return(FALSE); } #endif #ifdef AMIGA if(dummysoundbank) { DoSound(SInit,dummysoundbank); } else { DoSound(SInit,(char far *) *(patchHandle),0); } #endif InitList(&soundList); InstallServer(SoundServer,1); DoSound(SProcess,TRUE); return(TRUE); }