bool CCAudioPlayer::fill(ALuint buffer) { // create buffer if not if(!m_tempBuffer) { m_tempBuffer = (char*)malloc(BUFFER_SIZE * sizeof(char)); } // read max buffer size size_t length = m_stream->read(m_tempBuffer, BUFFER_SIZE); if(length <= 0) { if(isLoop()) { // decrease loop count if(m_loop > 0) m_loop--; // reset to first and read again m_stream->reset(); length = m_stream->read(m_tempBuffer, BUFFER_SIZE); if(length <= 0) return false; } else { return false; } } // set to buffer alBufferData(buffer, getALFormat(), m_tempBuffer, length, m_stream->getSampleRate()); return true; }
int main(int argc,const char *argv[]) { node_t * head=0,*node=0; node_t e={"e",0},d={"d",&e},c={"c",&d},b={"b",&d},a={"a",&b}; head=&a; list_display(&a); printf ("%d\n",list_len(&a)); // head=list_reverse(&a); // list_display(head); node=getRec_k_th(head,1); printf ("Find the reciprocal of the k-th element : %s\n",node->data); node=getMidNode(head); printf ("The middle node is %s\n",node->data); list_display_reserve(head); printf("\n"); node_t f = {"f",0}, g = {"g",&f}, h = {"h",&g}, i = {"i",&h}; f.next = &g; if(isLoop(&i)) printf("the list have a loop\n"); else printf("the list does'nt have a loop\n"); node=getLoopNode(&i); printf ("The loop node is %s\n",node->data); node_t ee = {"1", 0}, dd = {"2", &ee}, cc = {"3", &dd}, bb = {"4", &cc}, aa = {"5", &bb}; node_t z = {"8",&cc}, y = {"7", &z}, x = {"6", &y}; if(is_intersect(&aa, &x)) printf("the two lists are intersect\n"); if(node=get_intersect_node(&aa,&x)) printf("the intersect node is %s",node->data); return 0; }
bool LLAudioSource::isDone() const { static const F32 MAX_AGE = 60.f; static const F32 MAX_UNPLAYED_AGE = 15.f; static const F32 MAX_MUTED_AGE = 11.f; if(mCorrupted) { // If we decode bad data then just kill this source entirely. return true; } else if (isLoop()) { // Looped sources never die on their own. return false; } else if (hasPendingPreloads()) { // If there are pending preload requests then keep it alive. return false; } else if (mQueuedDatap) { // Don't kill this sound if we've got something queued up to play. return false; } else if(mPlayedOnce && (!mChannelp || !mChannelp->isPlaying())) { // This is a single-play source and it already did its thing. return true; } F32 elapsed = mAgeTimer.getElapsedTimeF32(); if (!mChannelp) { LLAudioData* adp = mCurrentDatap; //Still decoding. if(adp && adp->isInPreload()) return false; // We don't have a channel assigned, and it's been // over 15 seconds since we tried to play it. Don't bother. return (elapsed > (mSourceMuted ? MAX_MUTED_AGE : MAX_UNPLAYED_AGE)); } else if (mChannelp->isPlaying()) { // Arbitarily cut off non-looped sounds when they're old. return elapsed > MAX_AGE; } else if(!isSyncSlave()) { // The sound isn't playing back after 15 seconds, kill it. // This might happen if all channels are in use and this source is low-priority return elapsed > MAX_UNPLAYED_AGE; } return false; }
/* Main programm --------------------------*/ int main(){ setup(); //Main loop while(isLoop()){ loop(); } finalize(); }
/** * @brief Returns the innermost loop inside which @a stmt is. * * If there is no innermost loop, it returns the null pointer. * * @par Preconditions * - @a stmt is non-null */ ShPtr<Statement> getInnermostLoop(ShPtr<Statement> stmt) { PRECONDITION_NON_NULL(stmt); auto innLoop = stmt->getParent(); while (innLoop && !isLoop(innLoop)) { innLoop = innLoop->getParent(); } return innLoop; }
/** * @brief Returns the innermost loop or switch inside which @a stmt is. * * If there is no innermost loop or switch, it returns the null pointer. * * @par Preconditions * - @a stmt is non-null */ ShPtr<Statement> getInnermostLoopOrSwitch(ShPtr<Statement> stmt) { PRECONDITION_NON_NULL(stmt); auto innLoopOrSwitch = stmt->getParent(); while (innLoopOrSwitch && !isLoop(innLoopOrSwitch) && !isa<SwitchStmt>(innLoopOrSwitch)) { innLoopOrSwitch = innLoopOrSwitch->getParent(); } return innLoopOrSwitch; }
void UrlAudioPlayer::playEventCallback(SLPlayItf caller, SLuint32 playEvent) { // Note that it's on sub thread, please don't invoke OpenSLES API on sub thread if (playEvent == SL_PLAYEVENT_HEADATEND) { std::shared_ptr<bool> isDestroyed = _isDestroyed; auto func = [this, isDestroyed](){ // If it was destroyed, just return. if (*isDestroyed) { ALOGV("The UrlAudioPlayer (%p) was destroyed!", this); return; } //Note that It's in the caller's thread (Cocos Thread) // If state is already stopped, ignore the play over event. if (_state == State::STOPPED) { return; } //fix issue#8965:AudioEngine can't looping audio on Android 2.3.x if (isLoop()) { play(); } else { setState(State::OVER); if (_playEventCallback != nullptr) { _playEventCallback(State::OVER); } ALOGV("UrlAudioPlayer (%p) played over, destroy self ...", this); destroy(); delete this; } }; if (_callerThreadId == std::this_thread::get_id()) { func(); } else { _callerThreadUtils->performFunctionInCallerThread(func); } } }
bool OsmAnd::Model::Road::isRoundabout() const { for(auto itType = types.begin(); itType != types.end(); ++itType) { auto rule = subsection->section->_encodingRules[*itType]; if(rule->isRoundabout()) return true; else if(rule->getDirection() != Model::Road::TwoWay && isLoop()) return true; } return false; }
char Compiler::getCommand() { char ch; do { if(*mInput) { ch = mInput->get(); } else { ch = 0; break; } } while( !isMove(ch) and !isChange(ch) and !isIO(ch) and !isLoop(ch) ); return ch; }
void LLAudioSource::addAudioData(LLAudioData *adp, const bool set_current) { // Only handle a single piece of audio data associated with a source right now, // until I implement prefetch. if (set_current) { if (!mCurrentDatap) { mCurrentDatap = adp; if (mChannelp) { mChannelp->updateBuffer(); mChannelp->play(); } // Make sure the audio engine knows that we want to request this sound. gAudiop->startNextTransfer(); return; } else if (mQueueSounds) { // If we have current data, and we're queuing, put // the object onto the queue. if (mQueuedDatap) { // We only queue one sound at a time, and it's a FIFO. // Don't put it onto the queue. return; } if (adp == mCurrentDatap && isLoop()) { // No point in queueing the same sound if // we're looping. return; } mQueuedDatap = adp; // Make sure the audio engine knows that we want to request this sound. gAudiop->startNextTransfer(); } else { if (mCurrentDatap != adp) { // Right now, if we're currently playing this sound in a channel, we // update the buffer that the channel's associated with // and play it. This may not be the correct behavior. mCurrentDatap = adp; if (mChannelp) { mChannelp->updateBuffer(); mChannelp->play(); } // Make sure the audio engine knows that we want to request this sound. gAudiop->startNextTransfer(); } } } else { // Add it to the preload list. mPreloadMap[adp->getID()] = adp; gAudiop->startNextTransfer(); } }
bool LLAudioSource::isDone() const { const F32 MAX_AGE = 60.f; const F32 MAX_UNPLAYED_AGE = 15.f; const F32 MAX_MUTED_AGE = 11.f; if (isLoop()) { // Looped sources never die on their own. return false; } if (hasPendingPreloads()) { return false; } if (mQueuedDatap) { // Don't kill this sound if we've got something queued up to play. return false; } F32 elapsed = mAgeTimer.getElapsedTimeF32(); // This is a single-play source if (!mChannelp) { if ((elapsed > (mSourceMuted ? MAX_MUTED_AGE : MAX_UNPLAYED_AGE)) || mPlayedOnce) { // We don't have a channel assigned, and it's been // over 15 seconds since we tried to play it. Don't bother. //llinfos << "No channel assigned, source is done" << llendl; return true; } else { return false; } } if (mChannelp->isPlaying()) { if (elapsed > MAX_AGE) { // Arbitarily cut off non-looped sounds when they're old. return true; } else { // Sound is still playing and we haven't timed out, don't kill it. return false; } } if ((elapsed > MAX_UNPLAYED_AGE) || mPlayedOnce) { // The sound isn't playing back after 15 seconds or we're already done playing it, kill it. return true; } return false; }
/** * @brief Returns the (indirect) successor node of the given statement @a stmt. * * This function may add new nodes. */ ShPtr<CFG::Node> RecursiveCFGBuilder::getIndirectSuccessor(ShPtr<Statement> stmt) { if (isa<ContinueStmt>(stmt)) { // A continue statement has to be inside of a loop. ShPtr<Statement> innLoop(getInnermostLoop(stmt)); if (!innLoop) { return cfg->getExitNode(); } return addNode(innLoop); } if (isa<BreakStmt>(stmt)) { // A break statement has to be inside a loop or switch. ShPtr<Statement> innLoopOrSwitch(getInnermostLoopOrSwitch(stmt)); if (!innLoopOrSwitch) { return cfg->getExitNode(); } if (ShPtr<Statement> succ = innLoopOrSwitch->getSuccessor()) { return addNode(succ); } return getIndirectSuccessor(innLoopOrSwitch); } ShPtr<Statement> stmtParent(stmt->getParent()); if (!stmtParent) { // There is an implicit return from the function. return cfg->exitNode; } if (isLoop(stmtParent)) { return addNode(stmtParent); } if (isa<IfStmt>(stmtParent) && stmtParent->getSuccessor()) { return addNode(stmtParent->getSuccessor()); } if (ShPtr<SwitchStmt> stmtParentSwitch = cast<SwitchStmt>(stmtParent)) { // There should be a fall-through to the next switch clause (or to the // switch's successor, if there is no next clause). // Find out in which clause we are. auto i = stmtParentSwitch->clause_begin(); auto e = stmtParentSwitch->clause_end(); while (i != e) { if (isStatementInStatements(stmt, i->second)) { break; } ++i; } // Create an edge to the next clause (if any). ++i; if (i != e) { // There is a next clause. return addNode(i->second); } } // Traverse over parents (of parents) until a parent with a successor is // found. If there is no such parent, then there is an implicit return from // the current function. do { if (ShPtr<Statement> stmtParentSucc = stmtParent->getSuccessor()) { return addNode(stmtParentSucc); } } while ((stmtParent = stmtParent->getParent())); // There is an implicit return from the function. return cfg->exitNode; }
/** * @brief Tries to perform the case (1) optimization from the class description * on the given statement. * * For the preconditions, see tryOptimization(), which is the place from where * this function should be called. */ void SimpleCopyPropagationOptimizer::tryOptimizationCase1( ShPtr<Statement> stmt, ShPtr<Variable> lhsVar, ShPtr<Expression> rhs) { // Currently, we can only handle the situation where the right-hand side is // a function call; that is, there are no other computations. // TODO Add some more robust analysis to handle also this case. ShPtr<CallExpr> rhsCall(cast<CallExpr>(rhs)); if (!rhsCall) { return; } // We will need the set of variables which may be accessed when calling the // function from the right-hand side. ShPtr<ValueData> stmtData(va->getValueData(stmt)); const VarSet &varsAccessedInCall(stmtData->getDirAccessedVars()); ShPtr<CallInfo> rhsCallInfo(cio->getCallInfo(rhsCall, currFunc)); // Get the first statement where the variable is used by going through the // successors of stmt. During this traversal, check that the optimization // can be done. ShPtr<Statement> firstUseStmt(stmt->getSuccessor()); ShPtr<ValueData> firstUseStmtData; while (firstUseStmt) { firstUseStmtData = va->getValueData(firstUseStmt); if (firstUseStmtData->isDirAccessed(lhsVar)) { // Got it. break; } // There cannot be a compound statement. // TODO Add some more robust analysis to handle also this case. if (firstUseStmt->isCompound()) { return; } // There cannot be other calls, dereferences, or other possibly // "dangerous" constructs. if (firstUseStmtData->hasCalls() || firstUseStmtData->hasAddressOps() || firstUseStmtData->hasDerefs() || firstUseStmtData->hasArrayAccesses() || firstUseStmtData->hasStructAccesses()) { return; } // The statement cannot contain a variable which is accessed in the // original call from the right-hand side (both directly and // indirectly). for (auto i = firstUseStmtData->dir_all_begin(), e = firstUseStmtData->dir_all_end(); i != e; ++i) { if (hasItem(varsAccessedInCall, *i) || rhsCallInfo->mayBeRead(*i) || rhsCallInfo->mayBeModified(*i)) { return; } } // Keep traversing. firstUseStmt = firstUseStmt->getSuccessor(); } // The statement where lhsVar is used after stmt has to exist. if (!firstUseStmt) { return; } // This variable has to be used precisely once in there. if (firstUseStmtData->getDirNumOfUses(lhsVar) != 1) { return; } // There should not be any dereferences or other constructs that may cause // problems. if (firstUseStmtData->hasAddressOps() || firstUseStmtData->hasDerefs() || firstUseStmtData->hasArrayAccesses() || firstUseStmtData->hasStructAccesses()) { return; } // If there is a call, make sure that the statement is either of the form // // return call(a, b, c, ...) // // or // // x = call(a, b, c, ...) // // or // // call(a, b, c, ...) // // where a, b, c, ... are expressions that use only local variables and do // not contain any function calls. if (firstUseStmtData->hasCalls()) { if (firstUseStmtData->getNumOfCalls() != 1) { return; } if (ShPtr<ReturnStmt> returnStmt = cast<ReturnStmt>(firstUseStmt)) { if (!isa<CallExpr>(returnStmt->getRetVal())) { return; } } else if (ShPtr<AssignStmt> assignStmt = cast<AssignStmt>(firstUseStmt)) { if (!isa<CallExpr>(assignStmt->getRhs())) { return; } } else if (!isa<CallStmt>(firstUseStmt)) { return; } for (auto i = firstUseStmtData->dir_read_begin(), e = firstUseStmtData->dir_read_end(); i != e; ++i) { if (hasItem(globalVars, *i)) { return; } } } // The next statement cannot be a while or for loop. Otherwise, we would // optimize // // a = rand() // while (a) { // // ... // } // // to // // while (rand()) { // // ... // } // // which may not be correct. if (isLoop(firstUseStmt)) { return; } // Check that the two uses in stmt and firstUseStmt are the only uses of // lhsVar, with the exception of an optional variable-defining statement. ShPtr<VarDefStmt> lhsDefStmt; ShPtr<VarUses> allLhsUses(vuv->getUses(lhsVar, currFunc)); for (const auto &dirUse : allLhsUses->dirUses) { if (dirUse == stmt || dirUse == firstUseStmt) { continue; } lhsDefStmt = cast<VarDefStmt>(dirUse); if (!lhsDefStmt || lhsDefStmt->getVar() != lhsVar || lhsDefStmt->getInitializer()) { return; } } // Do the optimization. replaceVarWithExprInStmt(lhsVar, rhs, firstUseStmt); va->removeFromCache(firstUseStmt); Statement::removeStatementButKeepDebugComment(stmt); currCFG->removeStmt(stmt); if (lhsDefStmt) { removeVarDefOrAssignStatement(lhsDefStmt, currFunc); currCFG->removeStmt(lhsDefStmt); } }
bool LLAudioSource::play(const LLUUID &audio_uuid) { // Special abuse of play(); don't play a sound, but kill it. if (audio_uuid.isNull()) { if (getChannel()) { llassert(this == getChannel()->getSource()); getChannel()->cleanup(); if (!isMuted()) { mCurrentDatap = NULL; } } return false; } if(mType != LLAudioEngine::AUDIO_TYPE_UI) //&& mSourceID.notNull()) logSoundPlay(this, audio_uuid); // Reset our age timeout if someone attempts to play the source. mAgeTimer.reset(); LLAudioData *adp = gAudiop->getAudioData(audio_uuid); if (isQueueSounds()) { if(mQueuedDatap) { // We already have a sound queued up. Ignore new request. return false; } else if (adp == mCurrentDatap && isLoop()) { // No point in queuing the same sound if // we're looping. return true; } else if(mCurrentDatap) { mQueuedDatap = adp; return true; } } else if(mCurrentDatap == adp) //Desired sound did not change. Just re-play it. { if(getChannel() && getChannel()->isPlaying()) getChannel()->play(); return true; } else //Desired sound did change. Release the old channel if set. { if(getChannel()) getChannel()->cleanup(); mPlayedOnce = false; //Reset the played flag so the new sound is actually started up. } mCurrentDatap = adp; return true; }
bool Compiler::compile(std::istream& input) { mInput = &input; mInstructions.clear(); std::stack<int> loopStack; char command; command = getCommand(); while(command) { int move = 0; while(command and isMove(command)) { if(command == '>') { move++; } else { move--; } command = getCommand(); } if(move != 0) { push(op_move); push(move); } int change = 0; while(command and isChange(command)) { if(command == '+') { change++; } else { change--; } command = getCommand(); } if(change != 0) { push(op_change); push(change); } while(command and isIO(command)) { if(command == '.') { push(op_output); } else { push(op_input); } command = getCommand(); } while(command and isLoop(command)) { if(command == '[') { loopStack.push(mInstructions.size()); push(op_loop_begin); push(-1); } else { if(loopStack.empty()) { mError = "unopened ]"; return false; } else { push(op_loop_end); mInstructions[loopStack.top() + 1].param = mInstructions.size(); loopStack.pop(); } } command = getCommand(); } } if(not loopStack.empty()) { mError = "unclosed ["; return false; } push(op_stop); return true; }