void T_MProfile::IsSilentTestL() { __UHEAP_MARK; TBool isSilent( iProfile->IsSilent() ); __UHEAP_MARKEND; if( iActiveId == 1 || iActiveId == 4 ) { EUNIT_ASSERT( isSilent ); } else { EUNIT_ASSERT( !isSilent ); } }
AlgorithmStatus FrameCutter::process() { bool lastFrame = false; EXEC_DEBUG("process()"); // if _streamIndex < _startIndex, we need to advance into the stream until we // arrive at _startIndex if (_streamIndex < _startIndex) { // to make sure we can skip that many, use frameSize (buffer has been resized // to be able to accomodate at least that many sample before starting processing) int skipSize = _frameSize; int howmuch = min(_startIndex - _streamIndex, skipSize); _audio.setAcquireSize(howmuch); _audio.setReleaseSize(howmuch); _frames.setAcquireSize(0); _frames.setReleaseSize(0); if (acquireData() != OK) return NO_INPUT; releaseData(); _streamIndex += howmuch; return OK; } // need to know whether we have to zero-pad on the left: ie, _startIndex < 0 int zeropadSize = 0; int acquireSize = _frameSize; int releaseSize = min(_hopSize, _frameSize); // in case hopsize > framesize int available = _audio.available(); // we need this check anyway because we might be at the very end of the stream and try to acquire 0 // for our last frame, which will unfortunately work, so just get rid of this case right now if (available == 0) return NO_INPUT; if (_startIndex < 0) { // left zero-padding and only acquire as much as _frameSize + startIndex tokens and should release zero acquireSize = _frameSize + _startIndex; releaseSize = 0; zeropadSize = -_startIndex; } // if there are not enough tokens in the stream (howmuch < available): if (acquireSize >= available) { // has to be >= in case the size of the audio fits exactly with frameSize & hopSize if (!shouldStop()) return NO_INPUT; // not end of stream -> return and wait for more data to come acquireSize = available; // need to acquire what's left releaseSize = _startIndex >= 0 ? min(available, _hopSize) : 0; // cannot release more tokens than there are available if (_startFromZero) { if (_lastFrameToEndOfFile) { if (_startIndex >= _streamIndex+available) lastFrame = true; } else lastFrame = true; } else { if (_startIndex + _frameSize/2 >= _streamIndex + available) // center of frame >= end of stream lastFrame = true; } } _frames.setAcquireSize(1); _frames.setReleaseSize(1); _audio.setAcquireSize(acquireSize); _audio.setReleaseSize(releaseSize); /* EXEC_DEBUG("zeropadSize: " << zeropadSize << "\tacquireSize: " << acquireSize << "\treleaseSize: " << releaseSize << "\tavailable: " << available << "\tlast frame: " << lastFrame << "\tstartIndex: " << _startIndex << "\tstreamIndex: " << _streamIndex); */ AlgorithmStatus status = acquireData(); EXEC_DEBUG("data acquired (audio: " << acquireSize << " - frames: 1)"); if (status != OK) { if (status == NO_INPUT) return NO_INPUT; if (status == NO_OUTPUT) return NO_OUTPUT; throw EssentiaException("FrameCutter: something weird happened."); } // some semantic description to not get mixed up between the 2 meanings // of a vector<Real> (which acts both as a stream of Real tokens at the // input and as a single vector<Real> token at the output) typedef vector<AudioSample> Frame; // get the audio input and copy it as a frame to the output const vector<AudioSample>& audio = _audio.tokens(); Frame& frame = _frames.firstToken(); frame.resize(_frameSize); // left zero-padding of the frame int idxInFrame = 0; for (; idxInFrame < zeropadSize; idxInFrame++) { frame[idxInFrame] = (Real)0.0; } fastcopy(frame.begin()+idxInFrame, audio.begin(), acquireSize); idxInFrame += acquireSize; // check if the idxInFrame is below the threshold (this would only happen // for the last frame in the stream) and if so, don't produce data if (idxInFrame < _validFrameThreshold) { E_INFO("FrameCutter: dropping incomplete frame"); // release inputs (advance to next frame), but not the output frame (we didn't produce anything) _audio.release(_audio.releaseSize()); return NO_INPUT; } // right zero-padding on the last frame for (; idxInFrame < _frameSize; idxInFrame++) { frame[idxInFrame] = (Real)0.0; } _startIndex += _hopSize; if (isSilent(frame)) { switch (_silentFrames) { case DROP: E_INFO("FrameCutter: dropping silent frame"); // release inputs (advance to next frame), but not the output frame (we didn't produce anything) _audio.release(_audio.releaseSize()); return OK; case ADD_NOISE: { vector<AudioSample> inputFrame(_frameSize, 0.0); fastcopy(&inputFrame[0]+zeropadSize, &frame[0], acquireSize); _noiseAdder->input("signal").set(inputFrame); _noiseAdder->output("signal").set(frame); _noiseAdder->compute(); break; } // otherwise, don't do nothing... case KEEP: default: ; } } EXEC_DEBUG("produced frame; releasing"); releaseData(); _streamIndex += _audio.releaseSize(); EXEC_DEBUG("released"); if (lastFrame) return PASS; return OK; }
bool controller::isVerbose() { return !isSilent(); }
/** * Advance for online execution */ void Redirector::advanceOnline(){ const int MAX=JAIL_NET_BUFFER_SIZE; //Buffer size to read const int POLLBAD=POLLERR|POLLHUP|POLLNVAL; const int POLLREAD=POLLIN|POLLPRI; const int polltimeout= 100; // 0.1 sec States oldstate=state; switch(state){ case begin:{ if(fdps<0) { state=error; //fd pseudo terminal error break; } Util::fdblock(fdps,false); state=connected; case connected:{ //Poll to write and read from program and net if(ws->isReadBuffered()) programbuf += ws->receive(); struct pollfd devices[2]; devices[0].fd=fdps; devices[1].fd=ws->getSocket(); char buf[MAX]; if(programbuf.size()) devices[0].events=POLLREAD|POLLOUT; else devices[0].events=POLLREAD; devices[1].events=POLLREAD; int res=poll(devices,2,polltimeout); if(res==-1) { //Error syslog(LOG_INFO,"pool error %m"); state = error; break; } if(res==0) break; //Nothing to do syslog(LOG_INFO,"poll: program %d %s", devices[0].revents,eventsToString(devices[0].revents).c_str()); if(devices[1].revents & POLLREAD) programbuf += ws->receive(); if((devices[0].revents & POLLREAD) && !isOutputBufferFull()){ //Read program output int readsize=read(fdps,buf,MAX); if(readsize <= 0){ syslog(LOG_INFO,"program output read error: %m"); state=ending; break; //program output read error } if(readsize >0) { ws->send(string(buf,readsize)); } } if(programbuf.size()>0 && (devices[0].revents & POLLOUT)){ //Write to program int written=write(fdps,programbuf.data(),programbuf.size()); if(written <=0) { syslog(LOG_INFO,"Write to program error: %m"); state=ending; break; } programbuf.erase(0,written); } if((devices[0].revents & POLLBAD) && !(devices[0].revents & POLLREAD)){ syslog(LOG_INFO,"Program end or I/O error: %m %d %s",devices[0].revents,eventsToString(devices[0].revents).c_str()); state=ending; break; } break; } case ending:{ if(isSilent()){ syslog(LOG_INFO,"Program terminated with no output"); ws->send("\nProgram terminated with no output\n"); } if(messageBuf.size()>0){ syslog(LOG_INFO,"Add jail message to output"); ws->send(messageBuf); messageBuf=""; } } state=end; /* no break */ case end: case error: if(ws->isClosed()) usleep(50000); else ws->close(); break; } } if(oldstate != state) syslog(LOG_INFO,"New redirector state %d => %d",oldstate,state); }
//=========================================== // Entity::assignData //=========================================== void Entity::assignData(const XmlNode data) { if (data.isNull() || data.name() != "Entity") return; AssetManager assetManager; ShapeFactory shapeFactory; try { bool silent = isSilent(); setSilent(true); XmlAttribute attr = data.firstAttribute(); if (!attr.isNull() && attr.name() == "type") { m_type = internString(attr.getString()); attr = attr.nextAttribute(); } if (!attr.isNull() && attr.name() == "name") { m_name = internString(attr.getString()); attr = attr.nextAttribute(); } Vec2f transl = m_transl; if (!attr.isNull() && attr.name() == "x") { transl.x = attr.getFloat(); attr = attr.nextAttribute(); } if (!attr.isNull() && attr.name() == "y") { transl.y = attr.getFloat(); attr = attr.nextAttribute(); } setTranslation(transl); if (!attr.isNull() && attr.name() == "z") { m_z = attr.getFloat(); // So that no Z values are 'exactly' equal m_z += 0.1f * static_cast<float32_t>(rand()) / static_cast<float32_t>(RAND_MAX); attr = attr.nextAttribute(); } XmlNode node = data.firstChild(); if (!node.isNull() && node.name() == "shape") { m_shape = unique_ptr<Shape>(shapeFactory.create(node.firstChild())); node = node.nextSibling(); } if (!node.isNull() && node.name() == "scale") { setScale(Vec2f(node.firstChild())); node = node.nextSibling(); } if (!attr.isNull() && attr.name() == "rot") { setRotation(attr.getFloat()); } if (!node.isNull() && node.name() == "fillColour") { m_fillColour = Colour(node.firstChild()); node = node.nextSibling(); } if (!node.isNull() && node.name() == "lineColour") { m_lineColour = Colour(node.firstChild()); node = node.nextSibling(); } if (!node.isNull() && node.name() == "lineWidth") { m_lineWidth = node.getInt(); node = node.nextSibling(); } if (!node.isNull() && node.name() == "children") { XmlNode node_ = node.firstChild(); while (!node_.isNull() && node_.name() == "child") { XmlAttribute attr = node_.firstAttribute(); if (!attr.isNull() && attr.name() == "ptr") { long id = attr.getLong(); pEntity_t child = boost::dynamic_pointer_cast<Entity>(assetManager.getAssetPointer(id)); if (!child) throw XmlException("Bad entity asset id", __FILE__, __LINE__); addChild(child); } node_ = node_.nextSibling(); } } setSilent(silent); } catch (XmlException& e) { e.prepend("Error parsing XML for instance of class Entity; "); throw; } recomputeBoundary(); }