Esempio n. 1
0
        public void CreateFingerprintsFromFileAndFromAudioSamplesAndGetTheSameResultTest()
        {
            const int SecondsToProcess = 20;
            const int StartAtSecond    = 15;

            using (var audioService = new BassAudioService())
            {
                float[] samples = audioService.ReadMonoFromFile(PathToMp3, SampleRate, SecondsToProcess, StartAtSecond);

                var hashDatasFromFile = fingerprintCommandBuilderWithBass
                                        .BuildFingerprintCommand()
                                        .From(PathToMp3, SecondsToProcess, StartAtSecond)
                                        .WithDefaultFingerprintConfig()
                                        .Hash()
                                        .Result;

                var hashDatasFromSamples = fingerprintCommandBuilderWithBass
                                           .BuildFingerprintCommand()
                                           .From(samples)
                                           .WithDefaultFingerprintConfig()
                                           .Hash()
                                           .Result;

                AssertHashDatasAreTheSame(hashDatasFromFile, hashDatasFromSamples);
            }
        }
Esempio n. 2
0
 public void ReadMonoFromFileTest()
 {
     using (BassAudioService bassAudioService = new BassAudioService())
     {
         string tempFile = string.Format(@"{0}{1}", Path.GetTempPath(), "0.wav");
         bassAudioService.RecodeFileToMonoWave(PathToMp3, tempFile, SampleRate);
         float[]  samples      = bassAudioService.ReadMonoFromFile(PathToMp3, SampleRate);
         FileInfo info         = new FileInfo(tempFile);
         long     expectedSize = info.Length - WaveHeader;
         long     actualSize   = samples.Length * (BitsPerSample / 8);
         Assert.AreEqual(expectedSize, actualSize);
     }
 }
Esempio n. 3
0
        public void ReadMonoFromFileThrowsExceptionInCaseIfNoStreamIsCreated()
        {
            bassServiceProxy.Setup(proxy => proxy.GetLastError()).Returns("Could not create stream from specified path");

            bassServiceProxy.Setup(
                proxy =>
                proxy.CreateStream(
                    "path-to-audio-file",
                    BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_MONO | BASSFlag.BASS_SAMPLE_FLOAT)).Returns(0);

            bassAudioService.ReadMonoFromFile("path-to-audio-file", 5512);
        }
Esempio n. 4
0
        public void ComparePreStoredSameplesWithCurrentlyReadAudioSamples()
        {
            BinaryFormatter serializer = new BinaryFormatter();

            using (Stream stream = new FileStream(PathToSamples, FileMode.Open, FileAccess.Read))
            {
                float[] samples = (float[])serializer.Deserialize(stream);
                using (BassAudioService bassAudioService = new BassAudioService())
                {
                    float[] readSamples = bassAudioService.ReadMonoFromFile(PathToMp3, SampleRate);
                    Assert.AreEqual(samples.Length, readSamples.Length);
                    for (int i = 0; i < samples.Length; i++)
                    {
                        Assert.IsTrue(Math.Abs(samples[i] - readSamples[i]) < 0.0000001);
                    }
                }
            }
        }
Esempio n. 5
0
        public void CompareReadingFromASpecificPartOfTheSong()
        {
            const int SecondsToRead = 10;
            const int StartAtSecond = 20;
            const int AcceptedError = 5;

            BinaryFormatter serializer = new BinaryFormatter();

            using (Stream stream = new FileStream(PathToSamples, FileMode.Open, FileAccess.Read))
            {
                float[] samples         = (float[])serializer.Deserialize(stream);
                float[] subsetOfSamples = GetSubsetOfSamplesFromFullSong(samples, SecondsToRead, StartAtSecond);

                using (BassAudioService bassAudioService = new BassAudioService())
                {
                    float[] readSamples = bassAudioService.ReadMonoFromFile(PathToMp3, SampleRate, SecondsToRead, StartAtSecond);
                    Assert.AreEqual(subsetOfSamples.Length, readSamples.Length);
                    Assert.IsTrue(Math.Abs(subsetOfSamples.Sum(s => Math.Abs(s)) - readSamples.Sum(s => Math.Abs(s))) < AcceptedError, "Seek is working wrong!");
                }
            }
        }