コード例 #1
0
        public Fingerprinter(FingerprinterConfiguration config, IFFTService fftService)
        {
            m_image = new Image(12);
            if (config == null)
            {
                config = new FingerprinterConfigurationTest1();
            }
            m_image_builder     = new ImageBuilder(m_image);
            m_chroma_normalizer = new ChromaNormalizer(m_image_builder);
            m_chroma_filter     = new ChromaFilter(config.FilterCoefficients, m_chroma_normalizer);
            m_chroma            = new Chroma(MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, m_chroma_filter);
            //m_chroma.set_interpolate(true);

            // TODO: inject IFFTService
            m_fft = new FFT(FRAME_SIZE, OVERLAP, m_chroma, fftService);
            if (config.RemoveSilence)
            {
                m_silence_remover           = new SilenceRemover(m_fft);
                m_silence_remover.Threshold = config.SilenceThreshold;
                m_audio_processor           = new AudioProcessor(SAMPLE_RATE, m_silence_remover);
            }
            else
            {
                m_silence_remover = null;
                m_audio_processor = new AudioProcessor(SAMPLE_RATE, m_fft);
            }
            m_fingerprint_calculator = new FingerprintCalculator(config.Classifiers);
            m_config = config;
        }
コード例 #2
0
ファイル: Fingerprinter.cs プロジェクト: wo80/AcoustID.NET
        public Fingerprinter(FingerprinterConfiguration config, IFFTService fftService)
        {
            m_image = new Image(12);
            if (config == null)
            {
                config = new FingerprinterConfigurationTest1();
            }
            m_image_builder = new ImageBuilder(m_image);
            m_chroma_normalizer = new ChromaNormalizer(m_image_builder);
            m_chroma_filter = new ChromaFilter(config.FilterCoefficients, m_chroma_normalizer);
            m_chroma = new Chroma(MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, m_chroma_filter);
            //m_chroma.set_interpolate(true);

            // TODO: inject IFFTService
            m_fft = new FFT(FRAME_SIZE, OVERLAP, m_chroma, fftService);
            if (config.RemoveSilence)
            {
                m_silence_remover = new SilenceRemover(m_fft);
                m_silence_remover.Threshold = config.SilenceThreshold;
                m_audio_processor = new AudioProcessor(SAMPLE_RATE, m_silence_remover);
            }
            else
            {
                m_silence_remover = null;
                m_audio_processor = new AudioProcessor(SAMPLE_RATE, m_fft);
            }
            m_fingerprint_calculator = new FingerprintCalculator(config.Classifiers);
            m_config = config;
        }
コード例 #3
0
 public void Test1()
 {
     Image image = new Image(12, 0);
     ImageBuilder builder = new ImageBuilder(image);
     ChromaResampler resampler = new ChromaResampler(2, builder);
     double[] d1 = { 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d2 = { 1.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d3 = { 2.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     resampler.Consume(d1);
     resampler.Consume(d2);
     resampler.Consume(d3);
     Assert.AreEqual(1, image.Rows);
     Assert.AreEqual(0.5, image.Get(0, 0));
     Assert.AreEqual(5.5, image.Get(0, 1));
 }
コード例 #4
0
ファイル: ImageGenerator.cs プロジェクト: wo80/AcoustID.NET
        /// <summary>
        /// Computes the spectogram of an audio file.
        /// </summary>
        /// <param name="decoder">The <see cref="IDecoder"/> instance.</param>
        /// <returns>Chroma image.</returns>
        public static Image ComputeSpectrogram(IDecoder decoder)
        {
            int numBands = 72;

            var image = new Image(numBands);
            var image_builder = new ImageBuilder(image);

            var chroma = new Spectrum(numBands, MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, image_builder);

            var fft = new FFT(FRAME_SIZE, OVERLAP, chroma, new LomontFFTService());
            var processor = new AudioProcessor(SAMPLE_RATE, fft);

            processor.Reset(decoder.SampleRate, decoder.Channels);
            decoder.Decode(processor, 120);
            processor.Flush();

            return image;
        }
コード例 #5
0
ファイル: ImageGenerator.cs プロジェクト: wo80/AcoustID.NET
        /// <summary>
        /// Computes the chromagram of an audio file.
        /// </summary>
        /// <param name="decoder">The <see cref="IDecoder"/> instance.</param>
        /// <returns>Chroma image.</returns>
        public static Image ComputeChromagram(IDecoder decoder)
        {
            var image = new Image(12);
            var image_builder = new ImageBuilder(image);

            var chroma_normalizer = new ChromaNormalizer(image_builder);
            var chroma_filter = new ChromaFilter(ChromaFilterCoefficients, chroma_normalizer);
            var chroma = new Chroma(MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, chroma_filter);

            var fft = new FFT(FRAME_SIZE, OVERLAP, chroma, new LomontFFTService());
            var processor = new AudioProcessor(SAMPLE_RATE, fft);

            processor.Reset(decoder.SampleRate, decoder.Channels);
            decoder.Decode(processor, 120);
            processor.Flush();

            return image;
        }
コード例 #6
0
ファイル: Spectrogram.cs プロジェクト: gaborp/AcoustID.NET
        //static int MAX_FILTER_WIDTH = 20;

        public static Image Compute(string file, IDecoder decoder)
        {
            int numBands = 72;

            Image image = new Image(numBands);
            ImageBuilder image_builder = new ImageBuilder(image);
            Spectrum chroma = new Spectrum(numBands, MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, image_builder);
            FFT fft = new FFT(FRAME_SIZE, OVERLAP, chroma);
            AudioProcessor processor = new AudioProcessor(SAMPLE_RATE, fft);

            processor.Reset(decoder.SampleRate, decoder.Channels);
            decoder.Decode(processor, 120);
            processor.Flush();

            //ExportImage(image, name, 0.5);

            return image;
        }
コード例 #7
0
 public void TestDiff()
 {
     double[] coefficients = { 1.0, -1.0 };
     Image image = new Image(12);
     ImageBuilder builder = new ImageBuilder(image);
     ChromaFilter filter = new ChromaFilter(coefficients, builder);
     double[] d1 = { 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d2 = { 1.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d3 = { 2.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     filter.Consume(d1);
     filter.Consume(d2);
     filter.Consume(d3);
     Assert.AreEqual(2, image.Rows);
     Assert.AreEqual(-1.0, image.Get(0, 0));
     Assert.AreEqual(-1.0, image.Get(1, 0));
     Assert.AreEqual(-1.0, image.Get(0, 1));
     Assert.AreEqual(-1.0, image.Get(1, 1));
 }
コード例 #8
0
        public void TestBasicImage()
        {
            short[] data = TestsHelper.LoadAudioFile("test_stereo_44100.raw");

            Assert.IsNotNull(data, "Failed to load test data (check DATA_PATH in TestsHelper.cs)");

            Image image = new Image(12);
            ImageBuilder image_builder = new ImageBuilder(image);
            ChromaNormalizer chroma_normalizer = new ChromaNormalizer(image_builder);
            Chroma chroma = new Chroma(MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, chroma_normalizer);
            FFT fft = new FFT(FRAME_SIZE, OVERLAP, chroma);
            AudioProcessor processor = new AudioProcessor(SAMPLE_RATE, fft);

            processor.Reset(44100, 2);
            processor.Consume(data, data.Length);
            processor.Flush();

            double[][] chromagram = {
		        new double[] { 0.155444, 0.268618, 0.474445, 0.159887, 0.1761, 0.423511, 0.178933, 0.34433, 0.360958, 0.30421, 0.200217, 0.17072 },
		        new double[] { 0.159809, 0.238675, 0.286526, 0.166119, 0.225144, 0.449236, 0.162444, 0.371875, 0.259626, 0.483961, 0.24491, 0.17034 },
		        new double[] { 0.156518, 0.271503, 0.256073, 0.152689, 0.174664, 0.52585, 0.141517, 0.253695, 0.293199, 0.332114, 0.442906, 0.170459 },
		        new double[] { 0.154183, 0.38592, 0.497451, 0.203884, 0.362608, 0.355691, 0.125349, 0.146766, 0.315143, 0.318133, 0.172547, 0.112769 },
		        new double[] { 0.201289, 0.42033, 0.509467, 0.259247, 0.322772, 0.325837, 0.140072, 0.177756, 0.320356, 0.228176, 0.148994, 0.132588 },
		        new double[] { 0.187921, 0.302804, 0.46976, 0.302809, 0.183035, 0.228691, 0.206216, 0.35174, 0.308208, 0.233234, 0.316017, 0.243563 },
		        new double[] { 0.213539, 0.240346, 0.308664, 0.250704, 0.204879, 0.365022, 0.241966, 0.312579, 0.361886, 0.277293, 0.338944, 0.290351 },
		        new double[] { 0.227784, 0.252841, 0.295752, 0.265796, 0.227973, 0.451155, 0.219418, 0.272508, 0.376082, 0.312717, 0.285395, 0.165745 },
		        new double[] { 0.168662, 0.180795, 0.264397, 0.225101, 0.562332, 0.33243, 0.236684, 0.199847, 0.409727, 0.247569, 0.21153, 0.147286 },
		        new double[] { 0.0491864, 0.0503369, 0.130942, 0.0505802, 0.0694409, 0.0303877, 0.0389852, 0.674067, 0.712933, 0.05762, 0.0245158, 0.0389336 },
		        new double[] { 0.0814379, 0.0312366, 0.240546, 0.134609, 0.063374, 0.0466124, 0.0752175, 0.657041, 0.680085, 0.0720311, 0.0249404, 0.0673359 },
		        new double[] { 0.139331, 0.0173442, 0.49035, 0.287237, 0.0453947, 0.0873279, 0.15423, 0.447475, 0.621502, 0.127166, 0.0355933, 0.141163 },
		        new double[] { 0.115417, 0.0132515, 0.356601, 0.245902, 0.0283943, 0.0588233, 0.117077, 0.499376, 0.715366, 0.100398, 0.0281382, 0.0943482 },
		        new double[] { 0.047297, 0.0065354, 0.181074, 0.121455, 0.0135504, 0.030693, 0.0613105, 0.631705, 0.73548, 0.0550565, 0.0128093, 0.0460393 },
	        };

            Assert.AreEqual(14, image.Rows, "Numbers of rows doesn't match");
            for (int y = 0; y < 14; y++)
            {
                for (int x = 0; x < 12; x++)
                {
                    Assert.AreEqual(chromagram[y][x], image[y, x], 1e-5);
                }
            }
        }
コード例 #9
0
ファイル: Chromagram.cs プロジェクト: gaborp/AcoustID.NET
        public static Image Compute(string file, IDecoder decoder)
        {
            Image image = new Image(12);
            ImageBuilder image_builder = new ImageBuilder(image);
            ChromaNormalizer chroma_normalizer = new ChromaNormalizer(image_builder);
            ChromaFilter chroma_filter = new ChromaFilter(ChromaFilterCoefficients, chroma_normalizer);
            //Chroma chroma = new Chroma(MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, &chroma_normalizer);
            Chroma chroma = new Chroma(MIN_FREQ, MAX_FREQ, FRAME_SIZE, SAMPLE_RATE, chroma_filter);
            FFT fft = new FFT(FRAME_SIZE, OVERLAP, chroma);
            AudioProcessor processor = new AudioProcessor(SAMPLE_RATE, fft);

            processor.Reset(decoder.SampleRate, decoder.Channels);
            decoder.Decode(processor, 120);
            processor.Flush();

            //ExportImage(image, name);

            return image;
        }
コード例 #10
0
 public void TestBlur3()
 {
     double[] coefficients = { 0.5, 0.7, 0.5 };
     Image image = new Image(12, 0);
     ImageBuilder builder = new ImageBuilder(image);
     ChromaFilter filter = new ChromaFilter(coefficients, builder);
     double[] d1 = { 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d2 = { 1.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d3 = { 2.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     double[] d4 = { 3.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
     filter.Consume(d1);
     filter.Consume(d2);
     filter.Consume(d3);
     filter.Consume(d4);
     Assert.AreEqual(2, image.Rows);
     Assert.AreEqual(1.7, image.Get(0, 0), TestsHelper.EPS);
     Assert.AreEqual(3.399999999999999, image.Get(1, 0), TestsHelper.EPS);
     Assert.AreEqual(10.199999999999999, image.Get(0, 1), TestsHelper.EPS);
     Assert.AreEqual(11.899999999999999, image.Get(1, 1), TestsHelper.EPS);
 }