void PitchedDelay::prepareToPlay(double samplerate, int blockSize) { if (blockSize != sizeLastData) { sizeLastData = blockSize; lastDataL.realloc(sizeLastData); lastDataR.realloc(sizeLastData); } jassert(samplerate == 44100 || samplerate == 48000); if (samplerate != 44100 && samplerate != 44800) samplerate = 44100; sampleRate = samplerate; pitcher.prepareToPlay(sampleRate, blockSize); dcBlock.setSampleRate(sampleRate); latency = pitcher.getLatency(); delayL.setSampleRate(sampleRate); delayR.setSampleRate(sampleRate); updateLatency(latency); clearLastData(); }
void DataFromNexus::operator()(){ int numberOfFrame(0); int frameCounter(0); VDS::Client client; connectToServer(client); initialiseDataToStream(client); setAxisMapping(client); //receive the first full frame doneWithSubscriptions_.wait(); auto start = std::chrono::system_clock::now(); while (runCondition_.getRunCondition()) { getFrame(client); updateLatency(client); if (useMarkerData_) pushMarkerData(client); if (useGrfData_) pushForcePlateData(client); } pushEndOfData(client); client.DisableMarkerData(); client.DisableDeviceData(); cout << "Disconnecting from Nexus..." << std::endl; client.Disconnect(); cout << "Disconnected" << std::endl; doneWithExecution_.wait(); }
void PitchedDelay::setCurrentPitch(int index) { if (index < 0 || index >= pitcher.getNumPitches()) index = -1; pitcher.setPitchProc(index); enablePitch = index >= 0; updateLatency(enablePitch ? pitcher.getLatency() : 0); }
uint64_t MD1Memory::access(MemReq& req) { if (zinfo->numPhases > lastPhase) { futex_lock(&updateLock); //Recheck, someone may have updated already if (zinfo->numPhases > lastPhase) { updateLatency(); } futex_unlock(&updateLock); } switch (req.type) { case PUTX: //Dirty wback profWrites.atomicInc(); profTotalWrLat.atomicInc(curLatency); __sync_fetch_and_add(&curPhaseAccesses, 1); //Note no break case PUTS: //Not a real access -- memory must treat clean wbacks as if they never happened. *req.state = I; break; case GETS: profReads.atomicInc(); profTotalRdLat.atomicInc(curLatency); __sync_fetch_and_add(&curPhaseAccesses, 1); *req.state = req.is(MemReq::NOEXCL)? S : E; break; case GETX: profReads.atomicInc(); profTotalRdLat.atomicInc(curLatency); __sync_fetch_and_add(&curPhaseAccesses, 1); *req.state = M; break; default: panic("!?"); } return req.cycle + ((req.type == PUTS)? 0 /*PUTS is not a real access*/ : curLatency); }
/* Call this each loop to update the game timer */ void gameTimeUpdate() { uint32_t currTime = wzGetTicks(); if (currTime < baseTime) { // Warzone 2100, the first relativistic computer game! // Exhibit A: Time travel // force a rebase debug(LOG_WARNING, "Time travel is occurring! Clock went back in time a bit from %d to %d!\n", baseTime, currTime); baseTime = currTime; timeOffset = graphicsTime; } // Do not update the game time if gameTimeStop has been called if (stopCount == 0) { bool mayUpdate = true; // Calculate the new game time uint32_t scaledCurrTime = (currTime - baseTime)*modifier + timeOffset; if (scaledCurrTime < graphicsTime) // Make sure the clock doesn't step back at all. { debug(LOG_WARNING, "Rescaled clock went back in time a bit from %d to %d!\n", graphicsTime, scaledCurrTime); scaledCurrTime = graphicsTime; baseTime = currTime; timeOffset = graphicsTime; } if (updateWantedTime == 0 && scaledCurrTime >= gameTime) { updateWantedTime = currTime; // This is the time that we wanted to tick. } if (scaledCurrTime >= gameTime && !checkPlayerGameTime(NET_ALL_PLAYERS)) { unsigned player; // Pause time at current game time, since we are waiting GAME_GAME_TIME from other players. scaledCurrTime = gameTime; baseTime = currTime; timeOffset = gameTime; debug(LOG_SYNC, "Waiting for other players. gameTime = %u, player times are {%s}", gameTime, listToString("%u", ", ", gameQueueTime, gameQueueTime + game.maxPlayers).c_str()); mayUpdate = false; for (player = 0; player < game.maxPlayers; ++player) { if (!checkPlayerGameTime(player)) { NETsetPlayerConnectionStatus(CONNECTIONSTATUS_WAITING_FOR_PLAYER, player); break; // GAME_GAME_TIME is processed serially, so don't know if waiting for more players. } } } // Calculate the time for this frame deltaGraphicsTime = scaledCurrTime - graphicsTime; // Adjust deltas. if (scaledCurrTime >= gameTime && mayUpdate) { if (scaledCurrTime > gameTime + GAME_TICKS_PER_SEC*MAXIMUM_SPF) { // Game isn't updating fast enough... uint32_t slideBack = deltaGraphicsTime - GAME_TICKS_PER_SEC*MAXIMUM_SPF; baseTime += slideBack / modifier; // adjust the addition to base time deltaGraphicsTime -= slideBack; } deltaGameTime = GAME_TICKS_PER_UPDATE; updateLatency(); if (crcError) { debug(LOG_ERROR, "Synch error, gameTimes were: {%s}", listToString("%10u", ", ", gameQueueCheckTime, gameQueueCheckTime + game.maxPlayers).c_str()); debug(LOG_ERROR, "Synch error, CRCs were: {%s}", listToString("0x%08X", ", ", gameQueueCheckCrc, gameQueueCheckCrc + game.maxPlayers).c_str()); crcError = false; } } else { deltaGameTime = 0; } if (deltaGameTime != 0) { deltaGraphicsTime = 0; // Don't update graphics until game state is updated. } // Store the game and graphics times gameTime += deltaGameTime; graphicsTime += deltaGraphicsTime; } else { // The game is paused, so the change in time is zero. deltaGameTime = 0; deltaGraphicsTime = 0; } // Pre-calculate fraction used in timeAdjustedIncrement graphicsTimeFraction = (float)deltaGraphicsTime / (float)GAME_TICKS_PER_SEC; ASSERT(graphicsTime <= gameTime, "Trying to see the future."); }