Exemplo n.º 1
0
void SweepSettings::setSpan(Frequency f)
{
    if(f < device_traits::min_span()) {
        f = device_traits::min_span();
    }

    if(Mode() == MODE_REAL_TIME) {
        bb_lib::clamp(f, Frequency(device_traits::min_real_time_span()),
                      Frequency(device_traits::max_real_time_span()));
    }

    // Fit new span to device freq range
    if((center - f / 2.0) < device_traits::min_frequency()) {
        start = device_traits::min_frequency();
        stop = bb_lib::min2((start + f).Val(), device_traits::max_frequency());
    } else if((center + f / 2.0) > device_traits::max_frequency()) {
        stop = device_traits::max_frequency();
        start = bb_lib::max2((stop - f).Val(), device_traits::min_frequency());
    } else {
        start = center - f / 2.0;
        stop = center + f / 2.0;
    }

    center = (start + stop) / 2.0;
    span = stop - start;

    AutoBandwidthAdjust(false);
    UpdateProgram();
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// Purpose: Calculates the physics shake values
//-----------------------------------------------------------------------------
void CASWEnvShake::Think( void )
{
	int i;

	if ( gpGlobals->curtime > m_nextShake )
	{
		// Higher frequency means we recalc the extents more often and perturb the display again
		m_nextShake = gpGlobals->curtime + (1.0f / Frequency());

		// Compute random shake extents (the shake will settle down from this)
		for (i = 0; i < 2; i++ )
		{
			m_maxForce[i] = random->RandomFloat( -1, 1 );
		}
		// make the force it point mostly up
		m_maxForce.z = 4;
		VectorNormalize( m_maxForce );
		m_maxForce *= m_currentAmp * 400;	// amplitude is the acceleration of a 100kg object
	}

	float fraction = ( m_stopTime - gpGlobals->curtime ) / Duration();

	if ( fraction < 0 )
	{
		m_pShakeController->ClearObjects();
		return;
	}

	float freq = 0;
	// Ramp up frequency over duration
	if ( fraction )
	{
		freq = (Frequency() / fraction);
	}

	// square fraction to approach zero more quickly
	fraction *= fraction;

	// Sine wave that slowly settles to zero
	fraction = fraction * sin( gpGlobals->curtime * freq );

	// Add to view origin
	for ( i = 0; i < 3; i++ )
	{
		// store the force in the controller callback
		m_shakeCallback.m_force[i] = m_maxForce[i] * fraction;
	}

	// Drop amplitude a bit, less for higher frequency shakes
	m_currentAmp -= m_currentAmp * ( gpGlobals->frametime / (Duration() * Frequency()) );
	SetNextThink( gpGlobals->curtime );
}
Exemplo n.º 3
0
RfProfileData DomainRfProfileStatus_001::getRfProfileData(UIntN participantIndex, UIntN domainIndex)
{
    // FIXME:  can this be cached?  If so how do we know when the data changes?

    // if center frequency isn't available the error will get thrown back to the policy

    Frequency centerFrequency = getParticipantServices()->primitiveExecuteGetAsFrequency(
        esif_primitive_type::GET_RFPROFILE_CENTER_FREQUENCY, domainIndex);

    RfProfileSupplementalData rfProfileSupplementalData(0, 0, 0, 0, RadioConnectionStatus::NotConnected, 0);
    RfProfileData rfProfileData(centerFrequency, Frequency(0), Frequency(0), rfProfileSupplementalData);

    return rfProfileData;
}
Exemplo n.º 4
0
bool RNGTester::Test(unsigned char *eps, int n)
{
  double p_value = 1.0 ;

  std::cout << std::fixed << std::setprecision(6) ;

  p_value = std::min(p_value, Frequency(n, eps) ) ;
  p_value = std::min(p_value, BlockFrequency(n/100, n, eps) ) ;
  p_value = std::min(p_value, Runs(n, eps) ) ;
  p_value = std::min(p_value, LongestRunOfOnes(n, eps) ) ;
  //p_value = std::min(p_value, Rank(n, eps) ) ;
  //p_value = std::min(p_value, DiscreteFourierTransform(n, eps) ) ;
  //p_value = std::min(p_value, NonOverlappingTemplateMatchings(10, n, eps) ) ;
  //p_value = std::min(p_value, OverlappingTemplateMatchings(10, n, eps) ) ;
  p_value = std::min(p_value, Universal(n, eps) ) ;
  p_value = std::min(p_value, LinearComplexity(1000, n, eps) ) ;
  p_value = std::min(p_value, Serial(5, n, eps) ) ;
  //p_value = std::min(p_value, ApproximateEntropy(5, n, eps) ) ;
  p_value = std::min(p_value, CumulativeSums(n, eps) ) ;
  //p_value = std::min(p_value, RandomExcursions(n, eps) ) ;
  //p_value = std::min(p_value, RandomExcursionsVariant(n, eps) ) ;

  std::cout << "p_value = " << p_value << std::endl ;

  return (p_value>=0.01) ; 
}
Exemplo n.º 5
0
int main(void)
{
  for(int i=0;i<MY_N;i++)
  {
    scanf("%c", &eps[i]) ;
    eps[i] -= '0' ;
    if(eps[i]!=0 && eps[i]!=1) i-- ;
  }
  //for(int i=0;i<MY_N;i++) eps[i] = rand()%2 ;
  
  std::cout << Frequency(MY_N, eps) << std::endl ;
  std::cout << BlockFrequency(MY_N/100, MY_N, eps) << std::endl ;
  std::cout << Runs(MY_N, eps) << std::endl ;
  std::cout << LongestRunOfOnes(MY_N, eps) << std::endl ;
  //std::cout << Rank(MY_N, eps) << std::endl ;
  //std::cout << DiscreteFourierTransform(MY_N, eps) << std::endl ;
  //std::cout << NonOverlappingTemplateMatchings(10, MY_N, eps) << std::endl ;
  //std::cout << OverlappingTemplateMatchings(10, MY_N, eps) << std::endl ;
  std::cout << Universal(MY_N, eps) << std::endl ;
  std::cout << LinearComplexity(1000, MY_N, eps) << std::endl ;
  std::cout << Serial(5, MY_N, eps) << std::endl ;
  //std::cout << ApproximateEntropy(5, MY_N, eps) << std::endl ;
  std::cout << CumulativeSums(MY_N, eps) << std::endl ;
  //std::cout << RandomExcursions(MY_N, eps) << std::endl ;
  //std::cout << RandomExcursionsVariant(MY_N, eps) << std::endl ;

  return 0 ;
}
Exemplo n.º 6
0
void Localizer::getFrequency() {
    // Get frequency
    int rawFrequency;
    XPLMGetNavAidInfo(ref_, nullptr, nullptr, nullptr, nullptr, &rawFrequency, &heading_, nullptr, nullptr, nullptr);

    frequency_ = Frequency(rawFrequency * 10000);
}
Exemplo n.º 7
0
	/**
	 *  @alsymbols
	 *  @alfunref{GetBuffer}
	 *  @aldefref{SIZE}
	 *  @aldefref{FREQUENCY}
	 *  @aldefref{BITS}
	 *  @aldefref{CHANNELS}
	 */
	ALfloat Duration(void) const
	{
		ALfloat s = Size();
		ALfloat f = Frequency();
		ALfloat b = Bits()/8.0f;
		ALfloat c = Channels();
		ALfloat bps = f*b*c;
		return bps>0.0f?ALfloat(s/bps):ALfloat(0);
	}
Exemplo n.º 8
0
/* constructor trains learning algorithm with TRAINING_DATA */
NBClassifier::NBClassifier(DatasetDescription::PtrConst training_data,
                           EstMode _mode) :
  Classifier(training_data, kDomainSize, kRangeSize)
{
  FrequencyTable::Ptr freq_table;
  JointDistTable::Ptr joint_dist_table;
  Observation in_value, out_value;

  /* generating joint probability distribution tables for each variable */
  for (uint32_t var = 0; var < training_data_->varCount(); ++var) {
    /* creating frequency table for single variable;
       if MODE is equal to laplace, initialize frequency table values to 1
       rather than to 0 */
    Frequency init_freq = (_mode == kLaplace) ? Frequency(1) : Frequency(0);
    freq_table = FrequencyTable::FrequencyTableNew(domain_size_, range_size_,
                                                   init_freq);

    /* populating frequency table by tracking
       occurences throughout every data vector */
    DataInstance::PtrConst instance;
    for (uint32_t vec = 0; vec < training_data_->vectorCount(); ++vec) {
      instance = training_data_->instance(vec);

      in_value = instance->inputObservation(var);
      out_value = instance->outputObservation();

      /* incrementing frequency at coorditates
         (in_value, out_value) of frequency table */
      freq_table->frequencyInc(in_value.value(), out_value.value());
    }

    /* converting frequency table into a joint probability distribution table */
    joint_dist_table = JointDistTable::JointDistTableNew(freq_table);

    /* adding distribution table to model */
    joint_dist_.pushBack(joint_dist_table);
  }

  /* populating vector of output marginal probabilities, P(Y);
     all joint probability distribution tables should have the same P(Y) */
  for (uint32_t out_idx = 0; out_idx < range_size_; ++out_idx)
    out_marginal_.pushBack(joint_dist_[0]->outputMarginal(out_idx));
}
Exemplo n.º 9
0
void SweepSettings::setMode(OperationalMode new_mode)
{
    mode = new_mode;
    double maxRealTimeSpan = device_traits::max_real_time_span();

    if(mode == BB_REAL_TIME) {
        native_rbw = device_traits::has_native_bandwidths();
        //auto_rbw = true;
        auto_vbw = true;
        if(bb_lib::clamp(span, Frequency(device_traits::min_real_time_span()),
                         Frequency(device_traits::max_real_time_span()))) {
            start = center - (maxRealTimeSpan / 2.0);
            stop = center + (maxRealTimeSpan / 2.0);
        }

        AutoBandwidthAdjust(/*true*/false);
    }

    UpdateProgram();
}
Exemplo n.º 10
0
void Clock::Reset() {
	mFrequency = Frequency();
	mTotalTime = 0.0;
	mElapsedTime = 0.0;
	GetTime(mStartTime);
	mCurrentTime = mStartTime;
	mLastTime = mCurrentTime;
	mFrameCount = 0;
	mFrameRate = 0;
	mLastTotalElapsedTime = 0.0;
}
void
nist_test_suite()
{
	if ( (testVector[0] == 1) || (testVector[TEST_FREQUENCY] == 1) ) 
		Frequency(tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_BLOCK_FREQUENCY] == 1) ) 
		BlockFrequency(tp.blockFrequencyBlockLength, tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_CUSUM] == 1) )
		CumulativeSums(tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_RUNS] == 1) )
		Runs(tp.n); 
	
	if ( (testVector[0] == 1) || (testVector[TEST_LONGEST_RUN] == 1) )
		LongestRunOfOnes(tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_RANK] == 1) )
		Rank(tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_FFT] == 1) )
		DiscreteFourierTransform(tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_NONPERIODIC] == 1) )
		NonOverlappingTemplateMatchings(tp.nonOverlappingTemplateBlockLength, tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_OVERLAPPING] == 1) )
		OverlappingTemplateMatchings(tp.overlappingTemplateBlockLength, tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_UNIVERSAL] == 1) )
		Universal(tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_APEN] == 1) )
		ApproximateEntropy(tp.approximateEntropyBlockLength, tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_RND_EXCURSION] == 1) )
		RandomExcursions(tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_RND_EXCURSION_VAR] == 1) )
		RandomExcursionsVariant(tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_SERIAL] == 1) )
		Serial(tp.serialBlockLength,tp.n);
	
	if ( (testVector[0] == 1) || (testVector[TEST_LINEARCOMPLEXITY] == 1) )
		LinearComplexity(tp.linearComplexitySequenceLength, tp.n);

	if ( (testVector[0] == 1) || (testVector[TEST_FFT80] == 1) )
		DiscreteFourierTransform80(tp.n);
}
Exemplo n.º 12
0
    Frequency Period::frequency() const {
        // unsigned version
        Size length = std::abs(length_);

        if (length==0) {
            if (units_==Years) return Once;
            return NoFrequency;
        }

        switch (units_) {
          case Years:
            if (length == 1)
                return Annual;
            else
                return OtherFrequency;
          case Months:
            if (12%length == 0 && length <= 12)
                return Frequency(12/length);
            else
                return OtherFrequency;
          case Weeks:
            if (length==1)
                return Weekly;
            else if (length==2)
                return Biweekly;
            else if (length==4)
                return EveryFourthWeek;
            else
                return OtherFrequency;
          case Days:
            if (length==1)
                return Daily;
            else
                return OtherFrequency;
          default:
            QL_FAIL("unknown time unit (" << Integer(units_) << ")");
        }
    }
Exemplo n.º 13
0
bool HSNote::Attack(const MusicDeviceNoteParams &inParams)
{
    HSPad* hsp = (HSPad*) GetAudioUnit();
    wavetable = hsp->getWavetable();
    float freq = Frequency()*(1-GetGlobalParameter(kParameter_TouchSensitivity)*pow(inParams.mVelocity/127., 2.));
    wavetable_idx = wavetable->closestMatchingWavetable(freq);
    wavetable_num_samples = wavetable->getNumSamples();
    wavetable_sample_rate = wavetable->getSampleRate();

    double sampleRate = SampleRate();
    phase = (rand()/(RAND_MAX+1.0))*wavetable_num_samples;
    amp = 0.;
    maxamp = 0.4 * pow(inParams.mVelocity/127., 2.);

    float at = GetGlobalParameter(kParameter_AttackTime);
    // If at is 0, we set up_slope to maxamp/50. That is big enough to start the note
    // seemingly immediately, yet avoiding an ugly chipping sound that comes if you set
    // it to maxamp.
    up_slope = maxamp / (at==0.0?50.0:(at/1000.0 * sampleRate));

    float rt = GetGlobalParameter(kParameter_ReleaseTime);
    if (rt == 0) {
        // This is not 0, because that makes an ugly chipping sound when the note
        // is released. 0.99 is small enough to stop the note seemingly immediately
        dn_slope = 0.99;
    }
    else {
        double num_frames = rt/1000.0 * sampleRate;
        double off_threshold = 0.01; // 20dB
        dn_slope = pow(off_threshold, (double)1.0/num_frames);
    }

    fast_dn_slope = -maxamp / (0.005 * sampleRate);

    return true;
}
Exemplo n.º 14
0
 Frequency frequency() const {
     return freqMakesSense_ ? Frequency(Integer(freq_)) : NoFrequency;
 }
Exemplo n.º 15
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CASWEnvShake::ApplyShake( ShakeCommand_t command )
{
	if ( !HasSpawnFlags( SF_ASW_SHAKE_NO_VIEW ) )
	{
		bool air = (GetSpawnFlags() & SF_ASW_SHAKE_INAIR) ? true : false;
		UTIL_ASW_ScreenShake( GetAbsOrigin(), Amplitude(), Frequency(), Duration(), Radius(), command, air );
	}
		
	if ( GetSpawnFlags() & SF_ASW_SHAKE_ROPES )
	{
		CRopeKeyframe::ShakeRopes( GetAbsOrigin(), Radius(), Frequency() );
	}

	if ( GetSpawnFlags() & SF_ASW_SHAKE_PHYSICS )
	{
		if ( !m_pShakeController )
		{
			m_pShakeController = physenv->CreateMotionController( &m_shakeCallback );
		}
		// do physics shake
		switch( command )
		{
		case SHAKE_START:
			{
				m_stopTime = gpGlobals->curtime + Duration();
				m_nextShake = 0;
				m_pShakeController->ClearObjects();
				SetNextThink( gpGlobals->curtime );
				m_currentAmp = Amplitude();
				CBaseEntity *list[1024];
				float radius = Radius();
				
				// probably checked "Shake Everywhere" do a big radius
				if ( !radius )
				{
					radius = MAX_COORD_INTEGER;
				}
				Vector extents = Vector(radius, radius, radius);
				Vector mins = GetAbsOrigin() - extents;
				Vector maxs = GetAbsOrigin() + extents;
				int count = UTIL_EntitiesInBox( list, 1024, mins, maxs, 0 );

				for ( int i = 0; i < count; i++ )
				{
					//
					// Only shake physics entities that players can see. This is one frame out of date
					// so it's possible that we could miss objects if a player changed PVS this frame.
					//
					if ( ( list[i]->GetMoveType() == MOVETYPE_VPHYSICS ) )
					{
						IPhysicsObject *pPhys = list[i]->VPhysicsGetObject();
						if ( pPhys && pPhys->IsMoveable() )
						{
							m_pShakeController->AttachObject( pPhys, false );
							pPhys->Wake();
						}
					}
				}
			}
			break;
		case SHAKE_STOP:
			m_pShakeController->ClearObjects();
			break;
		case SHAKE_AMPLITUDE:
			m_currentAmp = Amplitude();
		case SHAKE_FREQUENCY:
			m_pShakeController->WakeObjects();
			break;
		}
	}
}
Exemplo n.º 16
0
void DRP2FD(SCAN *s, XSCAN *x, FDATA *fd)
{
    int i, odin=0;
    double *pa, cp, sp, sqrBt;
#ifdef SISYFOS
    int arr_no=0;
    double NorthAz, RAOffset, DecOffset;
#endif
#ifdef ONTHEFLY
    double NorthAz, RAOffset, DecOffset;
#endif
    
    double *CheckPosAngle();
    void SetCoordType();
    int CheckCRVALType();
    void GetEquOffsets(DATE *, double, double, double, double, double, double,
                       double *, double *);
    
    if (strncmp(s->Project, "Odin", 4)==0) odin=1;
    
    strncpy(fd->sname, s->Name, 12);
    fd->sname[12] = '\0';
    strip_trailing_spaces(fd->sname);
    strncpy(fd->molecule, s->Molecule, 18);
    fd->molecule[18] = '\0';
    strip_trailing_spaces(fd->molecule);
    fd->n = (int)x->NChannel;
    fd->sno = (int)s->ScanNo;
    fd->subno = (int)s->SubScan;
    fd->coordType = s->CSystem;
    SetCoordType(s->CSystem);
    if ((pa = CheckPosAngle()))
        fd->posang = (*pa)*PI/180.0;
    else
        fd->posang = (double)s->PosAngle;
    cp = cos(fd->posang);
    sp = sin(fd->posang);
    fd->xoff = rta(s->LMapOff)*cp - rta(s->BMapOff)*sp;
    fd->yoff = rta(s->BMapOff)*cp + rta(s->LMapOff)*sp;
    fd->equinox = s->Equinox;
    if (fd->equinox <= 1950.1) {
        fd->epoch = 'B';
    } else {
        fd->epoch = 'J';
    }
    fd->y0 = s->Latitude;
    fd->x0 = s->Longitude;
    if (CheckCRVALType()) {
        fd->y0 -= s->BMapOff;
        fd->x0 -= s->LMapOff/cos(fd->y0);
    }
    fd->scanType = s->ObsMode;
    fd->tsys = (double)s->Tsys;
    fd->tau  = (double)s->Tau;
    fd->int_time = (double)s->IntTime;
    fd->vlsr = s->VSource;
    fd->date.Year  = s->Year;
    fd->date.Month = s->Month;
    fd->date.Day   = s->Day;
    fd->date.Hour  = s->UTHour;
    fd->date.Min   = s->UTMin;
    fd->date.Sec   = s->UTSec;
    fd->LST = fd->date;
    fd->LST.Hour   = s->STHour;
    fd->LST.Min    = s->STMin;
    fd->LST.Sec    = s->STSec;
    fd->az = s->Azimuth * RADTODEG;
    fd->el = s->Elevation * RADTODEG;
    fd->aoff = rta(s->AzMapOff)*cp - rta(s->ElMapOff)*sp;
    fd->eoff = rta(s->ElMapOff)*cp + rta(s->AzMapOff)*sp;
#ifdef SISYFOS
    if (sscanf(s->Program, "COR%d", &arr_no) == 1) {
        if (arr_no >=1 && arr_no <= 4) {
            fd->aoff += (SisyfosAz[arr_no] - SisyfosAz[0]);
            fd->eoff += (SisyfosEl[arr_no] - SisyfosEl[0]);
            NorthAz = s->Azimuth + PI;
            GetEquOffsets(&(fd->LST), NorthAz, s->Elevation,
                          fd->aoff, fd->eoff,
                          s->Longitude, s->Latitude,
                          &RAOffset, &DecOffset);
            fd->xoff += RAOffset;
            fd->yoff += DecOffset;
        }
    }
#endif
#ifdef ONTHEFLY
    NorthAz = s->Azimuth + PI;
    GetEquOffsets(&(fd->LST), NorthAz, s->Elevation,
                  fd->aoff, fd->eoff,
                  s->Longitude, s->Latitude,
                  &RAOffset, &DecOffset);
    fd->xoff += RAOffset;
    fd->yoff += DecOffset;
#endif
    fd->b.maj = s->StepX;
    fd->b.min = s->StepY;
    fd->b.PA  = s->ParAngle;
    fd->beameff = s->RefCorr;
    fd->pol     = s->flag[0];
    fd->TAir = s->AirTemp; 
    fd->PAir = s->Pressure; 
    fd->RAir = s->Humidity; 
    
    fd->firstIF = s->FirstIF/1000.0;
    if (x) {
        fd->lofreq = x->LOFreq/1000.0;
    } else { /* Assume OSO */
        if (s->RestFreq < 105000.0) {
            fd->lofreq = (s->RestFreq + s->FirstIF)/1000.0;
	} else {
            fd->lofreq = (s->RestFreq - s->FirstIF)/1000.0;
	}
    }
    fd->skyfreq = s->SkyFreq/1000.0;
    
    if (s->FreqRes < 0.0) {
        fd->f0 = Frequency(x->NChannel-1, s, x)/1000.;
        fd->fn = Frequency(0, s, x)/1000.;
/*         printf("f0, fn=%f,%f  RF=%f  res=%f\n", fd->f0, fd->fn, s->RestFreq, s->FreqRes);
 */
        if (odin) {
            fd->v0 = VelOdin(x->NChannel-1, s, x);
        } else {
            fd->v0 = Velocity(x->NChannel-1, s, x);
        }
        fd->fres = -s->FreqRes;
        fd->vres = -s->VelRes;
        sqrBt = sqrt(fabs(fd->fres) * fd->int_time)*1000.0;
        for (i=x->NChannel-1; i>=0; i--) {
            fd->d[x->NChannel-1-i] = (double)(s->c[i]);
            if (sqrBt > 0.0 && fd->tsys > 0.0)
                fd->e[x->NChannel-1-i] = 2.0*fd->tsys/sqrBt;
            else
                fd->e[x->NChannel-1-i] = 1.0;
        }
    } else {
        fd->fn = Frequency(x->NChannel-1, s, x)/1000.;
        fd->f0 = Frequency(0, s, x)/1000.;
        if (odin) {
            fd->v0 = VelOdin(0, s, x);
        } else {
            fd->v0 = Velocity(0, s, x);
        }
        fd->fres = s->FreqRes;
        fd->vres = s->VelRes;
        sqrBt = sqrt(fabs(fd->fres) * fd->int_time)*1000.0;
        for (i=0; i<x->NChannel; i++) {
          fd->d[i] = (double)(s->c[i]);
          if (sqrBt > 0.0 && fd->tsys > 0.0)
              fd->e[i] = 2.0*fd->tsys/sqrBt;
          else
              fd->e[i] = 1.0;
        }
    }
}
Exemplo n.º 17
0
void CShake::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	UTIL_ScreenShake( pev->origin, Amplitude(), Frequency(), Duration(), Radius() );
}
Exemplo n.º 18
0
	GameTime::GameTime(void)
	{
		this->frequency = Frequency();
		this->startTime = Counter();
		this->lastTime = this->startTime;
	}
Exemplo n.º 19
0
    Frequency Frequency::ofMidiNote( float midiNote )
    {
        float hz = HZA4*powf( 2.0f, ( midiNote - MIDIA4 )/MIDIOCTAVE );
		return Frequency(hz);
    }
Exemplo n.º 20
0
	Frequency Frequency::ofHertz( float hz )
	{
		return Frequency(hz);
	}
Exemplo n.º 21
0
void MeasuringReceiver::ProcessThread()
{
    IQCapture capture;
    double center, power, relative, offset;
    std::list<double> average;
    std::vector<complex_f> full;

    while(running) {
        // Reinitialize to start tuned level measurements over
        if(reinitialize) {
            ampGroup->button(0)->setChecked(true); // Select high power
            emit updateRangeEnabled(rangeLevelNone);
            power = 0.0;
            offset = 0.0;
            relative = 0.0;
            reinitialize = false;
            recalibrate = true;
        }

        // Recalibrates to a new range
        // Range must be chosen before entering this block
        if(recalibrate) {
            offset += (power - relative);
            Recalibrate(center, power, capture);
            relative = power;
            full.resize(descriptor.returnLen * 3);
            average.clear();
        }

        device->GetIQFlush(&capture, true);
        simdCopy_32fc(&capture.capture[0], &full[0], descriptor.returnLen);
        for(int i = 1; i < 3; i++) {
            device->GetIQ(&capture);
            simdCopy_32fc(&capture.capture[0], &full[i * descriptor.returnLen], descriptor.returnLen);
        }
        getPeakCorrelation(&full[0], descriptor.returnLen*3, center, center, power, descriptor.sampleRate);
        std::cout << "Post center " << center << " " << power << "\n";

        if(device->ADCOverflow()) {
            emit updateRangeLevelText("IF Overload", rangeColorRed);
        } else {
            if(GetCurrentRange() == MeasRcvrRangeHigh) {
                if(power > -25.0) {
                    emit updateRangeLevelText("", rangeColorBlack);
                    emit updateRangeEnabled(rangeLevelNone);
                } else if(power < -40.0) {
                    emit updateRangeLevelText(MeasRcvrRangeMid, "Passed Mid-Range", rangeColorRed);
                    emit updateRangeEnabled(rangeLevelNone);
                } else {
                    emit updateRangeLevelText(MeasRcvrRangeMid, "Recal at new range", rangeColorOrange);
                    emit updateRangeEnabled(MeasRcvrRangeMid);
                }
            } else if(GetCurrentRange() == MeasRcvrRangeMid) {
                if(power > -50.0) {
                    emit updateRangeLevelText("", rangeColorBlack);
                    emit updateRangeEnabled(rangeLevelNone);
                } else if(power < -65.0) {
                    emit updateRangeLevelText(MeasRcvrRangeLow, "Passed Low-Range", rangeColorRed);
                    emit updateRangeEnabled(rangeLevelNone);
                } else {
                    emit updateRangeLevelText(MeasRcvrRangeLow, "Recal at new range", rangeColorOrange);
                    emit updateRangeEnabled(MeasRcvrRangeLow);
                }
            } else {
                emit updateRangeLevelText("", rangeColorBlack);
                emit updateRangeEnabled(rangeLevelNone);
            }
        }

        // Lets update our text
        double diff = (power - relative) + offset;
        average.push_front(diff);
        while(average.size() > 20) average.pop_back();
        double avgPower = 0.0;
        for(double d : average) avgPower += d;
        avgPower /= average.size();

        QString centerStr, powerStr, relativeStr, averageStr;
        centerStr = Frequency(freqEntry->GetFrequency() +
                              center * descriptor.sampleRate/*312500.0*/).GetFreqString();
        powerStr.sprintf("%.3f dBm", power);
        relativeStr.sprintf("%.3f dB", diff);
        averageStr.sprintf("%.3f dB", avgPower);

        emit updateLabels(centerStr, powerStr, relativeStr, averageStr);
    }

    device->Abort();
}
Exemplo n.º 22
0
int main()
{
    word16 x=1111; // nombre entre 1000 et 9999 pour Von Neumann
    struct mt19937p mt; // Pour Mersenne-Twister
    int tmp = rand(); // Pour Mersenne-Twister
    u32 Kx[NK], Kex[NB*NR], Px[NB]; // pour l'AES

    int n = 1024; // Echantillon de test

    int * output_rand = malloc(sizeof(int)*n); // sortie du rand du C
    int ** output_rand_fort = malloc(sizeof(sizeof(int)*4)*n); // sortie du rand du C	(4 bits poids fort)
    int ** output_rand_faible = malloc(sizeof(sizeof(int)*4)*n); // sortie du rand du C (4 bits poids faible)

    word32 * output_AES = malloc(sizeof(word32)*n); // sortie pour l'AES
    word16 * output_VN = malloc(sizeof(word16)*n); // sortie pour pour Von Neumann
    word32 * output_MT = malloc(sizeof(word32)*n); // sortie pour Mersenne-Twister


    // initialisation des graines des generateurs
    srand(rdtsc());  // rand du C
    sgenrand(time(NULL)+(tmp), &mt); // Mersenne-Twister
    // Initialisation de la clé et du plaintext pour l'AES
    // 45 est un paramètre qui doit changer à chaque initialisation
    init_rand(Kx, Px, NK, NB, 45);
    KeyExpansion(Kex,Kx); // AES : sous-clefs


    for(int i = 0; i < n; i++)
    {
        // sorties des generateurs
        output_rand[i] = rand(); // rand du C
        int* tempBin = convertBin(output_rand[i], taille_int);
        output_rand_fort[i] = extractBit(tempBin, 1, taille_int);
        output_rand_faible[i] = extractBit(tempBin, 0, taille_int);

        for(int j = 0; j < 4; j++)
        {
            if(!(tempBin[taille_int-1-j] == output_rand_faible[3-j]))
            {
                printf("PAS OK !!!!");
            }
        }


        output_VN[i] = Von_Neumann(&x); // Von Neumann
        output_MT[i] = genrand(&mt); // Mersenne-Twister
        output_AES[i] = AES(Px, Kex); // AES
    }

    // affichage

    /*printf("- Generation de nombres aleatoires -\n");
    printf("rand du C (poids fort) :\n");
    for(int i = 0; i < n; i++)
    {
    	checkBin(output_rand_fort[i], 4);
    }
    /*printf("rand du C (poids faible) :\n");
    for(int i = 0; i < n; i++)
    {
    	displayBinToDec(output_rand_faible[i],4);
    }
    printf("Von Neumann : \n");
    displayValuesWord16(output_VN, n);
    printf("Mersenne Twister : \n");
    displayValuesWord32(output_MT, n);
    printf("AES : \n");
    displayValuesWord32(output_AES, n);
    */
    // tests
    double testFreq_randFort = Frequency(output_rand_fort, n, 4);
    //double testFreq_randFaible = Frequency(output_rand_faible, n, 4);
    /*double testFreq_aes = Frequency(makeArrayWord32(output_AES,n), n, 32);
    double testFreq_VN = Frequency(makeArrayWord16(output_VN,n), n, 16);
    double testFreq_MT = Frequency(makeArrayWord32(output_MT,n), n, 32);

    printf("PValeurs : \n \
    Rand Bits Poids Fort : %lf\n \
    Rand Bits Poids Faible : %lf\n \
    AES : %lf\n \
    VN : %lf\n \
    MT : %lf\n",testFreq_randFort,testFreq_randFaible,testFreq_aes,testFreq_VN,testFreq_MT);*/
    return 0;
}
Exemplo n.º 23
0
 /// Constructor
 HammingData(boost::string_ref word) {
     freq=Frequency(word);
     coefficient=freq.getCoefficient();
 }
Exemplo n.º 24
0
OSStatus		TestNote::Render(UInt64 inAbsoluteSampleFrame, UInt32 inNumFrames, AudioBufferList** inBufferList, UInt32 inOutBusCount)
{
	float *left, *right;
    /* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
     Changes to this parameter (kGlobalVolumeParam) are not being de-zippered;
     Left as an exercise for the reader
     ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
	float globalVol = GetGlobalParameter(kGlobalVolumeParam);
	
	// TestNote only writes into the first bus regardless of what is handed to us.
	const int bus0 = 0;
	int numChans = inBufferList[bus0]->mNumberBuffers;
	if (numChans > 2) return -1;
	
	left = (float*)inBufferList[bus0]->mBuffers[0].mData;
	right = numChans == 2 ? (float*)inBufferList[bus0]->mBuffers[1].mData : 0;
    
	double sampleRate = SampleRate();
	double freq = Frequency() * (twopi/sampleRate);
    
	
#if DEBUG_PRINT_RENDER
	printf("TestNote::Render %p %d %g %g\n", this, GetState(), phase, amp);
#endif
	switch (GetState())
	{
		case kNoteState_Attacked :
		case kNoteState_Sostenutoed :
		case kNoteState_ReleasedButSostenutoed :
		case kNoteState_ReleasedButSustained :
        {
            for (UInt32 frame=0; frame<inNumFrames; ++frame)
            {
                if (amp < maxamp) amp += up_slope;
                float out = pow5(sin(phase)) * amp * globalVol;
                phase += freq;
                if (phase > twopi) phase -= twopi;
                left[frame] += out;
                if (right) right[frame] += out;
            }
        }
			break;
			
		case kNoteState_Released :
        {
            UInt32 endFrame = 0xFFFFFFFF;
            for (UInt32 frame=0; frame<inNumFrames; ++frame)
            {
                if (amp > 0.0) amp += dn_slope;
                else if (endFrame == 0xFFFFFFFF) endFrame = frame;
                float out = pow5(sin(phase)) * amp * globalVol;
                phase += freq;
                left[frame] += out;
                if (right) right[frame] += out;
            }
            if (endFrame != 0xFFFFFFFF) {
#if DEBUG_PRINT
                printf("TestNote::NoteEnded  %p %d %g %g\n", this, GetState(), phase, amp);
#endif
                NoteEnded(endFrame);
            }
        }
			break;
			
		case kNoteState_FastReleased :
        {
            UInt32 endFrame = 0xFFFFFFFF;
            for (UInt32 frame=0; frame<inNumFrames; ++frame)
            {
                if (amp > 0.0) amp += fast_dn_slope;
                else if (endFrame == 0xFFFFFFFF) endFrame = frame;
                float out = pow5(sin(phase)) * amp * globalVol;
                phase += freq;
                left[frame] += out;
                if (right) right[frame] += out;
            }
            if (endFrame != 0xFFFFFFFF) {
#if DEBUG_PRINT
                printf("TestNote::NoteEnded  %p %d %g %g\n", this, GetState(), phase, amp);
#endif
                NoteEnded(endFrame);
            }
        }
			break;
		default :
			break;
	}
	return noErr;
}
Exemplo n.º 25
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	HSPad::Render
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OSStatus		HSNote::Render(UInt64 inAbsoluteSampleFrame, UInt32 inNumFrames, AudioBufferList** inBufferList, UInt32 inOutBusCount)
{
    // TestNote only writes into the first bus regardless of what is handed to us.
    const int bus0 = 0;
    AudioBufferList* inBuffer = inBufferList[bus0];

    int numChans = inBuffer->mNumberBuffers;
    if (numChans > 2) return -1;

    float volumeFactor = pow(10, GetGlobalParameter(kParameter_Volume)/10);

    float *left, *right;

    wavetable->lockWavetables();
    {
        float *wt = wavetable->getWavetableData(wavetable_idx);
        float base_frequency = wavetable->getBaseFrequency(wavetable_idx);

        left = (float*)inBuffer->mBuffers[0].mData;
        right = numChans == 2 ? (float*)inBuffer->mBuffers[1].mData : 0;

        double freq = Frequency()/base_frequency*((double)wavetable_sample_rate)/SampleRate();

        switch (GetState())
        {
        case kNoteState_Attacked :
        case kNoteState_Sostenutoed :
        case kNoteState_ReleasedButSostenutoed :
        case kNoteState_ReleasedButSustained :
        {
            for (UInt32 frame=0; frame<inNumFrames; ++frame)
            {
                if (amp < maxamp) amp += up_slope;

                int pint = (int) phase;
                float out1 = wt[pint%wavetable_num_samples];
                float out2 = wt[(pint+1)%wavetable_num_samples];
                float out =  ((1-(phase-pint))*out1+(phase-pint)*out2) * amp * volumeFactor;

                phase += freq;
                if (phase >= wavetable_num_samples) phase -= wavetable_num_samples;
                left[frame] += out;
                if (right) right[frame] += out;
            }
        }
        break;

        case kNoteState_Released :
        {
            UInt32 endFrame = 0xFFFFFFFF;
            for (UInt32 frame=0; frame<inNumFrames; ++frame)
            {
                if (amp > 0.0) amp *= dn_slope;
                else if (endFrame == 0xFFFFFFFF) endFrame = frame;

                int pint = (int) phase;
                float out1 = wt[pint%wavetable_num_samples];
                float out2 = wt[(pint+1)%wavetable_num_samples];
                float out =  ((1-(phase-pint))*out1+(phase-pint)*out2) * amp * volumeFactor;

                phase += freq;
                if (phase >= wavetable_num_samples) phase -= wavetable_num_samples;
                left[frame] += out;
                if (right) right[frame] += out;
            }
            if (endFrame != 0xFFFFFFFF)
                NoteEnded(endFrame);
        }
        break;

        case kNoteState_FastReleased :
        {
            UInt32 endFrame = 0xFFFFFFFF;
            for (UInt32 frame=0; frame<inNumFrames; ++frame)
            {
                if (amp > 0.0) amp += fast_dn_slope;
                else if (endFrame == 0xFFFFFFFF) endFrame = frame;

                int pint = (int) phase;
                float out1 = wt[pint%wavetable_num_samples];
                float out2 = wt[(pint+1)%wavetable_num_samples];
                float out =  ((1-(phase-pint))*out1+(phase-pint)*out2) * amp * volumeFactor;

                phase += freq;
                if (phase >= wavetable_num_samples) phase -= wavetable_num_samples;
                left[frame] += out;
                if (right) right[frame] += out;
            }
            if (endFrame != 0xFFFFFFFF)
                NoteEnded(endFrame);
        }
        break;
        default :
            break;
        }

    }
    wavetable->unlockWavetables();
    return noErr;
}