/// <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); }
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(); 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); }
/// <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); }