예제 #1
0
void GLAnalyzer2::analyze(const Scope& s) {
  bool haveNoData = s.empty();

  // if we're going into pause mode, clear timers.
  if (!show.paused && haveNoData) show.pauseTimer = 0.0;

  // if we have got data, interpolate it (asking myself why I'm doing it here..)
  if (!(show.paused = haveNoData)) {
    int bands = s.size(), lowbands = bands / 4, hibands = bands / 3,
        midbands = bands - lowbands - hibands;
    Q_UNUSED(midbands);
    float currentEnergy = 0, currentMeanBand = 0, maxValue = 0;
    for (int i = 0; i < bands; i++) {
      float value = s[i];
      currentEnergy += value;
      currentMeanBand += (float)i * value;
      if (value > maxValue) maxValue = value;
    }
    frame.silence = currentEnergy < 0.001;
    if (!frame.silence) {
      frame.meanBand = 100.0 * currentMeanBand / (currentEnergy * bands);
      currentEnergy = 100.0 * currentEnergy / (float)bands;
      frame.dEnergy = currentEnergy - frame.energy;
      frame.energy = currentEnergy;
      //            printf( "%d  [%f :: %f ]\t%f \n", bands, frame.energy,
      // frame.meanBand, maxValue         );
    } else
      frame.energy = 0.0;
  }

  // update the frame
  updateGL();
}
예제 #2
0
void GLAnalyzer3::analyze( const Scope &s )
{
    // compute the dTime since the last call
    timeval tv;
    gettimeofday( &tv, NULL );
    double currentTime = (double)tv.tv_sec + (double)tv.tv_usec/1000000.0;
    show.dT = currentTime - show.timeStamp;
    show.timeStamp = currentTime;

    // compute energy integrating frame's spectrum
    if ( !s.empty() )
    {
    int bands = s.size();
    float currentEnergy = 0,
          maxValue = 0;
    // integrate spectrum -> energy
    for ( int i = 0; i < bands; i++ )
    {
        float value = s[i];
        currentEnergy += value;
        if ( value > maxValue )
        maxValue = value;
    }
    currentEnergy *= 100.0 / (float)bands;
    // emulate a peak detector: currentEnergy -> peakEnergy (3tau = 30 seconds)
    show.peakEnergy = 1.0 + ( show.peakEnergy - 1.0 ) * exp( - show.dT / 10.0 );
    if ( currentEnergy > show.peakEnergy )
        show.peakEnergy = currentEnergy;
    // check for silence
    frame.silence = currentEnergy < 0.001;
    // normalize frame energy against peak energy and compute frame stats
    currentEnergy /= show.peakEnergy;
    frame.dEnergy = currentEnergy - frame.energy;
    frame.energy = currentEnergy;
    } else
    frame.silence = true;

    // update the frame
    updateGL();
}