Пример #1
0
 public void Consume(FFTFrame frame)
 {
     for (int i = 0; i < NumBands(); i++)
     {
         int    first       = FirstIndex(i);
         int    last        = LastIndex(i);
         double numerator   = 0.0;
         double denominator = 0.0;
         for (int j = first; j < last; j++)
         {
             double s = frame.Energy(j);
             numerator   += j * s;
             denominator += s;
         }
         m_features[i] = denominator / (last - first);
     }
     m_consumer.Consume(m_features);
 }
Пример #2
0
        public void Consume(FFTFrame frame)
        {
            // TODO: do we really need to create a new instance here
            m_features = new double[NUM_BANDS];

            // Yes, we do. See ChromaFilter: m_buffer[i][] would reference
            // the same array for all i.

            //for (int i = 0; i < m_features.Length; i++)
            //{
            //    m_features[i] = 0.0;
            //}

            for (int i = m_min_index; i < m_max_index; i++)
            {
                int    note   = m_notes[i];
                double energy = frame.Energy(i);
                if (m_interpolate)
                {
                    int    note2 = note;
                    double a     = 1.0;
                    if (m_notes_frac[i] < 0.5)
                    {
                        note2 = (note + NUM_BANDS - 1) % NUM_BANDS;
                        a     = 0.5 + m_notes_frac[i];
                    }
                    if (m_notes_frac[i] > 0.5)
                    {
                        note2 = (note + 1) % NUM_BANDS;
                        a     = 1.5 - m_notes_frac[i];
                    }
                    m_features[note]  += energy * a;
                    m_features[note2] += energy * (1.0 - a);
                }
                else
                {
                    m_features[note] += energy;
                }
            }
            m_consumer.Consume(m_features);
        }
Пример #3
0
 public void Consume(FFTFrame frame)
 {
     for (int i = 0; i < NumBands(); i++)
     {
         int    first       = FirstIndex(i);
         int    last        = LastIndex(i);
         double numerator   = 0.0;
         double denominator = 0.0;
         for (int j = first; j < last; j++)
         {
             double s = frame.Energy(j);
             numerator   += j * s;
             denominator += s;
         }
         double centroid = numerator / denominator;
         if (Double.IsNaN(centroid))
         {
             centroid = (first + last) / 2.0; // handle NaN
         }
         m_features[i] = (centroid - first) / (last - first);
     }
     m_consumer.Consume(m_features);
 }