Ejemplo n.º 1
0
FeatureSet StringToFeatureSet(const std::string& features_string) {
    if (features_string.empty()) {
        return FeatureSet();
    }

    auto names = android::base::Split(features_string,
                                      {kFeatureStringDelimiter});
    return FeatureSet(names.begin(), names.end());
}
Ejemplo n.º 2
0
TemporalCentroid::FeatureSet
TemporalCentroid::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
{
    // First we need to compute the RMS
    float energy = 0.0f;

    size_t i = 0; // note: same type as m_blockSize

    while (i < m_blockSize)
    {
        float sample = inputBuffers[0][i];
        energy += sample * sample;
        ++i;
    }

    float mean_energy = energy / m_blockSize;
    float rms = sqrt(mean_energy);

    m_rms.push_back(rms);
    m_timestamps.push_back(timestamp);

    // cout << timestamp+Vamp::RealTime::fromSeconds(1) << endl; // debugging
    //cout << (float)timestamp.nsec/1e9 << endl;
    //cout << timestamp << ": " << timestamp.sec + (float)timestamp.nsec/1e9 << endl; // CONVERSION!

    return FeatureSet();
}
Ejemplo n.º 3
0
MzSpectrogramFFTW::FeatureSet 
MzSpectrogramFFTW::process(AUDIODATA inputbufs, Vamp::RealTime timestamp) {

   if (getChannelCount() <= 0) {
      std::cerr << "ERROR: MzSpectrogramFFTW::process: "
                << "MzSpectrogramFFTW has not been initialized"
                << std::endl;
      return FeatureSet();
   }

   // first window the input signal frame
   windowSignal(mz_transformer, mz_wind_buff, inputbufs[0]);

   // then calculate the complex DFT spectrum. 
   mz_transformer.doTransform();

   // return the spectral magnitude frame to the host application:

   FeatureSet returnFeatures;
   Feature    feature;
   feature.hasTimestamp = false;

   float magnitude;
   for (int i=mz_minbin; i<=mz_maxbin; i++) {
      magnitude = (float)mz_transformer.getSpectrumMagnitudeDb(i);
      feature.values.push_back(magnitude);
   }

   returnFeatures[0].push_back(feature);

   return returnFeatures;
}
Ejemplo n.º 4
0
Chordino::FeatureSet
Chordino::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
{   
    if (debug_on) cerr << "--> process" << endl;

    NNLSBase::baseProcess(inputBuffers, timestamp);

    return FeatureSet();
}
MusicHackChord::FeatureSet
MusicHackChord::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
{
    // Do actual work!
	int size = chromas[0].size();
	for(int i = m_startPos; i < m_blockSize; i++)
	{
		for(int j = 0; j < NUM_BINS; j++)
		{
			if(size >= BUFFER_SIZE)
				chromas[j].pop_front();
			chromas[j].push_back(apBandPass(inputBuffers[0][i], j));
		}	
	}
	m_counter += m_stepSize;
	if(m_counter >= BUFFER_SIZE)
	{	
		float chromaOctaves[NUM_CHROMAS];
		float correlations[2][NUM_CHROMAS];
		memset(chromaOctaves, 0, sizeof(chromaOctaves));
		memset(correlations, 0, sizeof(correlations));
		for(int i = 0; i < NUM_BINS; i++)
		{
			float sum = 0;
			for(int j = 0; j < chromas[j].size(); j++)
				sum += chromas[i][j] * chromas[i][j];
			chromaOctaves[i % NUM_CHROMAS] += sum;
		}
		float m = mean(chromaOctaves, NUM_CHROMAS);
		for(int i = 0; i < NUM_CHROMAS; i++)
		{	
			for(int j = 0; j < NUM_CHROMAS; j++)
			{
				correlations[0][i] += (chromaOctaves[j] - m) * (MAJOR[(j - i + NUM_CHROMAS) % NUM_CHROMAS] - MEAN_CHORD);
				correlations[1][i] += (chromaOctaves[j] - m) * (MINOR[(j - i + NUM_CHROMAS) % NUM_CHROMAS] - MEAN_CHORD); 
			}
		}
		int majorMaxIndex = max(correlations[0], NUM_CHROMAS);
		int minorMaxIndex = max(correlations[1], NUM_CHROMAS);
		Feature f;
		f.hasTimestamp = false;
		if(correlations[0][majorMaxIndex] > correlations[1][minorMaxIndex])
			f.values.push_back(majorMaxIndex);
		else
			f.values.push_back(minorMaxIndex + NUM_CHROMAS);

		FeatureSet fs;
		fs[0].push_back(f);
		m_counter=0; 
		return fs;
	}
    return FeatureSet();
}
SpeechMusicSegmenter::FeatureSet
SpeechMusicSegmenter::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
{
    // Extracting ZCR per frame
    size_t i = 1;
    double zc = 0.0;

    while (i < m_blockSize) {
        if ((inputBuffers[0][i] * inputBuffers[0][i - 1]) < 0) zc += 1;
        i += 1;
    }
    zc /= (m_blockSize - 1);
    m_zcr.push_back(zc);

    m_nframes += 1;

    return FeatureSet();
}
Ejemplo n.º 7
0
TemporalCentroid::FeatureSet
TemporalCentroid::getRemainingFeatures()
{
    Vamp::RealTime centroid_timestamp;

    if (m_rms.empty()) // empty signal
        centroid_timestamp = Vamp::RealTime::fromSeconds(0);
    else
    {
        // Compute the temporal centroid
        float max_rms = *(max_element(m_rms.begin(),m_rms.end())); // find the maximum RMS value
        float rms_threshold = 0.15f * max_rms; // threshold for starting to compute temporal centroid, 15% of max RMS

        int n1 = 0;
        while (m_rms[n1] < rms_threshold) // find first frame where RMS > 15% of max RMS
            n1++;

        int n2 = (int)m_rms.size() - 1;
        while (m_rms[n2] < rms_threshold)
            n2--;

        float sum_weighted_time = 0.0f;
        float sum_rms = 0.0f;
        for (int i=n1; i<=n2; i++)
        {
            sum_rms += m_rms[i];
            sum_weighted_time += m_rms[i] * (m_timestamps[i].sec + (float)m_timestamps[i].nsec/1e9);
        }

        float temporalcentroid = sum_weighted_time / sum_rms;
        centroid_timestamp = Vamp::RealTime::fromSeconds(temporalcentroid);
    }

    Feature f;
    f.hasTimestamp = true;
    f.timestamp = centroid_timestamp;

    FeatureSet fs;
    fs[0].push_back(f);

    return fs;
    return FeatureSet();
}
Ejemplo n.º 8
0
MyPlugin::FeatureSet
MyPlugin::getRemainingFeatures()
{
    return FeatureSet();
}
Ejemplo n.º 9
0
MyPlugin::FeatureSet
MyPlugin::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
{
    // Do actual work!
    return FeatureSet();
}
MusicHackChord::FeatureSet
MusicHackChord::getRemainingFeatures()
{
    return FeatureSet();
}
Ejemplo n.º 11
0
SpectralCentroid::FeatureSet
SpectralCentroid::getRemainingFeatures()
{
    return FeatureSet();
}
Ejemplo n.º 12
0
TonalChangeDetect::FeatureSet
TonalChangeDetect::process(const float *const *inputBuffers,
                           Vamp::RealTime timestamp)
{
    if (!m_chromagram) {
        cerr << "ERROR: TonalChangeDetect::process: "
             << "Chromagram has not been initialised"
             << endl;
        return FeatureSet();
    }

    if (!m_haveOrigin) m_origin = timestamp;

    // convert float* to double*
    double *tempBuffer = new double[m_block];
    for (size_t i = 0; i < m_block; ++i) {
        tempBuffer[i] = inputBuffers[0][i];
    }

    double *output = m_chromagram->process(tempBuffer);
    delete[] tempBuffer;

    for (size_t i = 0; i < 12; i++)
    {
        m_vaCurrentVector[i] = output[i];
    }


    FeatureSet returnFeatures;

    if (m_stepDelay == 0) {
        m_vaCurrentVector.normalizeL1();
        TCSVector tcsVector = m_TonalEstimator.transform2TCS(m_vaCurrentVector);
        m_TCSGram.addTCSVector(tcsVector);

        Feature feature;
        feature.hasTimestamp = false;
        for (int i = 0; i < 6; i++)
        {
            feature.values.push_back(static_cast<float>(tcsVector[i]));
        }
        feature.label = "";
        returnFeatures[0].push_back(feature);

        return returnFeatures;
    }

    if (m_pending.size() == m_stepDelay) {

        ChromaVector v = m_pending.front();
        v.normalizeL1();
        TCSVector tcsVector = m_TonalEstimator.transform2TCS(v);
        m_TCSGram.addTCSVector(tcsVector);

        Feature feature;
        feature.hasTimestamp = false;
        for (int i = 0; i < 6; i++)
        {
            feature.values.push_back(static_cast<float>(tcsVector[i]));
        }
        feature.label = "";
        returnFeatures[0].push_back(feature);
        m_pending.pop();

    } else {
        returnFeatures[0].push_back(Feature());
        m_TCSGram.addTCSVector(TCSVector());
    }

    m_pending.push(m_vaCurrentVector);


    return returnFeatures;
}
Ejemplo n.º 13
0
MzSpectrogramFFTW::FeatureSet 
MzSpectrogramFFTW::getRemainingFeatures(void) {
   // no remaining features, so return a dummy feature
   return FeatureSet();
}
Ejemplo n.º 14
0
/**
  * @brief  ÓÃÓÚ¼ì²âÊÇ·ñµÚÒ»´ÎʹÓÃÐÂоƬ£¬Ò²¾ÍÊDz鿴FLASHÀïÊÇ·ñ±£´æÓвÎÊý£¬Èç¹ûûÓÐÔòдÈëĬÈϲÎ
  *         
  * @param  reset:Èç¹ûΪfalseΪÕý³£¼ì²â£¬ÎªtrueÔòÇ¿ÖÆÖØвÁд
  * @retval none
  */
void Flash_CheckFirstTime(bool reset)
{
    uint8_t test_val, i;

    test_val = *(uint8_t *) FLASH_WRITE_ADDR;

    if (!reset && test_val == CHECKNEWCONF)
        return;

    // Default settings
    cfg.version = CHECKNEWCONF;
    cfg.mixerConfiguration = MULTITYPE_QUADX;
    FeatureClearAll();
    FeatureSet(FEATURE_MOTOR_STOP|FEATURE_FAILSAFE|FEATURE_GPS);

    cfg.looptime = 0;
    cfg.P8[ROLL] = 40;
    cfg.I8[ROLL] = 30;
    cfg.D8[ROLL] = 23;
    cfg.P8[PITCH] = 40;
    cfg.I8[PITCH] = 30;
    cfg.D8[PITCH] = 23;
    cfg.P8[YAW] = 85;
    cfg.I8[YAW] = 45;
    cfg.D8[YAW] = 0;
    cfg.P8[PIDALT] = 16;
    cfg.I8[PIDALT] = 15;
    cfg.D8[PIDALT] = 7;
    cfg.P8[PIDPOS] = 11; // POSHOLD_P * 100;
    cfg.I8[PIDPOS] = 0; // POSHOLD_I * 100;
    cfg.D8[PIDPOS] = 0;
    cfg.P8[PIDPOSR] = 20; // POSHOLD_RATE_P * 10;
    cfg.I8[PIDPOSR] = 8; // POSHOLD_RATE_I * 100;
    cfg.D8[PIDPOSR] = 45; // POSHOLD_RATE_D * 1000;
    cfg.P8[PIDNAVR] = 14; // NAV_P * 10;
    cfg.I8[PIDNAVR] = 20; // NAV_I * 100;
    cfg.D8[PIDNAVR] = 80; // NAV_D * 1000;
    cfg.P8[PIDLEVEL] = 70;
    cfg.I8[PIDLEVEL] = 10;
    cfg.D8[PIDLEVEL] = 20;
    cfg.P8[PIDMAG] = 40;
    cfg.P8[PIDVEL] = 0;
    cfg.I8[PIDVEL] = 0;
    cfg.D8[PIDVEL] = 0;
    cfg.rcRate8 = 90;
    cfg.rcExpo8 = 65;
    cfg.rollPitchRate = 0;
    cfg.yawRate = 0;
    cfg.dynThrPID = 0;
    cfg.thrMid8 = 50;
    cfg.thrExpo8 = 0;
    for (i = 0; i < CHECKBOXITEMS; i++)
        cfg.activate[i] = 0;
    cfg.angleTrim[0] = 0;
    cfg.angleTrim[1] = 0;
    cfg.accZero[0] = 0;
    cfg.accZero[1] = 0;
    cfg.accZero[2] = 0;
    cfg.mag_declination = -233;    // For example, -6deg 37min, = -637 Japan, format is [sign]dddmm (degreesminutes) default is zero. ¹ãÖÝ´ÅÆ«½ÇΪ2¶È33·Ö
    cfg.acc_hardware = ACC_MPU6050;     //ÎÒÃÇĬÈÏÊÇÓÃMPU6050
    cfg.acc_lpf_factor = 100;
    cfg.gyro_cmpf_factor = 1500; // default MWC
    cfg.gyro_lpf = 42;
    cfg.mpu6050_scale = 1; // f**k invensense
    cfg.gyro_smoothing_factor = 0x00141403;     // default factors of 20, 20, 3 for R/P/Y
    cfg.vbatscale = 110;
    cfg.vbatmaxcellvoltage = 43;
    cfg.vbatmincellvoltage = 33;

    // Radio
    ParseRcChannels("AETR1234");
    cfg.deadband = 0;
    cfg.yawdeadband = 0;
    cfg.alt_hold_throttle_neutral = 20;
    cfg.spektrum_hires = 0;
    cfg.midrc = 1500;
    cfg.mincheck = 1100;
    cfg.maxcheck = 1900;
    cfg.retarded_arm = 0;       // disable arm/disarm on roll left/right

    // Failsafe Variables
    cfg.failsafe_delay = 200;    // 0.1sec
    cfg.failsafe_off_delay = 50;       // 20sec
    cfg.failsafe_throttle = 1200;       // decent default which should always be below hover throttle for people.

    // Motor/ESC/Servo
    cfg.minthrottle = 1150;
    cfg.maxthrottle = 2000;//1850
    cfg.mincommand = 1000;
    cfg.Vision_ErrorZero[0] = 0;
    cfg.Vision_ErrorZero[1] = 0;

    // servos
    cfg.yaw_direction = 1;
    cfg.tri_yaw_middle = 1500;
    cfg.tri_yaw_min = 1020;
    cfg.tri_yaw_max = 2000;

    // gimbal
    cfg.gimbal_pitch_gain = 10;
    cfg.gimbal_roll_gain = 10;
    cfg.gimbal_flags = GIMBAL_NORMAL;
    cfg.gimbal_pitch_min = 1020;
    cfg.gimbal_pitch_max = 2000;
    cfg.gimbal_pitch_mid = 1500;
    cfg.gimbal_roll_min = 1020;
    cfg.gimbal_roll_max = 2000;
    cfg.gimbal_roll_mid = 1500;

    // gps/nav stuff
    cfg.gps_baudrate = 115200;
    cfg.gps_wp_radius = 200;		 //µ¥Î»  cm
    cfg.gps_lpf = 20;
    cfg.nav_slew_rate = 30;
    cfg.nav_controls_heading = 1;
    cfg.nav_speed_min = 100;
    cfg.nav_speed_max = 300;		  //3.0m/s

    // serial(uart1) baudrate
    cfg.serial_baudrate = 115200;

    Flash_WriteParams(0);
}
Ejemplo n.º 15
0
MiniBpmVamp::FeatureSet
MiniBpmVamp::process(const float *const *inputBuffers, Vamp::RealTime timestamp)
{
    m_mbpm->process(inputBuffers[0], m_blockSize);
    return FeatureSet();
}