virtual void process(YSE::SOUND_STATUS & intent) { assert(intent != YSE::SS_STOPPED); if (intent == YSE::SS_WANTSTOPLAY) { ramp.set(1, 10); intent = YSE::SS_PLAYING; } else if (intent == YSE::SS_WANTSTOSTOP) { ramp.setIfNew(0, 200); } // generate tone with frequency and velocity out = generator[2](getFrequency() * 3); out *= 0.3; out += generator[1](getFrequency() * 2); out *= 0.6; out += generator[0](getFrequency()); out *= getVelocity() * 0.1f; ramp.update(); if (intent == YSE::SS_WANTSTOSTOP && ramp.getValue() <= 0) { intent = YSE::SS_STOPPED; } out *= ramp; // copy buffer to all channels (YSE creates the buffer vector for your dsp, according to // the channels chosen for the current output device for (UInt i = 0; i < buffer.size(); i++) { buffer[i] = out; } }
//------------------------------------------------------------------------------ // updateData() -- update background data here //------------------------------------------------------------------------------ void IlsRadio::updateData(const LCreal dt) { //Must have ownship if (getOwnship() == 0) return; // Set our position to that of our ownship vehicle setPosition(); //Do not update data every time...Hard code delay length... if(timerCounter==0){ //Get Glideslope and Runway orientation: glideSlopeValid = findILSGlideslopeByFreq(getFrequency()); localizerValid = findLocalizerByFreq(getFrequency()); //Get test results - make sure dest LL do not change as plane flies Basic::Nav::gbd2ll(getLatitude(),getLongitude(),bearing,grdrange,&destLatitude,&destLongitude); //Test for bad result... if((glideSlopeValid==false)|(localizerValid==false)){ //std::cerr << "No ILS In Range..." << std::endl; } } else if(timerCounter==30){ timerCounter=0; //Make sure the lookup occurs on the next cycle } else{ timerCounter++; //Do not do another DB lookup - wait for some time } BaseClass::updateData(dt); }
void SoundSystem::input(const sf::Event& event) { if(event.type == sf::Event::KeyPressed) { if(event.key.code >= sf::Keyboard::F1 && event.key.code <= sf::Keyboard::F6) { setOctaveByKey(event.key.code); } else { RawNote note = map(event.key.code); if(note.getTypeNote() != SILENCE) { //Start the beep float octave = _currentOctave + note.getOctave(); float frequency = getFrequency(note.getTypeNote(), octave); Beeper::get().startBeep(frequency); } } } else if(event.type == sf::Event::KeyReleased) { RawNote note = map(event.key.code); if(note.getTypeNote() != SILENCE) { //Stop the beep float octave = _currentOctave + note.getOctave(); float frequency = getFrequency(note.getTypeNote(), octave); Beeper::get().stopBeep(frequency); } } }
void ProfilerNode::dump( std::ostream& output ) { // convert to microseconds double total = ((double)totalTime * 1000000.) / getFrequency(); double withoutChildren = ((double)withoutChildrenTime * 1000000.) / getFrequency(); output << name << "\t" << (double)totalCalls << "\t" << total << "\t" << withoutChildren << std::endl; }
int getFrameLength(MP3Header * pHeader) { int frame_length = -1; if (pHeader->bitrate != 0 /*BR_FREE*/ && pHeader->bitrate != 15 /*BR_BAD*/ && pHeader->frequency != 3/*SF_RESERVED*/) { if (pHeader->layer == LAYER_I) { frame_length = (12 * getBitrate(pHeader) * 1024 / getFrequency(pHeader) + pHeader->padding) * 4; } else if (pHeader->layer == LAYER_II || !(pHeader->version == MPEG_2_0)) { frame_length = 144 * getBitrate(pHeader) * 1000 / getFrequency(pHeader) + pHeader->padding; } else { frame_length = 72 * getBitrate(pHeader) * 1000 / getFrequency(pHeader) + pHeader->padding; } } return frame_length; }
//------------------------------------------------------------------------------ // transmit() -- send radar emissions //------------------------------------------------------------------------------ void Radar::transmit(const LCreal dt) { BaseClass::transmit(dt); // Transmitting, scanning and have an antenna? if ( !areEmissionsDisabled() && isTransmitting() ) { // Send the emission to the other player Emission* em = new Emission(); em->setFrequency(getFrequency()); em->setBandwidth(getBandwidth()); const LCreal prf1 = getPRF(); em->setPRF(prf1); int pulses = static_cast<int>(prf1 * dt + 0.5); if (pulses == 0) pulses = 1; // at least one em->setPulses(pulses); const LCreal p = getPeakPower(); em->setPower(p); em->setMaxRangeNM(getRange()); em->setPulseWidth(getPulseWidth()); em->setTransmitLoss(getRfTransmitLoss()); em->setReturnRequest( isReceiverEnabled() ); em->setTransmitter(this); getAntenna()->rfTransmit(em); em->unref(); } }
vrpn_HapticVector InstantBuzzEffect::calcEffectForce(void) { #else gstVector InstantBuzzEffect::calcEffectForce(void *phantom) { #endif // No force if inactive if (!active) { return vrpn_HapticVector(0,0,0); } LARGE_INTEGER counter; if (currentPerformanceFrequency.HighPart == 0 && currentPerformanceFrequency.LowPart == 0) { return vrpn_HapticVector(0,0,0); } #ifdef _WIN32 if (QueryPerformanceCounter(&counter) != TRUE){ fprintf(stderr, "unable to get perfo counter\n"); return vrpn_HapticVector(0,0,0); } #endif double elapsedSec = (counter.QuadPart - debut.QuadPart) / (double) currentPerformanceFrequency.QuadPart; if (elapsedSec < getDuration()) { double currentPart = (counter.QuadPart*getFrequency()/currentPerformanceFrequency.QuadPart); currentPart = (currentPart-(long)currentPart)*2*PI; double currentForce = sin(currentPart); double force = currentForce*getAmplitude(); return vrpn_HapticVector( x*force, y*force, z*force ); } return vrpn_HapticVector(0,0,0); }
/** * lets LED blink and changes STATUS * LED will blink 5 times and turns off afterwards * //TODO * must be implemented with a thread later on * @return void */ void CLED::blink() { // ausschalten der LED per Funktion setzt den Status der LED // kurzzeitig auf OFF bis der Status auf BLINK gesetzt wird. turnOff(); setStatus(BLINK); // wiederholtes ein- und auschalten der LED // hier wird manuell geschaltet um den Status nicht immer wieder // ändern zu müssen. for (int i = 0; i < 5; i++) { delay(1000/((getFrequency()*2))); digitalWrite(getPort(), HIGH); delay((1000/(getFrequency()*2))); digitalWrite(getPort(), LOW); } }
void RandomMovementParticleAffector::changed(ConstFieldMaskArg whichField, UInt32 origin, BitVector details) { Inherited::changed(whichField, origin, details); if(whichField & PersistanceFieldMask) { getPerlinDistribution()->setPersistance(getPersistance()); } else if (whichField & FrequencyFieldMask) { getPerlinDistribution()->setFrequency(getFrequency()); } else if (whichField & InterpolationTypeFieldMask) { getPerlinDistribution()->setInterpolationType(getInterpolationType()); } else if (whichField & OctavesFieldMask) { getPerlinDistribution()->setOctaves(getOctaves()); } else if (whichField & AmplitudeFieldMask ) { getPerlinDistribution()->setAmplitude(getAmplitude()); } else if (whichField & PhaseFieldMask ) { getPerlinDistribution()->setPhase(getPhase()[0]); } }
time_t DateRangeDaily::secIn( const DateRange & dateTwo ) const { return( UnionOfDur( getTimeT(), dur, dateTwo.getSecOfDay(), dateTwo.getDur(), getFrequency() ) ); }
void GuitarTuner::initAudioOutput() { m_format_output.setSampleRate(DataFrequencyHzOutput); m_format_output.setCodec("audio/pcm"); m_format_output.setSampleSize(16); m_format_output.setChannelCount(1); m_format_output.setByteOrder(QAudioFormat::LittleEndian); m_format_output.setSampleType(QAudioFormat::SignedInt); QAudioDeviceInfo outputDeviceInfo( QAudioDeviceInfo::defaultOutputDevice()); if (!outputDeviceInfo.isFormatSupported(m_format_output)) { m_format_output = outputDeviceInfo.nearestFormat(m_format_output); } m_audioOutput = new QAudioOutput(outputDeviceInfo, m_format_output, this); m_voicegenerator = new VoiceGenerator(m_format_output, getFrequency(), getVolume(), this); connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(outputStateChanged(QAudio::State))); }
void HighPassFilter2::step(Signal* inout) { sample* samples = inout->samples; sample* f = getFrequency().samples; sample* m = getResonance().samples; const float pi_2 = 3.1415f*2.f; const float te = 1.f/(float)Signal::frequency; const float _2te=te*2.f; for (unsigned int i=0; i<Signal::size;i++) { const float w0=f[i]*pi_2; const float w0te=w0*te; const float w02te=w0*_2te; const float w02te2=w0te*w0te; const float _2mw0te=m[i]*w02te; float a=w02te2+_2mw0te+1.f; a=1.f/a; const float b=_2mw0te+2.f; const float _2_x_1=2*_x_1; const float save_x_1=samples[i]; samples[i]=a*(_y_1*b-_y_2+samples[i]-_2_x_1+_x_2); //std::cout << samples[i]<<std::endl; _y_2=_y_1; _y_1=samples[i]; _x_2=_x_1; _x_1=save_x_1; } }
//------------------------------------------------------------------------------ // transmitDataMessage() -- send a data message emission; // returns true if the data emission was sent. //------------------------------------------------------------------------------ bool CommRadio::transmitDataMessage(base::Object* const msg) { bool sent = false; // Transmitting, scanning and have an antenna? if(getOwnship() == nullptr) { if (isMessageEnabled(MSG_DEBUG)) { std::cout << "CommRadio ownship == nullptr!" << std::endl; } return sent; } if (msg != nullptr && isTransmitterEnabled() && getAntenna() != nullptr) { // Send the emission to the other player Emission* em = new Emission(); em->setDataMessage(msg); em->setFrequency(getFrequency()); em->setBandwidth(getBandwidth()); em->setPower(getPeakPower()); em->setTransmitLoss(getRfTransmitLoss()); em->setMaxRangeNM(getMaxDetectRange()); em->setTransmitter(this); em->setReturnRequest(false); getAntenna()->rfTransmit(em); em->unref(); sent = true; } return sent; }
void PerformanceTimer::Initialize() { timeBeginPeriod(1); InitializeCriticalSection(&TimeCS); MMTimeWrapCounter = 0; getFrequency(); }
bool CDVAPClientModemSet::Validate() { if (m_port->GetCurrentSelection() == wxNOT_FOUND) return false; unsigned int freq = getFrequency(); int n = m_band->GetCurrentSelection(); switch (n) { case 0: if (freq < 144000000U || freq > 148000000U) { wxMessageDialog dialog(this, _("The Frequency is out of range"), m_title + _(" Error"), wxICON_ERROR); dialog.ShowModal(); return false; } break; case 1: if (freq < 420000000U || freq > 450000000U) { wxMessageDialog dialog(this, _("The Frequency is out of range"), m_title + _(" Error"), wxICON_ERROR); dialog.ShowModal(); return false; } break; default: return false; } return true; }
//Format as XML tag for dvdauthor std::string AudioStream::toXml(void) { std::ostringstream xml; xml << "<audio format=\"" << getFormat() << "\" channels=\"" << getChannels() << "\" "; xml << "quant=\"" << getQuantization() << "\" samplerate=\"" << getFrequency() << "\" lang=\"" << getLangCode() << "\"/>"; return xml.str(); }
virtual void process(YSE::SOUND_STATUS & intent) { YSE::DSP::ADSRenvelope::STATE state = YSE::DSP::ADSRenvelope::RESUME; if (intent == YSE::SS_WANTSTOPLAY) { state = YSE::DSP::ADSRenvelope::ATTACK; intent = YSE::SS_PLAYING; releaseRequested = false; } else if (intent == YSE::SS_WANTSTOSTOP && !releaseRequested) { state = YSE::DSP::ADSRenvelope::RELEASE; releaseRequested = true; } out = generator(getFrequency()); out *= envelope(state); out *= 0.25f; if (envelope.isAtEnd()) intent = YSE::SS_STOPPED; for (UInt i = 0; i < buffer.size(); i++) { buffer[i] = out; } }
void BandPassFilter2::step(Signal* inout) { sample* samples = inout->samples; sample* f = getFrequency().samples; sample* m = getResonance().samples; const float pi_2 = 3.1415f*2.f; const float te = 1.f/(float)Signal::frequency; for (unsigned int i=0;i < Signal::size;i++) { const float w0=f[i]*pi_2; const float w0te=w0*te; const float mw0te=w0te*2.f*m[i]; const float w0te2=w0te*w0te; const float d=1.f+mw0te+w0te2; const float a0=mw0te/d; const float b1=(2.f + mw0te)/d; const float b2=1.f/d; const float save_x_1 = samples[i]; const float k=1.f/0.7f; samples[i] = k*a0*samples[i]-k*a0*_x_1+b1*_y_1-b2*_y_2; _y_2 = _y_1; _y_1 = samples[i]; _x_1 = save_x_1; } }
RcppExport SEXP advance2(SEXP calSexp, SEXP param, SEXP dateSexp){ try { boost::shared_ptr<QuantLib::Calendar> pcal( getCalendar(Rcpp::as<std::string>(calSexp)) ); Rcpp::List rparam(param); QuantLib::BusinessDayConvention bdc = getBusinessDayConvention( Rcpp::as<double>(rparam["bdc"]) ); double emr = Rcpp::as<double>(rparam["emr"]); double period = Rcpp::as<double>(rparam["period"]); Rcpp::DateVector dates = Rcpp::DateVector(dateSexp); int n = dates.size(); std::vector<QuantLib::Date> advance(n); for (int i=0; i<n; i++) { QuantLib::Date day( dateFromR(dates[i]) ); advance[i] = pcal->advance(day, QuantLib::Period(getFrequency(period)), bdc, (emr == 1)?true:false ); dates[i] = Rcpp::Date(advance[i].month(), advance[i].dayOfMonth(), advance[i].year()); } return Rcpp::wrap(dates); } catch(std::exception &ex) { forward_exception_to_r(ex); } catch(...) { ::Rf_error("c++ exception (unknown reason)"); } return R_NilValue; }
long DueTimer::getPeriod(void) const { /* Get current time period */ return 1.0/getFrequency()*1000000; }
RcppExport SEXP cfamounts(SEXP params){ SEXP rl=R_NilValue; char* exceptionMesg=NULL; try{ RcppParams rparam(params); QuantLib::Date maturity(dateFromR(rparam.getDateValue("Maturity"))); QuantLib::Date settle(dateFromR(rparam.getDateValue("Settle"))); QuantLib::Date issue(dateFromR(rparam.getDateValue("IssueDate"))); double rate = rparam.getDoubleValue("CouponRate"); std::vector<double> rateVec(1, rate); double faceAmount = rparam.getDoubleValue("Face"); double period = rparam.getDoubleValue("Period"); double basis = rparam.getDoubleValue("Basis"); DayCounter dayCounter = getDayCounter(basis); Frequency freq = getFrequency(period); Period p(freq); double EMR = rparam.getDoubleValue("EMR"); Calendar calendar=UnitedStates(UnitedStates::GovernmentBond); Schedule sch(settle, maturity, p, calendar, Unadjusted, Unadjusted, DateGeneration::Backward, (EMR == 1)? true : false); FixedRateBond bond(1, faceAmount, sch, rateVec, dayCounter, Following, 100, issue); //cashflow int numCol = 2; std::vector<std::string> colNames(numCol); colNames[0] = "Date"; colNames[1] = "Amount"; RcppFrame frame(colNames); Leg bondCashFlow = bond.cashflows(); for (unsigned int i = 0; i< bondCashFlow.size(); i++){ std::vector<ColDatum> row(numCol); Date d = bondCashFlow[i]->date(); row[0].setDateValue(RcppDate(d.month(), d.dayOfMonth(), d.year())); row[1].setDoubleValue(bondCashFlow[i]->amount()); frame.addRow(row); } RcppResultSet rs; rs.add("cashFlow", frame); rl = rs.getReturnList(); } catch(std::exception& ex) { exceptionMesg = copyMessageToR(ex.what()); } catch(...) { exceptionMesg = copyMessageToR("unknown reason"); } if(exceptionMesg != NULL) Rf_error(exceptionMesg); return rl; }
// Returns the number of seconds elapsed since t1 till t2. double deltaTime(TimeType t2, TimeType t1) { TimeType diff; diff.QuadPart = t2.QuadPart - t1.QuadPart; double fdiff = ((double)diff.QuadPart / getFrequency().QuadPart); return fdiff; }
void TurbulenceModule::write (utils::OutStream &s) const { s.writeDouble (mPower); s.writeInt (getRoughness()); s.writeInt (getSeed()); s.writeDouble (getFrequency()); s.writeInt (getQuality()); }
void evgMxc::setFrequency(epicsFloat64 freq) { epicsUInt32 clkSpeed = (epicsUInt32)(getFrequency() * pow(10.0, 6)); epicsUInt32 preScaler = (epicsUInt32)((epicsFloat64)clkSpeed / freq); setPrescaler(preScaler); }
/** Calculate prescale value based on the specified frequency and write it to the device. * @param Frequency in Hz * @see PCA9685_RA_PRE_SCALE */ void PCA9685::setFrequency(float frequency) { sleep(); usleep(10000); uint8_t prescale = roundf(24576000.f / 4096.f / frequency) - 1; I2Cdev::writeByte(devAddr, PCA9685_RA_PRE_SCALE, prescale); this->frequency = getFrequency(); restart(); }
void GuitarTuner::modeChanged(bool isInput) { if (isInput) { m_audioOutput->stop(); m_voicegenerator->stop(); m_analyzer->start(getFrequency()); m_audioInput->start(m_analyzer); } else { m_audioInput->stop(); m_analyzer->stop(); if (m_voicegenerator->frequency() != getFrequency()) { m_voicegenerator->setFrequency(getFrequency()); } m_voicegenerator->start(); m_audioOutput->start(m_voicegenerator); } }
bool rigControl::init() { int retcode; if(!catParams.enableCAT) return false; addToLog(QString("rigcontrol:init myport pathname: %1").arg(myport.pathname),LOGRIGCTRL); catParams.radioModelNumber=getModelNumber(getRadioModelIndex()); my_rig = rig_init(catParams.radioModelNumber); if(!my_rig) { addToLog(QString("Error in connection using radio model %1").arg(catParams.radioModel),LOGALL); initError=QString("Error in connection using radio model %1").arg(catParams.radioModel); return false; } if(QString(my_rig->caps->mfg_name)=="Icom") { if(!catParams.civAddress.isEmpty()) { rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), catParams.civAddress.toLatin1()); } } strncpy(my_rig->state.rigport.pathname,(const char *)catParams.serialPort.toLatin1().data(),FILPATHLEN); strncpy(my_rig->state.pttport.pathname,(const char *)catParams.serialPort.toLatin1().data(),FILPATHLEN); my_rig->state.rigport.parm.serial.rate = catParams.baudrate; my_rig->state.rigport.parm.serial.data_bits=catParams.databits; my_rig->state.rigport.parm.serial.stop_bits=catParams.stopbits; if(catParams.parity=="Even") my_rig->state.rigport.parm.serial.parity= RIG_PARITY_EVEN; else if (catParams.parity=="Odd") my_rig->state.rigport.parm.serial.parity = RIG_PARITY_ODD; else my_rig->state.rigport.parm.serial.parity = RIG_PARITY_NONE; if(catParams.handshake=="XOn/Xoff") my_rig->state.rigport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF; if(catParams.handshake=="Hardware") my_rig->state.rigport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE; else my_rig->state.rigport.parm.serial.handshake = RIG_HANDSHAKE_NONE; my_rig->state.pttport.type.ptt = catParams.pttType; addToLog(QString("rigcontrol:init rigport.pathname: %1").arg(my_rig->state.rigport.pathname),LOGRIGCTRL); retcode = rig_open(my_rig); if (retcode != RIG_OK ) { addToLog(QString("CAT Error: %1").arg(QString(rigerror(retcode))),LOGALL); initError=QString("CAT Error: %1").arg(QString(rigerror(retcode))); return false; } addToLog("rigcontroller successfully opened",LOGRIGCTRL); rigControlEnabled=true; // int verbose=0; // rig_set_debug(verbose<2 ? RIG_DEBUG_NONE: (rig_debug_level_e)verbose); // rig_debug(RIG_DEBUG_VERBOSE, "rigctl, %s\n", hamlib_version); // test if we can contact the tranceiver double fr; if(!getFrequency(fr)) { // rigControlEnabled=false; } return true; }
std::vector<unsigned char> Compressor::compress(void* data, unsigned length) { mFrequency = getFrequency(data, length); int bits = getBestRatio(length); char* ptr = (char*)data; int i; if (bits == -1) return std::vector<unsigned char>(); BitStream bs; unsigned totalSize = 27 + ((1 << bits) - 1) * 8; if (mIsLittleEndian) bs.insert((int)length, 24); else bs.insert(reverseEndianess((int)length), 24); bs.insert(bits, 3); for (i = 0; i < (1 << bits) - 1; i++) { if ((int)mFrequency.size() > i) bs.insert(mFrequency[i].character); else bs.insert(0); } std::vector<char> uncompressed; for (i = 0; i < (int)length; i++) { int vecPos = findChar(mFrequency, *ptr, (1 << bits) - 1); if (vecPos == -1) { bs.insert(0U, bits); uncompressed.push_back(*ptr); } else { bs.insert(vecPos + 1, bits); } totalSize += bits; ptr++; } for (i = 0; i < (int)uncompressed.size(); i++) { bs.insert(uncompressed[i]); totalSize += 8; } return bs.getData(); }
bool TurbulenceParticleAffector::distributionIsNotInitialized(void) { PerlinNoiseDistribution1DRefPtr dist(getPerlinDistribution()); return (1.0f != getAmplitude() || dist->getPersistance() != getPersistance() || dist->getOctaves() != getOctaves() || dist->getInterpolationType() != getInterpolationType() || dist->getFrequency() != getFrequency()); }
std::string Note::toString() const { std::stringstream stream; stream << "Note number: " << getNumber() << " "; stream << "name: " << getName(true) << " "; if ( getName(true)!=getName(false) ) stream << "(or " << getName(false) << ") "; stream << "frequency: " << getFrequency() << " "; stream << std::endl; return stream.str(); }