Exemplo n.º 1
0
        public void TestNormalB()
        {
            FeatureVectorBuffer buffer = new FeatureVectorBuffer();
            Chroma chroma = new Chroma(10, 510, 256, 1000, buffer);
            FFTFrame frame = new FFTFrame(128);
            frame.Data[64] = 1.0; // 250 Hz
            chroma.Consume(frame);
            Assert.AreEqual(12, buffer.features.Length);
            double[] expected_features = {
		        0.0, 0.0, 1.0, 0.0, 0.0, 0.0,
		        0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
	        };
            for (int i = 0; i < 12; i++)
            {
                Assert.AreEqual(expected_features[i], buffer.features[i], 0.0001);
            }
        }
Exemplo n.º 2
0
        public void TestInterpolatedB()
        {
            FeatureVectorBuffer buffer = new FeatureVectorBuffer();
            Chroma chroma = new Chroma(10, 510, 256, 1000, buffer);
            chroma.Interpolate = true;
            FFTFrame frame = new FFTFrame(128);
            frame.Data[64] = 1.0;
            chroma.Consume(frame);
            Assert.AreEqual(12, buffer.features.Length);
            double[] expected_features = {
		        0.0, 0.286905, 0.713095, 0.0, 0.0, 0.0,
		        0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
	        };
            for (int i = 0; i < 12; i++)
            {
                Assert.AreEqual(expected_features[i], buffer.features[i], 0.0001);
            }
        }
Exemplo n.º 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;
         }
         m_features[i] = denominator / (last - first);
     }
     m_consumer.Consume(m_features);
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public FFT(int frame_size, int overlap, IFFTFrameConsumer consumer, IFFTService fftService)
        {
            m_window        = new double[frame_size];
            m_buffer_offset = 0;
            m_buffer        = new short[frame_size];
            m_frame         = new FFTFrame(frame_size);
            m_frame_size    = frame_size;
            m_increment     = frame_size - overlap;
            m_consumer      = consumer;

            Helper.PrepareHammingWindow(ref m_window, 0, frame_size);
            for (int i = 0; i < frame_size; i++)
            {
                m_window[i] /= short.MaxValue;
            }

            m_lib = fftService;
            m_lib.Initialize(frame_size, m_window);

            m_input = new short[frame_size];
        }
Exemplo n.º 8
0
        public FFT(int frame_size, int overlap, IFFTFrameConsumer consumer, IFFTService fftService)
        {
            m_window = new double[frame_size];
            m_buffer_offset = 0;
            m_buffer = new short[frame_size];
            m_frame = new FFTFrame(frame_size);
            m_frame_size = frame_size;
            m_increment = frame_size - overlap;
            m_consumer = consumer;

            Helper.PrepareHammingWindow(ref m_window, 0, frame_size);
            for (int i = 0; i < frame_size; i++)
            {
                m_window[i] /= short.MaxValue;
            }

            m_lib = fftService;
            m_lib.Initialize(frame_size, m_window);

            m_input = new short[frame_size];
        }
Exemplo n.º 9
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);
 }
Exemplo n.º 10
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);
 }