From cacc484f92c3289fdba15c5ee1cf8dc5bbfda03d Mon Sep 17 00:00:00 2001 From: Sergiu Ciumac Date: Thu, 3 Oct 2024 14:30:47 +0300 Subject: [PATCH] Removing NAudio from SoundFingerprinting code base. The code is not relevant anymore as we moved completely to FFmpeg audio processing for both Windows and Unix operating systems. FFmpegAudioService is available in SoundFingerprinting.Emy. It will be later moved to SoundFingerprinting core. NAudio is obsolete and not supported anymore. --- .../BlockingQueueSamplesProviderTest.cs | 53 ------------ .../NAudioSamplesProviderAdapterTest.cs | 30 ------- .../NAudioServiceTest.cs | 50 ----------- .../NAudioSoundCaptureServiceTest.cs | 39 --------- .../NAudioStreamUrlReaderTest.cs | 38 -------- .../NAudioWaveFileUtilityTest.cs | 86 ------------------- .../Play/NAudioPlayAudioFileServiceTest.cs | 62 ------------- .../Play/TestWaveStream.cs | 18 ---- .../Properties/AssemblyInfo.cs | 17 ---- ...undFingerprinting.Audio.NAudio.Test.csproj | 16 ---- .../BlockingQueueSamplesProvider.cs | 33 ------- .../INAudioFactory.cs | 20 ----- .../INAudioSourceReader.cs | 7 -- .../NAudioFactory.cs | 46 ---------- .../NAudioSamplesProviderAdapter.cs | 19 ---- .../NAudioService.cs | 41 --------- .../NAudioSoundCaptureService.cs | 48 ----------- .../NAudioSourceReader.cs | 43 ---------- .../NAudioStreamingUrlReader.cs | 44 ---------- .../NAudioTagService.cs | 27 ------ .../NAudioWaveFileUtility.cs | 45 ---------- .../Play/INAudioPlayAudioFactory.cs | 11 --- .../Play/NAudioPlayAudioFactory.cs | 18 ---- .../Play/NAudioPlayAudioFileService.cs | 36 -------- .../PlayFileAttributes.cs | 17 ---- .../Properties/AssemblyInfo.cs | 18 ---- .../SoundFingerprinting.Audio.NAudio.csproj | 35 -------- src/SoundFingerprinting.sln | 12 --- 28 files changed, 929 deletions(-) delete mode 100644 src/SoundFingerprinting.Audio.NAudio.Test/BlockingQueueSamplesProviderTest.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio.Test/NAudioSamplesProviderAdapterTest.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio.Test/NAudioServiceTest.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio.Test/NAudioSoundCaptureServiceTest.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio.Test/NAudioStreamUrlReaderTest.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio.Test/NAudioWaveFileUtilityTest.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio.Test/Play/NAudioPlayAudioFileServiceTest.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio.Test/Play/TestWaveStream.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio.Test/Properties/AssemblyInfo.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio.Test/SoundFingerprinting.Audio.NAudio.Test.csproj delete mode 100644 src/SoundFingerprinting.Audio.NAudio/BlockingQueueSamplesProvider.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/INAudioFactory.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/INAudioSourceReader.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/NAudioFactory.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/NAudioSamplesProviderAdapter.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/NAudioService.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/NAudioSoundCaptureService.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/NAudioSourceReader.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/NAudioStreamingUrlReader.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/NAudioTagService.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/NAudioWaveFileUtility.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/Play/INAudioPlayAudioFactory.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/Play/NAudioPlayAudioFactory.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/Play/NAudioPlayAudioFileService.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/PlayFileAttributes.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/Properties/AssemblyInfo.cs delete mode 100644 src/SoundFingerprinting.Audio.NAudio/SoundFingerprinting.Audio.NAudio.csproj diff --git a/src/SoundFingerprinting.Audio.NAudio.Test/BlockingQueueSamplesProviderTest.cs b/src/SoundFingerprinting.Audio.NAudio.Test/BlockingQueueSamplesProviderTest.cs deleted file mode 100644 index fe51c462d..000000000 --- a/src/SoundFingerprinting.Audio.NAudio.Test/BlockingQueueSamplesProviderTest.cs +++ /dev/null @@ -1,53 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio.Test -{ - using System; - using System.Collections.Concurrent; - using System.Threading; - using System.Threading.Tasks; - - using NUnit.Framework; - - [TestFixture] - public class BlockingQueueSamplesProviderTest - { - private readonly Random random = new Random(); - - [Test] - public void ShouldGetNextSamples() - { - var producer = new BlockingCollection(); - const int numberOfItemsToAdd = 5; - PutSamplesIntoQueueOnIrregularIntervals(producer, numberOfItemsToAdd); - - var samplesProvider = new BlockingQueueSamplesProvider(producer); - - int count = 0; - while (!producer.IsAddingCompleted) - { - var added = samplesProvider.GetNextSamples(new float[1024]); - if (count < numberOfItemsToAdd) - { - Assert.AreEqual(1024 * 4, added); - } - - count++; - } - - Assert.AreEqual(numberOfItemsToAdd + 1, count); - } - - private void PutSamplesIntoQueueOnIrregularIntervals(BlockingCollection producer, int count) - { - Task.Factory.StartNew(() => AddValues(producer, count)).ContinueWith(t => producer.CompleteAdding()); - } - - private void AddValues(BlockingCollection producer, int count) - { - for (int i = 0; i < count; ++i) - { - Thread.Sleep(random.Next(1000, 3000)); - producer.Add(new float[1024]); - } - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio.Test/NAudioSamplesProviderAdapterTest.cs b/src/SoundFingerprinting.Audio.NAudio.Test/NAudioSamplesProviderAdapterTest.cs deleted file mode 100644 index edd985cff..000000000 --- a/src/SoundFingerprinting.Audio.NAudio.Test/NAudioSamplesProviderAdapterTest.cs +++ /dev/null @@ -1,30 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio.Test -{ - using Moq; - - using global::NAudio.Wave; - - using global::NAudio.Wave.SampleProviders; - - using NUnit.Framework; - - [TestFixture] - public class NAudioSamplesProviderAdapterTest - { - [Test] - public void TestGetNextSamplesQueriesStreamCorrectly() - { - var waveProvider = new Mock(MockBehavior.Loose); - waveProvider.Setup(provider => provider.WaveFormat).Returns(WaveFormat.CreateIeeeFloatWaveFormat(5512, 1)); - var waveToSampleProvider = new Mock(MockBehavior.Strict, waveProvider.Object); - const int numberOfReadSamples = 1024; - float[] buffer = new float[numberOfReadSamples]; - waveToSampleProvider.Setup(provider => provider.Read(buffer, 0, buffer.Length)).Returns(numberOfReadSamples); - var nAudioSamplesProvider = new SoundFingerprinting.Audio.NAudio.NAudioSamplesProviderAdapter(waveToSampleProvider.Object); - - int samplesRead = nAudioSamplesProvider.GetNextSamples(buffer); - - Assert.AreEqual(numberOfReadSamples * 4, samplesRead); - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio.Test/NAudioServiceTest.cs b/src/SoundFingerprinting.Audio.NAudio.Test/NAudioServiceTest.cs deleted file mode 100644 index 16d745525..000000000 --- a/src/SoundFingerprinting.Audio.NAudio.Test/NAudioServiceTest.cs +++ /dev/null @@ -1,50 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio.Test -{ - using System.Linq; - - using Moq; - - using NUnit.Framework; - - [TestFixture] - public class NAudioServiceTest - { - private readonly Mock sourceReader = new Mock(MockBehavior.Strict); - - private NAudioService nAudioService; - - [SetUp] - public void SetUp() - { - nAudioService = new NAudioService(25, sourceReader.Object); - } - - [TearDown] - public void TearDown() - { - sourceReader.VerifyAll(); - } - - [Test] - public void TestSupportedNAudioFormats() - { - var supportedFormats = nAudioService.SupportedFormats.ToList(); - - Assert.IsTrue(supportedFormats.Contains(".mp3")); - Assert.IsTrue(supportedFormats.Contains(".wav")); - } - - [Test] - public void TestReadMonoSamplesFromFile() - { - const int secondsToRead = 10; - const int startAt = 10; - float[] samples = new float[1024]; - sourceReader.Setup(r => r.ReadMonoFromSource("path-to-audio-file", 5512, secondsToRead, startAt, 25)).Returns(samples); - - var result = nAudioService.ReadMonoSamplesFromFile("path-to-audio-file", 5512, secondsToRead, startAt); - - Assert.AreSame(samples, result.Samples); - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio.Test/NAudioSoundCaptureServiceTest.cs b/src/SoundFingerprinting.Audio.NAudio.Test/NAudioSoundCaptureServiceTest.cs deleted file mode 100644 index 942c8bc66..000000000 --- a/src/SoundFingerprinting.Audio.NAudio.Test/NAudioSoundCaptureServiceTest.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio.Test -{ - using Moq; - using Moq.Protected; - - using global::NAudio.Wave; - - using NUnit.Framework; - - [TestFixture] - [Category("RequiresWindowsDLL")] - public class NAudioSoundCaptureServiceTest - { - private readonly Mock naudioFactory = new Mock(MockBehavior.Strict); - private readonly Mock samplesAggregator = new Mock(MockBehavior.Strict); - - private NAudioSoundCaptureService soundCaptureService; - - [SetUp] - public void SetUp() - { - soundCaptureService = new NAudioSoundCaptureService(samplesAggregator.Object, naudioFactory.Object); - } - - [Test] - public void ShouldReadFromMicrophone() - { - var waveInEvent = new Mock(); - naudioFactory.Setup(factory => factory.GetWaveInEvent(5512, 1)).Returns(waveInEvent.Object); - float[] samples = new float[1024]; - const int secondsToRecord = 10; - samplesAggregator.Setup(agg => agg.ReadSamplesFromSource(It.IsAny(), secondsToRecord, 5512)).Returns(samples); - - float[] resultSamples = soundCaptureService.ReadMonoSamples(5512, secondsToRecord); - - Assert.AreSame(samples, resultSamples); - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio.Test/NAudioStreamUrlReaderTest.cs b/src/SoundFingerprinting.Audio.NAudio.Test/NAudioStreamUrlReaderTest.cs deleted file mode 100644 index d6ab9d960..000000000 --- a/src/SoundFingerprinting.Audio.NAudio.Test/NAudioStreamUrlReaderTest.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio.Test -{ - using Moq; - - using NUnit.Framework; - - [TestFixture] - public class NAudioStreamUrlReaderTest - { - private readonly Mock sourceReader = new Mock(MockBehavior.Strict); - - private NAudioStreamingUrlReader reader; - - [SetUp] - public void SetUp() - { - reader = new NAudioStreamingUrlReader(sourceReader.Object); - } - - [TearDown] - public void TearDown() - { - sourceReader.VerifyAll(); - } - - [Test] - public void TestReadMonoSamplesFromFile() - { - const int secondsToRead = 10; - float[] samples = new float[1024]; - sourceReader.Setup(r => r.ReadMonoFromSource("path-to-streaming-url", 5512, secondsToRead * 2, 0, 25)).Returns(samples); - - var result = reader.ReadMonoSamples("path-to-streaming-url", 5512, secondsToRead); - - Assert.AreEqual(samples.Length / 2, result.Length); - } - } -} \ No newline at end of file diff --git a/src/SoundFingerprinting.Audio.NAudio.Test/NAudioWaveFileUtilityTest.cs b/src/SoundFingerprinting.Audio.NAudio.Test/NAudioWaveFileUtilityTest.cs deleted file mode 100644 index 7935fa37c..000000000 --- a/src/SoundFingerprinting.Audio.NAudio.Test/NAudioWaveFileUtilityTest.cs +++ /dev/null @@ -1,86 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio.Test -{ - using System; - using System.IO; - - using Moq; - using Moq.Protected; - - using global::NAudio.MediaFoundation; - - using global::NAudio.Wave; - - using NUnit.Framework; - - [TestFixture] - public class NAudioWaveFileUtilityTest - { - private readonly Random rand = new Random((int)DateTime.Now.Ticks << 4); - private readonly Mock naudioFactory = new Mock(MockBehavior.Strict); - private NAudioWaveFileUtility waveFileUtility; - - [SetUp] - public void SetUp() - { - waveFileUtility = new NAudioWaveFileUtility(naudioFactory.Object); - } - - [Test] - public void TestWriteSamplesToWaveFile() - { - using (var stream = new MemoryStream()) - { - const int mono = 1; - var writer = new Mock(MockBehavior.Loose, stream, WaveFormat.CreateIeeeFloatWaveFormat(5512, mono)); - naudioFactory.Setup(factory => factory.GetWriter("path-to-audio-file", 5512, mono)) - .Returns(writer.Object); - const int songLengthInFloats = 16; - float[] samples = GenerateRandomFloatArray(songLengthInFloats); - writer.Setup(w => w.Close()); - - waveFileUtility.WriteSamplesToFile(samples, 5512, "path-to-audio-file"); - - var readSamples = GetWrittenSamplesInStream(stream, songLengthInFloats); - CollectionAssert.AreEqual(samples, readSamples); - } - } - - [Test] - public void TestRecodeFileToMonoWave() - { - Mock waveStream = new Mock(MockBehavior.Strict); - naudioFactory.Setup(factory => factory.GetStream("path-to-audio-file")).Returns(waveStream.Object); - const int mono = 1; - WaveFormat waveFormat = WaveFormat.CreateIeeeFloatWaveFormat(5512, mono); - waveStream.Setup(stream => stream.WaveFormat).Returns(waveFormat); - waveStream.Setup(stream => stream.Close()); - Mock resampler = new Mock(MockBehavior.Strict, waveStream.Object, waveFormat); - resampler.Protected().Setup("Dispose", new object[] { true }); - naudioFactory.Setup(factory => factory.GetResampler(waveStream.Object, 5512, mono, 25)).Returns(resampler.Object); - naudioFactory.Setup(factory => factory.CreateWaveFile("path-to-recoded-file", resampler.Object)); - - waveFileUtility.RecodeFileToMonoWave("path-to-audio-file", "path-to-recoded-file", 5512, 25); - } - - private float[] GetWrittenSamplesInStream(MemoryStream memoryStream, int length) - { - const int waveHeaderLength = 58; - memoryStream.Seek(waveHeaderLength, SeekOrigin.Begin); - const int bytesInFloat = 4; - byte[] buffer = new byte[length * bytesInFloat]; - memoryStream.Read(buffer, 0, length * bytesInFloat); - return SamplesConverter.GetFloatSamplesFromByte(length * bytesInFloat, buffer); - } - - private float[] GenerateRandomFloatArray(int length) - { - float[] result = new float[length]; - for (int i = 0; i < length; i++) - { - result[i] = (float)rand.NextDouble() * 32767; - } - - return result; - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio.Test/Play/NAudioPlayAudioFileServiceTest.cs b/src/SoundFingerprinting.Audio.NAudio.Test/Play/NAudioPlayAudioFileServiceTest.cs deleted file mode 100644 index d1710341b..000000000 --- a/src/SoundFingerprinting.Audio.NAudio.Test/Play/NAudioPlayAudioFileServiceTest.cs +++ /dev/null @@ -1,62 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio.Test.Play -{ - using Moq; - - using global::NAudio.Wave; - - using NUnit.Framework; - - using SoundFingerprinting.Audio.NAudio.Play; - - [TestFixture] - public class NAudioPlayAudioFileServiceTest - { - private NAudioPlayAudioFileService service; - - private Mock factory; - - [SetUp] - public void SetUp() - { - factory = new Mock(MockBehavior.Strict); - service = new NAudioPlayAudioFileService(factory.Object); - } - - [Test] - public void TestPlayFile() - { - Mock wavePlayer = new Mock(MockBehavior.Strict); - factory.Setup(f => f.CreateNewWavePlayer()).Returns(wavePlayer.Object); - Mock waveStream = new Mock(MockBehavior.Loose); - factory.Setup(f => f.CreateNewStreamFromFilename("path-to-file")).Returns(waveStream.Object); - wavePlayer.Setup(w => w.Init(waveStream.Object)); - wavePlayer.Setup(w => w.Play()); - - var playFileAttributes = service.PlayFile("path-to-file"); - - if (playFileAttributes is PlayFileAttributes attributes) - { - Assert.AreSame(wavePlayer.Object, attributes.WavePlayer); - Assert.AreSame(waveStream.Object, attributes.WaveStream); - } - } - - [Test] - public void TestStopPlayingFile() - { - Mock wavePlayer = new Mock(MockBehavior.Strict); - factory.Setup(f => f.CreateNewWavePlayer()).Returns(wavePlayer.Object); - Mock waveStream = new Mock(MockBehavior.Strict); - factory.Setup(f => f.CreateNewStreamFromFilename("path-to-file")).Returns(waveStream.Object); - wavePlayer.Setup(w => w.Init(waveStream.Object)); - wavePlayer.Setup(w => w.Play()); - wavePlayer.Setup(w => w.Stop()); - wavePlayer.Setup(w => w.Dispose()); - waveStream.Setup(w => w.Close()); - - var playFileAttributes = service.PlayFile("path-to-file"); - - service.StopPlayingFile(playFileAttributes); - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio.Test/Play/TestWaveStream.cs b/src/SoundFingerprinting.Audio.NAudio.Test/Play/TestWaveStream.cs deleted file mode 100644 index 0c2ee4225..000000000 --- a/src/SoundFingerprinting.Audio.NAudio.Test/Play/TestWaveStream.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio.Test.Play -{ - using global::NAudio.Wave; - - internal class TestWaveStream : WaveStream - { - public override WaveFormat WaveFormat => WaveFormat.CreateIeeeFloatWaveFormat(5512, 1); - - public override long Length => 0; - - public override long Position { get; set; } - - public override int Read(byte[] buffer, int offset, int count) - { - return 0; - } - } -} \ No newline at end of file diff --git a/src/SoundFingerprinting.Audio.NAudio.Test/Properties/AssemblyInfo.cs b/src/SoundFingerprinting.Audio.NAudio.Test/Properties/AssemblyInfo.cs deleted file mode 100644 index 9630df553..000000000 --- a/src/SoundFingerprinting.Audio.NAudio.Test/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SoundFingerprinting.Audio.NAudio.Test")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SoundFingerprinting.Audio.NAudio.Test")] -[assembly: AssemblyCopyright("Copyright © Sergiu Ciumac 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("5a5c0ae3-f864-4c73-96ec-7f9c9a338c53")] -[assembly: AssemblyVersion("8.0.0.105")] -[assembly: AssemblyInformationalVersion("8.0.0.105")] -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] diff --git a/src/SoundFingerprinting.Audio.NAudio.Test/SoundFingerprinting.Audio.NAudio.Test.csproj b/src/SoundFingerprinting.Audio.NAudio.Test/SoundFingerprinting.Audio.NAudio.Test.csproj deleted file mode 100644 index ca9d9e9d6..000000000 --- a/src/SoundFingerprinting.Audio.NAudio.Test/SoundFingerprinting.Audio.NAudio.Test.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - net6.0-windows - true - false - - - - - - - - - - - \ No newline at end of file diff --git a/src/SoundFingerprinting.Audio.NAudio/BlockingQueueSamplesProvider.cs b/src/SoundFingerprinting.Audio.NAudio/BlockingQueueSamplesProvider.cs deleted file mode 100644 index b61735764..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/BlockingQueueSamplesProvider.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - using System; - using System.Collections.Concurrent; - using System.Diagnostics; - - public class BlockingQueueSamplesProvider : ISamplesProvider - { - private readonly BlockingCollection producer; - - public BlockingQueueSamplesProvider(BlockingCollection producer) - { - this.producer = producer; - } - - public int GetNextSamples(float[] buffer) - { - try - { - float[] samples = producer.Take(); - Array.Copy(samples, buffer, samples.Length); - return samples.Length * 4; - } - catch (InvalidOperationException e) - { - // thrown when collection is marked as not allowing more additions - Trace.WriteLine(e.Message); - } - - return 0; - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio/INAudioFactory.cs b/src/SoundFingerprinting.Audio.NAudio/INAudioFactory.cs deleted file mode 100644 index d40eec1b7..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/INAudioFactory.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - using global::NAudio.MediaFoundation; - using global::NAudio.Wave; - - internal interface INAudioFactory - { - WaveStream GetStream(string pathToAudioFile); - - WaveFileWriter GetWriter(string pathToFile, int sampleRate, int numberOfChannels); - - WaveFormat GetWaveFormat(int sampleRate, int numberOfChannels); - - MediaFoundationTransform GetResampler(WaveStream streamToResample, int sampleRate, int numberOfChannels, int resamplerQuality); - - WaveInEvent GetWaveInEvent(int sampleRate, int numberOfChannels); - - void CreateWaveFile(string pathToWaveFile, IWaveProvider waveProvider); - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio/INAudioSourceReader.cs b/src/SoundFingerprinting.Audio.NAudio/INAudioSourceReader.cs deleted file mode 100644 index ea50af574..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/INAudioSourceReader.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - internal interface INAudioSourceReader - { - float[] ReadMonoFromSource(string source, int sampleRate, double secondsToRead, double startAtSecond, int resamplerQuality); - } -} \ No newline at end of file diff --git a/src/SoundFingerprinting.Audio.NAudio/NAudioFactory.cs b/src/SoundFingerprinting.Audio.NAudio/NAudioFactory.cs deleted file mode 100644 index f02019db6..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/NAudioFactory.cs +++ /dev/null @@ -1,46 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - using global::NAudio.MediaFoundation; - using global::NAudio.Wave; - - internal class NAudioFactory : INAudioFactory - { - public WaveStream GetStream(string pathToAudioFile) - { - // This class assumes media foundation libraries are installed on target machine - // In case you are running on Azure (Windows Server 2012) install Server Media Foundation feature - return new MediaFoundationReader(pathToAudioFile); - } - - public WaveFileWriter GetWriter(string pathToFile, int sampleRate, int numberOfChannels) - { - return new WaveFileWriter(pathToFile, WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, numberOfChannels)); - } - - public WaveFormat GetWaveFormat(int sampleRate, int numberOfChannels) - { - return WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, numberOfChannels); - } - - public MediaFoundationTransform GetResampler(WaveStream streamToResample, int sampleRate, int numberOfChannels, int resamplerQuality) - { - return new MediaFoundationResampler(streamToResample, GetWaveFormat(sampleRate, numberOfChannels)) - { - ResamplerQuality = resamplerQuality - }; - } - - public WaveInEvent GetWaveInEvent(int sampleRate, int numberOfChannels) - { - return new WaveInEvent - { - WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(sampleRate, numberOfChannels) - }; - } - - public void CreateWaveFile(string pathToWaveFile, IWaveProvider waveProvider) - { - WaveFileWriter.CreateWaveFile(pathToWaveFile, waveProvider); - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio/NAudioSamplesProviderAdapter.cs b/src/SoundFingerprinting.Audio.NAudio/NAudioSamplesProviderAdapter.cs deleted file mode 100644 index 508fd6cee..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/NAudioSamplesProviderAdapter.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - using global::NAudio.Wave; - - public class NAudioSamplesProviderAdapter : ISamplesProvider - { - private readonly ISampleProvider samplesProvider; - - public NAudioSamplesProviderAdapter(ISampleProvider samplesProvider) - { - this.samplesProvider = samplesProvider; - } - - public int GetNextSamples(float[] buffer) - { - return samplesProvider.Read(buffer, 0, buffer.Length) * sizeof(float); - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio/NAudioService.cs b/src/SoundFingerprinting.Audio.NAudio/NAudioService.cs deleted file mode 100644 index 677184b8e..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/NAudioService.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - using System.Collections.Generic; - - using global::NAudio.Wave; - - public class NAudioService : AudioService - { - private static readonly IReadOnlyCollection NAudioSupportedFormats = new[] { ".mp3", ".wav" }; - - private readonly INAudioSourceReader sourceReader; - private readonly int downSamplingQuality; - - public NAudioService(int downSamplingQuality = 25) : this(downSamplingQuality, new NAudioSourceReader(new SamplesAggregator(), new NAudioFactory())) - { - // no op - } - - internal NAudioService(int downSamplingQuality, INAudioSourceReader sourceReader) - { - this.sourceReader = sourceReader; - this.downSamplingQuality = downSamplingQuality; - } - - public override float GetLengthInSeconds(string file) - { - using (var mediaFoundationReader = new MediaFoundationReader(file)) - { - return (float)mediaFoundationReader.TotalTime.TotalSeconds; - } - } - - public override IReadOnlyCollection SupportedFormats => NAudioSupportedFormats; - - public override AudioSamples ReadMonoSamplesFromFile(string pathToSourceFile, int sampleRate, double seconds, double startAt) - { - var samples = sourceReader.ReadMonoFromSource(pathToSourceFile, sampleRate, seconds, startAt, downSamplingQuality); - return new AudioSamples(samples, pathToSourceFile, sampleRate); - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio/NAudioSoundCaptureService.cs b/src/SoundFingerprinting.Audio.NAudio/NAudioSoundCaptureService.cs deleted file mode 100644 index 1f7629f32..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/NAudioSoundCaptureService.cs +++ /dev/null @@ -1,48 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - using System.Collections.Concurrent; - - public class NAudioSoundCaptureService : ISoundCaptureService - { - private const int Mono = 1; - - private readonly INAudioFactory naudioFactory; - private readonly ISamplesAggregator samplesAggregator; - - public NAudioSoundCaptureService() : this(new SamplesAggregator(), new NAudioFactory()) - { - // no op - } - - internal NAudioSoundCaptureService(ISamplesAggregator samplesAggregator, INAudioFactory naudioFactory) - { - this.naudioFactory = naudioFactory; - this.samplesAggregator = samplesAggregator; - } - - public float[] ReadMonoSamples(int sampleRate, int secondsToRecord) - { - var producer = new BlockingCollection(); - float[] samples; - using (var waveIn = naudioFactory.GetWaveInEvent(sampleRate, Mono)) - { - waveIn.DataAvailable += (sender, e) => - { - var chunk = SamplesConverter.GetFloatSamplesFromByte(e.BytesRecorded, e.Buffer); - producer.Add(chunk); - }; - - waveIn.RecordingStopped += (sender, args) => producer.CompleteAdding(); - - waveIn.StartRecording(); - - samples = samplesAggregator.ReadSamplesFromSource( - new BlockingQueueSamplesProvider(producer), secondsToRecord, sampleRate); - - waveIn.StopRecording(); - } - - return samples; - } - } -} \ No newline at end of file diff --git a/src/SoundFingerprinting.Audio.NAudio/NAudioSourceReader.cs b/src/SoundFingerprinting.Audio.NAudio/NAudioSourceReader.cs deleted file mode 100644 index 226ad88da..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/NAudioSourceReader.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - using System; - - using global::NAudio.Wave; - - using global::NAudio.Wave.SampleProviders; - - internal class NAudioSourceReader : INAudioSourceReader - { - private const int Mono = 1; - - private readonly INAudioFactory naudioFactory; - private readonly ISamplesAggregator samplesAggregator; - - internal NAudioSourceReader(ISamplesAggregator samplesAggregator, INAudioFactory naudioFactory) - { - this.samplesAggregator = samplesAggregator; - this.naudioFactory = naudioFactory; - } - - public float[] ReadMonoFromSource(string source, int sampleRate, double secondsToRead, double startAtSecond, int resamplerQuality) - { - using (var stream = naudioFactory.GetStream(source)) - { - SeekToSecondInCaseIfRequired(startAtSecond, stream); - using (var resampler = naudioFactory.GetResampler(stream, sampleRate, Mono, resamplerQuality)) - { - var waveToSampleProvider = new WaveToSampleProvider(resampler); - return samplesAggregator.ReadSamplesFromSource(new NAudioSamplesProviderAdapter(waveToSampleProvider), secondsToRead, sampleRate); - } - } - } - - private void SeekToSecondInCaseIfRequired(double startAtSecond, WaveStream stream) - { - if (startAtSecond > 0) - { - stream.CurrentTime = stream.CurrentTime.Add(TimeSpan.FromSeconds(startAtSecond)); - } - } - } -} \ No newline at end of file diff --git a/src/SoundFingerprinting.Audio.NAudio/NAudioStreamingUrlReader.cs b/src/SoundFingerprinting.Audio.NAudio/NAudioStreamingUrlReader.cs deleted file mode 100644 index 7456ff3df..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/NAudioStreamingUrlReader.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - public class NAudioStreamingUrlReader : IStreamingUrlReader - { - private const int DefaultResamplerQuality = 25; - private readonly INAudioSourceReader reader; - - public NAudioStreamingUrlReader() : this(new NAudioSourceReader(new SamplesAggregator(), new NAudioFactory())) - { - // no op - } - - internal NAudioStreamingUrlReader(INAudioSourceReader reader) - { - this.reader = reader; - } - - public float[] ReadMonoSamples(string url, int sampleRate, int secondsToRead) - { - // When reading directly from URL NAudio 1.7.1 disregards Mono resampler parameter, thus reading stereo samples - // End result has to be converted to Mono in order to comply to interface requirements - // The issue has been addressed here: http://stackoverflow.com/questions/22385783/aac-stream-resampled-incorrectly though not yet resolved - float[] stereoSamples = reader.ReadMonoFromSource(url, sampleRate, secondsToRead * 2 /*for stereo request twice as much data as for mono*/, startAtSecond: 0, resamplerQuality: DefaultResamplerQuality); - return ConvertStereoSamplesToMono(stereoSamples); - } - - private float[] ConvertStereoSamplesToMono(float[] stereoSamples) - { - float[] monoSamples = new float[stereoSamples.Length / 2]; - for (int i = 0; i < stereoSamples.Length; i += 2) - { - float sum = stereoSamples[i] + stereoSamples[i + 1]; - if (sum > short.MaxValue) - { - sum = short.MaxValue; - } - - monoSamples[i / 2] = sum / 2; - } - - return monoSamples; - } - } -} \ No newline at end of file diff --git a/src/SoundFingerprinting.Audio.NAudio/NAudioTagService.cs b/src/SoundFingerprinting.Audio.NAudio/NAudioTagService.cs deleted file mode 100644 index 1bc2db2df..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/NAudioTagService.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - using global::NAudio.Wave; - - public class NAudioTagService : ITagService - { - public TagInfo GetTagInfo(string pathToAudioFile) - { - using (var reader = new MediaFoundationReader(pathToAudioFile)) - { - return new TagInfo - { - Duration = reader.TotalTime.TotalSeconds, - Album = string.Empty, - AlbumArtist = string.Empty, - Artist = pathToAudioFile, - Composer = string.Empty, - Genre = string.Empty, - IsEmpty = false, - ISRC = string.Empty, - Title = pathToAudioFile, - Year = 0 - }; - } - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio/NAudioWaveFileUtility.cs b/src/SoundFingerprinting.Audio.NAudio/NAudioWaveFileUtility.cs deleted file mode 100644 index 34031e10c..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/NAudioWaveFileUtility.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - public class NAudioWaveFileUtility : IWaveFileUtility - { - private const int Mono = 1; - private readonly INAudioFactory factory; - - public NAudioWaveFileUtility() : this(new NAudioFactory()) - { - // no op - } - - internal NAudioWaveFileUtility(INAudioFactory factory) - { - this.factory = factory; - } - - public void WriteSamplesToFile(float[] samples, int sampleRate, string destination) - { - using (var writer = factory.GetWriter(destination, sampleRate, Mono)) - { - writer.WriteSamples(samples, 0, samples.Length); - } - } - - public void WriteSamplesToFile(short[] samples, int sampleRate, string destination) - { - using (var writer = factory.GetWriter(destination, sampleRate, Mono)) - { - writer.WriteSamples(samples, 0, samples.Length); - } - } - - public void RecodeFileToMonoWave(string source, string destination, int sampleRate, int resamplerQuality) - { - using (var stream = factory.GetStream(source)) - { - using (var resampler = factory.GetResampler(stream, sampleRate, Mono, resamplerQuality)) - { - factory.CreateWaveFile(destination, resampler); - } - } - } - } -} \ No newline at end of file diff --git a/src/SoundFingerprinting.Audio.NAudio/Play/INAudioPlayAudioFactory.cs b/src/SoundFingerprinting.Audio.NAudio/Play/INAudioPlayAudioFactory.cs deleted file mode 100644 index 697d14ce6..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/Play/INAudioPlayAudioFactory.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio.Play -{ - using global::NAudio.Wave; - - internal interface INAudioPlayAudioFactory - { - IWavePlayer CreateNewWavePlayer(); - - WaveStream CreateNewStreamFromFilename(string fileName); - } -} \ No newline at end of file diff --git a/src/SoundFingerprinting.Audio.NAudio/Play/NAudioPlayAudioFactory.cs b/src/SoundFingerprinting.Audio.NAudio/Play/NAudioPlayAudioFactory.cs deleted file mode 100644 index 31542b6aa..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/Play/NAudioPlayAudioFactory.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio.Play -{ - using global::NAudio.Wave; - - internal class NAudioPlayAudioFactory : INAudioPlayAudioFactory - { - public IWavePlayer CreateNewWavePlayer() - { - return new WaveOut(); - } - - public WaveStream CreateNewStreamFromFilename(string fileName) - { - var reader = new MediaFoundationReader(fileName); - return new WaveChannel32(reader); - } - } -} \ No newline at end of file diff --git a/src/SoundFingerprinting.Audio.NAudio/Play/NAudioPlayAudioFileService.cs b/src/SoundFingerprinting.Audio.NAudio/Play/NAudioPlayAudioFileService.cs deleted file mode 100644 index 67da7f950..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/Play/NAudioPlayAudioFileService.cs +++ /dev/null @@ -1,36 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio.Play -{ - public class NAudioPlayAudioFileService : IPlayAudioFileService - { - private readonly INAudioPlayAudioFactory audioFactory; - - public NAudioPlayAudioFileService(): this(new NAudioPlayAudioFactory()) - { - } - - internal NAudioPlayAudioFileService(INAudioPlayAudioFactory audioFactory) - { - this.audioFactory = audioFactory; - } - - public object PlayFile(string pathToFile) - { - var wavePlayer = audioFactory.CreateNewWavePlayer(); - var waveStream = audioFactory.CreateNewStreamFromFilename(pathToFile); - wavePlayer.Init(waveStream); - wavePlayer.Play(); - return new PlayFileAttributes(wavePlayer, waveStream); - } - - public void StopPlayingFile(object playFileAttributes) - { - if (playFileAttributes is PlayFileAttributes attributes) - { - attributes.WavePlayer.Stop(); - attributes.WaveStream.Close(); - attributes.WavePlayer.Dispose(); - attributes.WaveStream.Dispose(); - } - } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio/PlayFileAttributes.cs b/src/SoundFingerprinting.Audio.NAudio/PlayFileAttributes.cs deleted file mode 100644 index 8b3db8eb9..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/PlayFileAttributes.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace SoundFingerprinting.Audio.NAudio -{ - using global::NAudio.Wave; - - public class PlayFileAttributes - { - public PlayFileAttributes(IWavePlayer wavePlayer, WaveStream waveStream) - { - WavePlayer = wavePlayer; - WaveStream = waveStream; - } - - public IWavePlayer WavePlayer { get; private set; } - - public WaveStream WaveStream { get; private set; } - } -} diff --git a/src/SoundFingerprinting.Audio.NAudio/Properties/AssemblyInfo.cs b/src/SoundFingerprinting.Audio.NAudio/Properties/AssemblyInfo.cs deleted file mode 100644 index 5d65a91bf..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("SoundFingerprinting.Audio.NAudio")] -[assembly: AssemblyDescription("NAudio extension library for SoundFingerprinting framework. SoundFingerprinting default library is designed to read only raw wave files. This extension provides the ability to read all files supported by NAudio media foundation framework. Since NAudio depends on Windows native calls, this extension can only be run on Windows environment.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Sergiu Ciumac")] -[assembly: AssemblyProduct("SoundFingerprinting.Audio.NAudio")] -[assembly: AssemblyCopyright("Copyright © Sergiu Ciumac 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] -[assembly: ComVisible(false)] -[assembly: Guid("8750fb98-a464-4917-8489-19cc756b4d68")] -[assembly: AssemblyVersion("8.0.0.105")] -[assembly: AssemblyInformationalVersion("8.0.0.105")] -[assembly: InternalsVisibleTo("SoundFingerprinting.Audio.NAudio.Test")] -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] diff --git a/src/SoundFingerprinting.Audio.NAudio/SoundFingerprinting.Audio.NAudio.csproj b/src/SoundFingerprinting.Audio.NAudio/SoundFingerprinting.Audio.NAudio.csproj deleted file mode 100644 index 7d4e01f38..000000000 --- a/src/SoundFingerprinting.Audio.NAudio/SoundFingerprinting.Audio.NAudio.csproj +++ /dev/null @@ -1,35 +0,0 @@ - - - netstandard2.0 - false - Sergiu Ciumac - 8.0.0 - https://github.com/AddictedCS/soundfingerprinting - https://github.com/AddictedCS/soundfingerprinting - git - NAudio extension library for SoundFingerprinting framework. This extension provides the ability to read all files supported by NAudio media foundation framework. Since NAudio depends on Windows native calls, this extension can execute only in Windows environment. - Audio Identification Fingerprinting Digital Signal Processing Music Recognition Data Mining Content Sound Shazam - - Version 8.0.0 comes as a version upgrade to support SoundFingerprinting core library. - More details on why you may need SoundFingerprinting.Audio.NAudio visit this page: https://github.com/AddictedCS/soundfingerprinting/wiki/Audio-Services - - latest - true - license.txt - soundfingerprinting.png - - - - - - - - True - - - - True - - - - \ No newline at end of file diff --git a/src/SoundFingerprinting.sln b/src/SoundFingerprinting.sln index 6b7b2d76b..df5488cc0 100644 --- a/src/SoundFingerprinting.sln +++ b/src/SoundFingerprinting.sln @@ -9,10 +9,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoundFingerprinting", "Soun EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{73D53E1C-FB16-4B8C-8EAA-70E170228C51}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoundFingerprinting.Audio.NAudio", "SoundFingerprinting.Audio.NAudio\SoundFingerprinting.Audio.NAudio.csproj", "{73A3FEE8-13EE-4EEB-9DB2-E52A30C8467A}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoundFingerprinting.Audio.NAudio.Test", "SoundFingerprinting.Audio.NAudio.Test\SoundFingerprinting.Audio.NAudio.Test.csproj", "{AE1865DB-C8D2-48E8-BB00-551D9D858C37}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,14 +23,6 @@ Global {56EB1986-589C-4DA9-B961-5833BB4A7816}.Debug|Any CPU.Build.0 = Debug|Any CPU {56EB1986-589C-4DA9-B961-5833BB4A7816}.Release|Any CPU.ActiveCfg = Release|Any CPU {56EB1986-589C-4DA9-B961-5833BB4A7816}.Release|Any CPU.Build.0 = Release|Any CPU - {73A3FEE8-13EE-4EEB-9DB2-E52A30C8467A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {73A3FEE8-13EE-4EEB-9DB2-E52A30C8467A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {73A3FEE8-13EE-4EEB-9DB2-E52A30C8467A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {73A3FEE8-13EE-4EEB-9DB2-E52A30C8467A}.Release|Any CPU.Build.0 = Release|Any CPU - {AE1865DB-C8D2-48E8-BB00-551D9D858C37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AE1865DB-C8D2-48E8-BB00-551D9D858C37}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AE1865DB-C8D2-48E8-BB00-551D9D858C37}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AE1865DB-C8D2-48E8-BB00-551D9D858C37}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE