Example #1
0
        private void ProcessFile(string file)
        {
            if (File.Exists(file))
            {
                if (decoder != null)
                {
                    //btnOpen.Enabled = false;
                    btnFingerPrint.Enabled = false;
                    btnRequest.Enabled     = false;

                    Task.Factory.StartNew(() =>
                    {
                        Stopwatch stopwatch = new Stopwatch();
                        stopwatch.Start();

                        ChromaContext context = new ChromaContext();
                        context.Start(decoder.SampleRate, decoder.Channels);
                        decoder.Decode(context.Consumer, 120);
                        context.Finish();

                        stopwatch.Stop();

                        ProcessFileCallback(context.GetFingerprint(), stopwatch.ElapsedMilliseconds);
                    });
                }
            }
        }
Example #2
0
        /// <summary>
        /// Calcul l'empreinte de la musique et l'enregistre dans les métadatas
        /// </summary>
        /// <returns></returns>
        public void CalculateFingerprint()
        {
            // Initialisation du décodeur pour décompresser la musique
            IAudioDecoder decoder;

            decoder = new NAudioDecoder(PathNameExtension);

            int bits     = decoder.Format.BitDepth;
            int channels = decoder.Format.Channels;

            // Initialisation de chromaprint
            ChromaContext context = new ChromaContext(AcoustID.Chromaprint.ChromaprintAlgorithm.TEST1);

            context.Start(decoder.SampleRate, decoder.Channels);
            SetDurationEverywhere(decoder.Format.Duration);
            decoder.Decode(context.Consumer, 120);
            context.Finish();

            decoder.Dispose();

            try
            {
                if (context.GetFingerprint() != null && context.GetFingerprint() != "")
                {
                    SetFingerprintEverywhere(context.GetFingerprint());
                }
            }
            catch
            {
            }
        }
Example #3
0
        public async Task RunFingerprinting(string filePath)
        {
            if (filePath == null)
            {
                throw new ArgumentNullException(nameof(filePath), $"Cannot fingerprint audio file, since its path is null.");
            }
            if (filePath.Length < 8) // "C:\x.abc" is 8 characters long
            {
                throw new ArgumentException($"Cannot fingerprint audio file, since its path is too short.", nameof(filePath));
            }
            if (File.Exists(filePath) == false)
            {
                throw new FileNotFoundException($"Cannot fingerprint audio file, since it does not exist on the given path of {filePath}.", nameof(filePath));
            }

            dataReady = false;

            await Task.Factory.StartNew(() =>
            {
                InitReader(filePath);

                ChromaContext context = new ChromaContext();
                context.Start(sampleRate, channels);
                Decode(context.Consumer, 120);
                context.Finish();

                fingerprint = context.GetFingerprint();

                DisposeReader();

                dataReady = true;
            });
        }
Example #4
0
        private AcoustID.FingerprintAcoustID MakeAcoustIDFinger(string key, string filename)
        {
            // resample to 11025Hz
            IAudioDecoder decoder = new BassDecoder();

            try
            {
                decoder.Load(filename);

                ChromaContext context = new ChromaContext();

                context.Start(decoder.SampleRate, decoder.Channels);
                decoder.Decode(context.Consumer, 120);
                if (context.Finish())
                {
                    FingerprintAcoustID fingerprint = new FingerprintAcoustID();
                    fingerprint.Reference      = key;
                    fingerprint.DurationInMS   = (long)decoder.Duration * 1000;
                    fingerprint.SignatureInt32 = context.GetRawFingerprint();

                    return(fingerprint);
                }
            }
            catch (Exception e)
            {
                // Probleem waarschijnlijk met file.
                Console.Error.WriteLine(e.ToString());
            }
            finally
            {
                decoder.Dispose();
            }

            return(null);
        }
        private static string Generate(string file)
        {
            NAudioDecoder decoder = new NAudioDecoder(file);
            ChromaContext context = new ChromaContext();

            context.Start(decoder.SampleRate, decoder.Channels);
            decoder.Decode(context, 1000);
            context.Finish();

            return(context.GetFingerprint());
        }
        public string GenerateFingerprint(string file)
        {
            var decoder = new NAudioDecoder(file);
            var context = new ChromaContext();

            context.Start(decoder.SampleRate, decoder.Channels);
            decoder.Decode(context.Consumer, 1000);
            context.Finish();

            return(context.GetFingerprint());
        }
        public void TestDecodeFingerprint()
        {
            byte[] data = { 55, 0, 0, 2, 65, 0 };

            int algorithm;

            int[] fingerprint = ChromaContext.DecodeFingerprint(data, false, out algorithm);

            Assert.AreEqual(2, fingerprint.Length);
            Assert.AreEqual(55, algorithm);
            Assert.AreEqual(1, fingerprint[0]);
            Assert.AreEqual(0, fingerprint[1]);
        }
        public void TestEncodeFingerprintBase64()
        {
            int[]  fingerprint = { 1, 0 };
            byte[] expected    = Base64.ByteEncoding.GetBytes("NwAAAkEA");


            byte[] encoded = ChromaContext.EncodeFingerprint(fingerprint, 55, true);

            Assert.AreEqual(8, encoded.Length);
            for (int i = 0; i < encoded.Length; i++)
            {
                Assert.AreEqual(expected[i], encoded[i]);
            }
        }
        public void TestEncodeFingerprint()
        {
            int[]  fingerprint = { 1, 0 };
            byte[] expected    = new byte[] { 55, 0, 0, 2, 65, 0 };


            byte[] encoded = ChromaContext.EncodeFingerprint(fingerprint, 55, false);

            Assert.AreEqual(6, encoded.Length);
            for (int i = 0; i < encoded.Length; i++)
            {
                Assert.AreEqual(expected[i], encoded[i]);// << "Different at " << i;
            }
        }
        /// <summary>
        /// Create a Fingerprint and lookup the Recordings
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        private async Task <List <Recording> > GetRecordings(string file)
        {
            var stream = Bass.BASS_StreamCreateFile(file, 0, 0, BASSFlag.BASS_STREAM_DECODE);
            var chInfo = Bass.BASS_ChannelGetInfo(stream);

            var bufLen = (int)Bass.BASS_ChannelSeconds2Bytes(stream, 120.0);
            var buf    = new short[bufLen];

            var chromaContext = new ChromaContext();

            chromaContext.Start(chInfo.freq, chInfo.chans);

            var length = Bass.BASS_ChannelGetData(stream, buf, bufLen);

            chromaContext.Feed(buf, length / 2);

            chromaContext.Finish();

            var fingerPrint = chromaContext.GetFingerprint();

            Configuration.ClientKey = "mfbgmu2P";
            var lookupSvc = new LookupService();

            var len  = Bass.BASS_ChannelGetLength(stream, BASSMode.BASS_POS_BYTE);
            var time = Bass.BASS_ChannelBytes2Seconds(stream, len);

            Bass.BASS_StreamFree(stream);

            //var result = await lookupSvc.GetAsync(fingerPrint, Convert.ToInt32(time), new[] { "recordingids", "releases", "artists" });
            var trackIds = await lookupSvc.GetAsync(fingerPrint, Convert.ToInt32(time), new[] { "recordingids" });

            var recordings = new List <Recording>();

            foreach (var trackId in trackIds.Results)
            {
                foreach (var rec in trackId.Recordings)
                {
                    System.Threading.Thread.Sleep(400);
                    var recording = await Recording.GetAsync(rec.Id, new[] { "releases", "artists", "media", "discids" });

                    recordings.Add(recording);
                }
            }
            return(recordings);
        }
Example #11
0
        public void Test2SilenceRawFp()
        {
            short[] zeroes = new short[1024];

            ChromaContext ctx = new ChromaContext(ChromaprintAlgorithm.TEST2);
            ctx.Start(44100, 1);
            for (int i = 0; i < 130; i++)
            {
                ctx.Feed(zeroes, 1024);
            }


            ctx.Finish();
            int[] fp = ctx.GetRawFingerprint();

            Assert.AreEqual(3, fp.Length);
            Assert.AreEqual(627964279, fp[0]);
            Assert.AreEqual(627964279, fp[1]);
            Assert.AreEqual(627964279, fp[2]);
        }
Example #12
0
        public void Test2SilenceFp()
        {
            short[] zeroes = new short[1024];

            ChromaContext ctx = new ChromaContext(ChromaprintAlgorithm.TEST2);
            ctx.Start(44100, 1);

            for (int i = 0; i < 130; i++)
            {
                ctx.Feed(zeroes, 1024);
            }

            ;

            ctx.Finish();
            string fp = ctx.GetFingerprint();

            Assert.AreEqual(18, fp.Length);
            Assert.AreEqual("AQAAA0mUaEkSRZEGAA", fp);
        }
        public void Test2SilenceRawFp()
        {
            short[] zeroes = new short[1024];

            ChromaContext ctx = new ChromaContext(ChromaprintAlgorithm.TEST2);

            ctx.Start(44100, 1);
            for (int i = 0; i < 130; i++)
            {
                ctx.Feed(zeroes, 1024);
            }


            ctx.Finish();
            int[] fp = ctx.GetRawFingerprint();

            Assert.AreEqual(3, fp.Length);
            Assert.AreEqual(627964279, fp[0]);
            Assert.AreEqual(627964279, fp[1]);
            Assert.AreEqual(627964279, fp[2]);
        }
        public void Test2SilenceFp()
        {
            short[] zeroes = new short[1024];

            ChromaContext ctx = new ChromaContext(ChromaprintAlgorithm.TEST2);

            ctx.Start(44100, 1);

            for (int i = 0; i < 130; i++)
            {
                ctx.Feed(zeroes, 1024);
            }

            ctx.Finish();

            string fp   = ctx.GetFingerprint();
            int    hash = ctx.GetFingerprintHash();

            Assert.AreEqual(18, fp.Length);
            Assert.AreEqual("AQAAA0mUaEkSRZEGAA", fp);
            Assert.AreEqual(627964279, hash);
        }
Example #15
0
        /// <summary>
        /// Fingerpring the audio and send it to the AcoustID identification service for results.
        /// /// </summary>
        /// <param name="pathToAudioFile"></param>
        /// <returns>The AcoustID identification response object with the audio information if found.</returns>
        public async Task <List <LookupResponse> > ProcessAudioFile(Uri pathToAudioFile)
        {
            short[]       auData    = LoadAudioFile(pathToAudioFile);
            int           tSec      = (int)TagLib.File.Create(pathToAudioFile.LocalPath).Properties.Duration.TotalSeconds;
            ChromaContext ctx       = new ChromaContext(ChromaprintAlgorithm.TEST2);
            var           responces = new List <LookupResponse>();

            var commonSamples = new List <int> {
                8000, 11025, 16000, 22050, 44100, 48000, 88200, 96000, 176400, 192000, 352800, 384000
            };

            async Task FingerprintAndLookup(int sample, int channels)
            {
                try {
                    ctx.Start(sample, channels);
                    ctx.Feed(auData, auData.Length);
                    ctx.Finish();
                } catch {
                    Console.WriteLine("Failed on fingerprint audio sample for " + sample + "hz sampling rate " + channels + "channels.");
                }

                try {
                    var lur = await new AcoustID.Web.LookupService().GetAsync(ctx.GetFingerprint(), tSec);
                    if (lur.Results.Any())
                    {
                        responces.Add(lur);
                    }
                } catch {
                    Console.WriteLine("Failed on query audio sample for " + sample + "hz sampling rate " + channels + "channels.");
                }
            }

            foreach (var sample in commonSamples)
            {
                await FingerprintAndLookup(sample, 1);
                await FingerprintAndLookup(sample, 2);
            }
            return(responces);
        }
Example #16
0
        private void ProcessFile(string file)
        {
            if (File.Exists(file))
            {
                if (decoder.Ready)
                {
                    Task.Factory.StartNew(() =>
                    {
                        Stopwatch stopwatch = new Stopwatch();
                        stopwatch.Start();

                        ChromaContext context = new ChromaContext();
                        context.Start(decoder.SampleRate, decoder.Channels);
                        decoder.Decode(context.Consumer, 120);

                        context.Finish();

                        stopwatch.Stop();
                        ProcessFileCallback(context.GetFingerprint(), stopwatch.ElapsedMilliseconds);
                    });
                }
                Lookup(fp, dur);
            }
        }