/// <summary> /// Get track info from the filename /// </summary> /// <param name = "mintracklen">Min track length</param> /// <param name = "maxtracklen">Max track length</param> /// <param name = "filename">Filename from which to extract the requested info</param> /// <param name = "audioService">Audio audioService to read tags</param> /// <returns>Track to be analyzed further / null if the track is not eligible</returns> public static Track GetTrackInfo(int mintracklen, int maxtracklen, string filename, BassAudioService audioService) { TAG_INFO tags = audioService.GetTagInfoFromFile(filename); //get file tags string artist, title; double duration; if (tags == null) { /*The song does not contain any tags*/ artist = "Unknown"; title = "Unknown"; duration = 60; } else { /*The song contains related tags*/ artist = tags.artist; title = tags.title; duration = tags.duration; } if (String.IsNullOrEmpty(artist)) /*assign a name to music files that don't have tags*/ artist = "Unknown"; if (String.IsNullOrEmpty(title)) /*assign a title to music files that don't have tags*/ title = "Unknown"; if (duration < mintracklen || duration > maxtracklen) /*check the duration of a music file*/ return null; Track track = new Track { Artist = artist, Title = title, TrackLength = duration, Path = Path.GetFullPath(filename) }; return track; }
public void GetTagInfoFromFileTest() { string name = MethodBase.GetCurrentMethod().Name; using (BassAudioService audioService = new BassAudioService()) { TAG_INFO tags = audioService.GetTagInfoFromFile(Path.GetFullPath(PathToMp3)); Assert.IsNotNull(tags); Assert.IsNotNull(tags.artist); Assert.IsNotNull(tags.title); Assert.IsNotNull(tags.duration); } }
public void ReadMonoFromFileTest() { using (BassAudioService bass = new BassAudioService()) { string tempFile = Path.GetTempPath() + "\\" + 0 + ".wav"; bass.RecodeTheFile(PathToMp3, tempFile, 5512); float[] samples = bass.ReadMonoFromFile(PathToMp3, SampleRate); FileInfo info = new FileInfo(tempFile); long expectedSize = info.Length - WaveHeader; long actualSize = samples.Length * (BitsPerSample / 8); Assert.AreEqual(expectedSize, actualSize); } }
private void BtnResampleClick(object sender, EventArgs e) { if (string.IsNullOrEmpty(_tbPathToFile.Text)) { MessageBox.Show( Resources.SelectAPathToBeDrawn, Resources.SelectFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!File.Exists(Path.GetFullPath(_tbPathToFile.Text))) { MessageBox.Show( Resources.NoSuchFile, Resources.NoSuchFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SaveFileDialog sfd = new SaveFileDialog { Filter = Resources.FileFilterWav, FileName = Path.GetFileNameWithoutExtension(_tbPathToFile.Text) + ".wav" }; if (sfd.ShowDialog() == DialogResult.OK) { Action action = () => { using (BassAudioService bass = new BassAudioService()) { string pathToRecoded = Path.GetFullPath(sfd.FileName); bass.RecodeTheFile(_tbPathToFile.Text, pathToRecoded, (int)_nudSampleRate.Value); } }; FadeControls(false); action.BeginInvoke( (result) => { action.EndInvoke(result); FadeControls(true); MessageBox.Show( Resources.FileConverted, Resources.FileConverted, MessageBoxButtons.OK, MessageBoxIcon.Information); }, null); } }
public void CheckFingerprintCreationAlgorithmTest() { using (BassAudioService bassAudioService = new BassAudioService()) { string tempFile = Path.GetTempPath() + 0 + ".wav"; bassAudioService.RecodeTheFile(PathToMp3, tempFile, 5512); long fileSize = new FileInfo(tempFile).Length; List<bool[]> list = workUnitBuilder.BuildWorkUnit().On(PathToMp3).With(fingerprintingConfiguration). GetFingerprintsUsingService(fingerprintingServiceWithBass).Result; // One fingerprint corresponds to a granularity of 8192 samples which is 16384 bytes long expected = fileSize / (fingerprintingConfiguration.SamplesPerFingerprint * 4); Assert.AreEqual(expected, list.Count); File.Delete(tempFile); } }
public void ReadMonoFromFileUsingBothProxiesTest() { string name = MethodBase.GetCurrentMethod().Name; using (BassAudioService bassAudioService = new BassAudioService()) { using (DirectSoundAudioService directSoundAudioService = new DirectSoundAudioService()) { float[] bdata = bassAudioService.ReadMonoFromFile(PathToMp3, 5512); float[] ddata = directSoundAudioService.ReadMonoFromFile(PathToWav, 5512); for (int i = 0; i < bdata.Length; i++) { if ((Math.Abs(bdata[i] - ddata[i]) / int.MaxValue) > 1) { Assert.Fail("Data arrays are different: " + bdata[i] + ":" + ddata[i] + " at " + i); } } Assert.AreEqual(bdata.Length, ddata.Length); } } }
private void BtnDumpInfoClick(object sender, EventArgs e) { if (string.IsNullOrEmpty(_tbPathToFile.Text)) { MessageBox.Show(Resources.ErrorNoFileToAnalyze, Resources.SelectFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(_tbOutputPath.Text)) { MessageBox.Show(Resources.SelectPathToDump, Resources.SelectFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!File.Exists(Path.GetFullPath(_tbPathToFile.Text))) { MessageBox.Show(Resources.NoSuchFile, Resources.NoSuchFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (_chbCompare.Checked) { if (string.IsNullOrEmpty(_tbSongToCompare.Text)) { MessageBox.Show(Resources.ErrorNoFileToAnalyze, Resources.SelectFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } Action action = () => { using (BassAudioService audioService = new BassAudioService()) { FadeControls(false); int stride = (int)_nudStride.Value; var unitOfWork = workUnitBuilder.BuildWorkUnit().On(_tbPathToFile.Text).WithCustomConfiguration( config => { config.MinFrequency = (int)_nudFreq.Value; config.TopWavelets = (int)_nudTopWavelets.Value; config.Stride = _chbStride.Checked ? (IStride)new RandomStride(0, stride) : new StaticStride(stride); }); var sameUnitOfWork = workUnitBuilder.BuildWorkUnit().On(_tbPathToFile.Text).WithCustomConfiguration( config => { config.MinFrequency = (int)_nudFreq.Value; config.TopWavelets = (int)_nudTopWavelets.Value; config.Stride = new StaticStride(5115, 5115 / 2); }); DumpResults resultObj = new DumpResults(); string pathToInput = _tbPathToFile.Text; string pathToOutput = _tbOutputPath.Text; int hashTables = (int)_nudTables.Value; int hashKeys = (int)_nudKeys.Value; GetFingerprintSimilarity(fingerprintService, unitOfWork, sameUnitOfWork, resultObj); GetHashSimilarity(fingerprintService, hashTables, hashKeys, unitOfWork, sameUnitOfWork, resultObj); if (_chbCompare.Checked) { int comparisonStride = (int)_nudQueryStride.Value; var unitOfWorkToCompareWith = workUnitBuilder.BuildWorkUnit().On(_tbSongToCompare.Text).WithCustomConfiguration( config => { config.MinFrequency = (int)_nudFreq.Value; config.TopWavelets = (int)_nudTopWavelets.Value; config.Stride = _chbQueryStride.Checked ? (IStride)new RandomStride(0, comparisonStride) : new StaticStride(comparisonStride); }); GetFingerprintSimilarity(fingerprintService, unitOfWork, unitOfWorkToCompareWith, resultObj); } resultObj.Info.MinFrequency = (int)_nudFreq.Value; resultObj.Info.TopWavelets = (int)_nudTopWavelets.Value; resultObj.Info.StrideSize = stride; resultObj.Info.RandomStride = _chbStride.Checked; resultObj.Info.Filename = pathToInput; resultObj.ComparisonDone = _chbCompare.Checked; XmlSerializer serializer = new XmlSerializer(typeof(DumpResults)); TextWriter writer = new StreamWriter(pathToOutput); serializer.Serialize(writer, resultObj); writer.Close(); } }; action.BeginInvoke( (result) => { action.EndInvoke(result); FadeControls(true); }, null); }
private void ProcessFiles() { Action finishDel = delegate { buttonStop.Enabled = false; buttonPause.Enabled = false; buttonStartConversion.Enabled = true; stopped = false; }; Process process = new Process { StartInfo = { FileName = "ffmpeg.exe", CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, RedirectStandardInput = true, RedirectStandardError = true, RedirectStandardOutput = true, UseShellExecute = false } }; Action del = delegate { labelCurrentProcessed.Text = currentProceesedFiles.ToString(); labelSkipped.Text = skipped.ToString(); richTextBox1.AppendText(process.StandardError.ReadToEnd() + "\n"); richTextBox1.Focus(); richTextBox1.SelectionStart = richTextBox1.Text.Length; }; using (BassAudioService audioService = new BassAudioService()) { foreach (string f in fileList) { if (stopped) { Invoke(finishDel); Thread.CurrentThread.Abort(); } while (pause) { if (stopped) { Invoke(finishDel); Thread.CurrentThread.Abort(); } Thread.Sleep(1000); } TAG_INFO tags = null; try { //Read Tags from the file tags = audioService.GetTagInfoFromFile(f); } catch { skipped++; currentProceesedFiles++; Invoke(del); continue; } //Compose the output name of the wav file if (String.IsNullOrEmpty(tags.title) || tags.title.Length == 0) { //Skip file skipped++; currentProceesedFiles++; Invoke(del); continue; } string artist = ""; if (String.IsNullOrEmpty(tags.artist)) { if (tags.composer == null) { skipped++; currentProceesedFiles++; Invoke(del); continue; } artist = tags.composer; } else artist = tags.artist; string outfilename = tags.title + " + " + artist + ".wav"; string outfile = outputPath + "\\" + outfilename; string arguments = "-i \"" + f + "\" -ac 1 -ar " + samplingRate + " -ab " + bitRate + " \"" + outfile + "\""; process.StartInfo.Arguments = arguments; process.Start(); process.StandardInput.Write("n"); currentProceesedFiles++; Invoke(del); } } Invoke(finishDel); }
private void BtnDrawSignalClick(object sender, EventArgs e) { if (string.IsNullOrEmpty(_tbPathToFile.Text)) { MessageBox.Show( Resources.SelectAPathToBeDrawn, Resources.SelectFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (!File.Exists(Path.GetFullPath(_tbPathToFile.Text))) { MessageBox.Show( Resources.NoSuchFile, Resources.NoSuchFile, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } SaveFileDialog sfd = new SaveFileDialog { Filter = Resources.FileFilterJPeg, FileName = Path.GetFileNameWithoutExtension(_tbPathToFile.Text) + "_signal_" + ".jpg" }; if (sfd.ShowDialog() == DialogResult.OK) { string fullpath = Path.GetFullPath(_tbPathToFile.Text); FadeControls(false); Action action = () => { using (IAudioService proxy = new BassAudioService()) { float[] data = proxy.ReadMonoFromFile( fullpath, new DefaultFingerprintingConfiguration().SampleRate, 0, 0); Bitmap image = Imaging.GetSignalImage(data, (int)_nudWidth.Value, (int)_nudHeight.Value); image.Save(sfd.FileName, ImageFormat.Jpeg); image.Dispose(); } }; action.BeginInvoke( (result) => { FadeControls(true); action.EndInvoke(result); MessageBox.Show( Resources.ImageIsDrawn, Resources.Finished, MessageBoxButtons.OK, MessageBoxIcon.Information); }, null); } }