Browse Source

import POC without const paths

Coder 7 months ago
parent
commit
8e88457a81

+ 4 - 0
.gitignore

@@ -1,3 +1,7 @@
+# project specific
+
+*.ignore.cs
+
 # ---> C Sharp
 # Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
 [Bb]in/

+ 6 - 1
BMP.sln

@@ -7,7 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bmp.Poc", "Bmp.Poc\Bmp.Poc.
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bmp.Core", "Bmp.Core\Bmp.Core.csproj", "{B3AD1B0C-F2C6-4425-B172-933CA3E63907}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bmp.WinForms", "Bmp.WinForms\Bmp.WinForms.csproj", "{114D7388-AA14-41C7-9DF9-8759F48FE137}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bmp.WinForms", "Bmp.WinForms\Bmp.WinForms.csproj", "{114D7388-AA14-41C7-9DF9-8759F48FE137}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "解决方案项", "解决方案项", "{6BBF8CFA-2FBF-442A-99E6-7A6CF83B0D88}"
+	ProjectSection(SolutionItems) = preProject
+		.gitignore = .gitignore
+	EndProjectSection
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution

+ 19 - 0
Bmp.Poc/Bmp.Poc.csproj

@@ -0,0 +1,19 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+	<PropertyGroup>
+		<OutputType>Exe</OutputType>
+		<TargetFramework>net8-windows</TargetFramework>
+		<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
+		<LangVersion>latest</LangVersion>
+	</PropertyGroup>
+
+	<ItemGroup>
+		<PackageReference Include="NAudio" Version="2.2.0" />
+	</ItemGroup>
+
+	<ItemGroup>
+	  <ProjectReference Include="..\Bmp.Core\Bmp.Core.csproj" />
+	</ItemGroup>
+
+
+</Project>

+ 34 - 0
Bmp.Poc/PoCs/PocAsioDFFPlay.cs

@@ -0,0 +1,34 @@
+using Bmp.Core.Playback.Inputs;
+using System.Threading;
+using System;
+using NAudio.Wave;
+using AsioOut = Bmp.Core.Playback.Outputs.NAudioASIO.AsioOut;
+
+namespace Bmp.Poc.PoCs;
+
+internal static class PocAsioDFFPlay
+{
+    public static void MainFunc()
+    {
+        var dffFilePath =Const.FileDff;
+        var asioDriverName = "Creative SB USB DSD ASIO Device";
+
+        var inputSource = InputSourceProvider.CreateWaveStream(dffFilePath);
+        var outputDevice = new AsioOut(asioDriverName);
+        outputDevice.SetNativeDsd();
+
+        outputDevice.Init(inputSource);
+        outputDevice.Play();
+
+        while (outputDevice.PlaybackState == PlaybackState.Playing)
+        {
+            Console.WriteLine($"{inputSource.CurrentTime}/{inputSource.TotalTime}");
+            Thread.Sleep(3000);
+            outputDevice.Pause();
+            inputSource.CurrentTime = inputSource.CurrentTime.Add(TimeSpan.FromSeconds(1));
+            Thread.Sleep(100);
+            outputDevice.Play();
+        }
+
+    }
+}

+ 29 - 0
Bmp.Poc/PoCs/PocAsioDSDFuture.cs

@@ -0,0 +1,29 @@
+using Bmp.Core.Playback.Outputs.NAudioASIO;
+
+namespace Bmp.Poc.PoCs;
+
+internal static class PocAsioDSDFuture
+{
+    public static void MainFunc()
+    {
+        var asioDriverName = "Creative SB USB DSD ASIO Device";
+
+        var ao = new AsioOut(asioDriverName);
+
+        var flagPCM0 = ao.Driver.Future_GetIoFormat_Is_PCM();
+        var flagDSD0 = ao.Driver.Future_GetIoFormat_Is_DSD();
+
+        ao.Driver.Future_SetIoFormat_DSD();
+
+        var flagDSD1 = ao.Driver.Future_GetIoFormat_Is_DSD();
+        var flagPCM1 = ao.Driver.Future_GetIoFormat_Is_PCM();
+
+        if (flagDSD1)
+        {
+            var flag2822400 = ao.Driver.IsSampleRateSupported(2822400);
+            if (flag2822400) ao.Driver.SetSampleRate(2822400, false);
+        }
+
+        ao.Dispose();
+    }
+}

+ 48 - 0
Bmp.Poc/PoCs/PocAsioDSDStart.cs

@@ -0,0 +1,48 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Threading;
+using Bmp.Core.Playback.Outputs.NAudioASIO;
+
+namespace Bmp.Poc.PoCs;
+
+internal static class PocAsioDSDStart
+{
+    public static void MainFunc()
+    {
+        var asioDriverName = "Creative SB USB DSD ASIO Device";
+
+        var drv = new AsioDriverExt(asioDriverName);
+        drv.Future_SetIoFormat_DSD();
+        var sampleRate = 2822400;
+
+        var flagDSD1 = drv.Future_GetIoFormat_Is_DSD();
+        if (flagDSD1)
+        {
+            var flag = drv.IsSampleRateSupported(sampleRate);
+            if (flag) drv.SetSampleRate(sampleRate, false);
+        }
+
+        var channels = 2;
+        var nbSamples = drv.CreateBuffers(channels, 0, false);
+        var bufSize = (int)(nbSamples * channels * 1.0 / 8);
+        var buf = new byte[bufSize];
+
+        var rng = new Random();
+        drv.FillBufferCallback = (inputChannels, outputChannels) =>
+        {
+            for (int i = 0; i < channels; i++)
+            {
+                rng.NextBytes(buf);
+                Marshal.Copy(buf, 0, outputChannels[i], bufSize);
+            }
+
+        };
+
+        drv.Start();
+        while (true)
+        {
+            Thread.Sleep(3000);
+        }
+    }
+
+}

+ 90 - 0
Bmp.Poc/PoCs/PocAsioDSFPlay.cs

@@ -0,0 +1,90 @@
+using System;
+using System.Linq.Expressions;
+using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Channels;
+using Bmp.Core.Playback.Inputs;
+using Bmp.Core.Playback.Outputs.NAudioASIO;
+
+namespace Bmp.Poc.PoCs;
+
+internal static class PocAsioDSFPlay
+{
+    public static void MainFunc()
+    {
+        var dsfFilePath = Const.FileDsf;
+        var asioDriverName = "Creative SB USB DSD ASIO Device";
+
+        var dsfStream = new DsfSourceStream(dsfFilePath);
+
+        var drv = new AsioDriverExt(asioDriverName);
+        drv.Future_SetIoFormat_DSD();
+
+        var flagDSD1 = drv.Future_GetIoFormat_Is_DSD();
+        if (flagDSD1)
+        {
+            var flag = drv.IsSampleRateSupported(dsfStream.SampleRate);
+            if (flag) drv.SetSampleRate(dsfStream.SampleRate, false);
+            else throw new NotSupportedException("Failure to set sample rate");
+        }
+        else
+        {
+            throw new NotSupportedException("Device is not support DSD");
+        }
+
+        var nbSamples = drv.CreateBuffers(dsfStream.ChannelNum, 0, false);
+        var outputBufBytes = nbSamples / 8;
+
+        var channelBlockBuf = new byte[dsfStream.BlockSizePerChannel * dsfStream.ChannelNum];
+        var channelOffset = 0;
+
+        //生产者-消费者 模式, 结束检测
+
+        bool ReadBlock()
+        {
+            var readCount = 0;
+            do
+            {
+                var read = dsfStream.Read(channelBlockBuf, readCount, channelBlockBuf.Length - readCount);
+                if (read == 0) return false;
+
+                readCount += read;
+            } while (readCount < channelBlockBuf.Length);
+
+            return true;
+        }
+
+        ReadBlock();
+
+        drv.FillBufferCallback = (inputChannels, outputChannels) =>
+        {
+            for (int iBuf = 0; iBuf < outputBufBytes; iBuf++)
+            {
+                for (int ich = 0; ich < dsfStream.ChannelNum; ich++)
+                {
+                    Marshal.WriteByte(outputChannels[ich] + iBuf, channelBlockBuf[dsfStream.BlockSizePerChannel * ich + channelOffset]);
+                }
+
+                channelOffset++;
+
+                if (channelOffset >= dsfStream.BlockSizePerChannel)
+                {
+                    if (!ReadBlock())
+                    {
+                        drv.Stop(); //END
+                        return;
+                    }
+                    channelOffset = 0;
+                }
+            }
+        };
+
+        drv.Start();
+        while (true)
+        {
+            Console.WriteLine($"{dsfStream.CurrentTime}");
+            Thread.Sleep(3000);
+            dsfStream.CurrentTime += TimeSpan.FromSeconds(-1);
+        }
+    }
+}

+ 54 - 0
Bmp.Poc/PoCs/PocAsioFFMpegHttpSeekingPlayback.cs

@@ -0,0 +1,54 @@
+// See https://aka.ms/new-console-template for more information
+
+using System;
+using System.Threading;
+using Bmp.Core.Common.Net;
+using Bmp.Core.NAudioExt;
+using Bmp.Core.Playback.Inputs;
+using NAudio.Wave;
+using AsioOut = Bmp.Core.Playback.Outputs.NAudioASIO.AsioOut;
+using static Bmp.Poc.Const;
+
+namespace Bmp.Poc.PoCs;
+
+internal class PocAsioFFMpegHttpSeekingPlayback
+{
+    public static void MainFunc()
+    {
+        var asioDriverName = "Creative SB USB RT ASIO Device";
+
+        var shs = new SeekableHttpStream(UrlFlac24Bit96Khz);
+        var source = new FFMPEGAudioReader(shs);
+        //var source = new NAudioFFMPEGAudioReader(UrlFlac24Bit96Khz);
+
+        var sourceBitPerRawSample = source.BitPerRawSample;
+
+        var vdWrap = new VisualizeDataMiddleWrap(source);
+        var vdSourceBitPerRawSample = source.BitPerRawSample;
+
+
+        var driverNames = AsioOut.GetDriverNames();
+        var driverIndex = Array.IndexOf(driverNames, asioDriverName);
+
+        var outputDevice = new AsioOut(driverIndex);
+
+        vdWrap.DataTransferred += (_, args) =>
+        {
+            Console.WriteLine($"{DateTime.Now:HH:mm:ss.ff} {nameof(vdWrap.DataTransferred)}:{args.Bytes.Length}");
+        };
+
+        outputDevice.Init(vdWrap);
+
+        outputDevice.Play();
+
+        while (outputDevice.PlaybackState == PlaybackState.Playing)
+        {
+            Console.WriteLine($"{source.CurrentTime}/{source.TotalTime}");
+            Thread.Sleep(3000);
+            outputDevice.Pause();
+            source.CurrentTime = source.CurrentTime.Add(TimeSpan.FromSeconds(1));
+            Thread.Sleep(100);
+            outputDevice.Play();
+        }
+    }
+}

+ 95 - 0
Bmp.Poc/PoCs/PocAsioFreqBit.cs

@@ -0,0 +1,95 @@
+using System;
+using System.Linq;
+using System.Threading;
+using Bmp.Core.Playback.Inputs;
+using Bmp.Core.Playback.Outputs.NAudioASIO;
+using NAudio.Wave;
+using AsioOut = Bmp.Core.Playback.Outputs.NAudioASIO.AsioOut;
+using static Bmp.Poc.Const;
+
+namespace Bmp.Poc.PoCs;
+
+internal static class PocAsioFreqBit
+{
+    public static void MainFunc()
+    {
+        var asioDriverName = "Creative SB USB RT ASIO Device";
+
+        AsioDriverExt driver;
+
+        driver = new AsioDriverExt(asioDriverName);
+        var flag24000 = driver.IsSampleRateSupported(24000);
+        var flag256000 = driver.IsSampleRateSupported(256000);
+
+        var flag44100 = driver.IsSampleRateSupported(44100);
+        var flag48000 = driver.IsSampleRateSupported(48000);
+        var flag88200 = driver.IsSampleRateSupported(88200);
+        var flag96000 = driver.IsSampleRateSupported(96000);
+        var flag192000 = driver.IsSampleRateSupported(192000);
+        var flag384000 = driver.IsSampleRateSupported(384000);
+        driver.ReleaseDriver();
+
+        driver = new AsioDriverExt(asioDriverName);
+        driver.SetSampleRate(44100);
+        var sampleRate44100 = driver.GetSampleRate();
+        var bit44100 = driver.Capabilities.OutputChannelInfos.First().type; //32
+        driver.ReleaseDriver();
+
+        driver = new AsioDriverExt(asioDriverName);
+        driver.SetSampleRate(48000);
+        var sampleRate48000 = driver.GetSampleRate();
+        var bit48000 = driver.Capabilities.OutputChannelInfos.First().type; //24
+        driver.ReleaseDriver();
+
+        driver = new AsioDriverExt(asioDriverName);
+        driver.SetSampleRate(88200);
+        var sampleRate88200 = driver.GetSampleRate();
+        var bit88200 = driver.Capabilities.OutputChannelInfos.First().type; //32
+        driver.ReleaseDriver();
+
+        driver = new AsioDriverExt(asioDriverName);
+        driver.SetSampleRate(96000);
+        var sampleRate96000 = driver.GetSampleRate();
+        var bit96000 = driver.Capabilities.OutputChannelInfos.First().type; //24
+        driver.ReleaseDriver();
+
+        driver = new AsioDriverExt(asioDriverName);
+        driver.SetSampleRate(192000);
+        driver.ReleaseDriver();
+
+        driver = new AsioDriverExt(asioDriverName);
+        var sampleRate192000 = driver.GetSampleRate();
+        var bit192000 = driver.Capabilities.OutputChannelInfos.First().type; //24
+        driver.ReleaseDriver();
+
+        driver = new AsioDriverExt(asioDriverName);
+        driver.SetSampleRate(384000);
+        var sampleRate384000 = driver.GetSampleRate();
+        var bit384000 = driver.Capabilities.OutputChannelInfos.First().type; //32
+        driver.ReleaseDriver();
+
+        var source = new FFMPEGAudioReader(UrlFlac24Bit96Khz);
+
+        var driverNames = AsioOut.GetDriverNames();
+        var driverIndex = Array.IndexOf(driverNames, asioDriverName);
+
+        var outputDevice = new AsioOut(driverIndex);
+        var x = outputDevice.IsSampleRateSupported(source.WaveFormat.SampleRate);
+
+        outputDevice.AudioAvailable += delegate { Console.WriteLine("AudioAvailable"); };
+        outputDevice.DriverResetRequest += delegate { Console.WriteLine("DriverResetRequest"); };
+
+        outputDevice.Init(source);
+
+        outputDevice.Play();
+
+        while (outputDevice.PlaybackState == PlaybackState.Playing)
+        {
+            Console.WriteLine($"{source.CurrentTime}/{source.TotalTime}");
+            Thread.Sleep(5000);
+            outputDevice.Pause();
+            source.CurrentTime = source.CurrentTime.Add(TimeSpan.FromSeconds(-1));
+            outputDevice.Play();
+        }
+    }
+}

+ 40 - 0
Bmp.Poc/PoCs/PocAsioNativeDSDOut.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using Bmp.Core.Playback.Inputs;
+using Bmp.Core.Playback.Outputs.NAudioASIO;
+using NAudio.Wave;
+using AsioOut = Bmp.Core.Playback.Outputs.NAudioASIO.AsioOut;
+
+namespace Bmp.Poc.PoCs
+{
+    internal class PocAsioNativeDSDOut
+    {
+        public static void MainFunc()
+        {
+            var dsfFilePath = Const.FileDsf;
+            var asioDriverName = "Creative SB USB DSD ASIO Device";
+
+            var inputSource = new DsfSourceStream(dsfFilePath);
+            var outputDevice = new AsioOut(asioDriverName);
+            outputDevice.SetNativeDsd();
+
+            outputDevice.Init(inputSource);
+
+            outputDevice.Play();
+
+            while (outputDevice.PlaybackState == PlaybackState.Playing)
+            {
+                Console.WriteLine($"{inputSource.CurrentTime}/{inputSource.TotalTime}");
+                Thread.Sleep(3000);
+                //outputDevice.Pause();
+                inputSource.CurrentTime = inputSource.CurrentTime.Add(TimeSpan.FromSeconds(30));
+                //Thread.Sleep(100);
+                //outputDevice.Play();
+            }
+        }
+    }
+}

+ 31 - 0
Bmp.Poc/PoCs/PocAsioRateScan.cs

@@ -0,0 +1,31 @@
+using System.Collections.Generic;
+using System.Linq;
+using Bmp.Core.Playback.Outputs.NAudioASIO;
+using Bmp.Core.Playback.Outputs.NAudioASIO.Originals;
+
+namespace Bmp.Poc.PoCs;
+
+internal class PocAsioRateScan
+{
+    public static void MainFunc()
+    {
+        var asioDriverName = "Creative SB USB RT ASIO Device";
+
+        var driver = new AsioDriverExt(asioDriverName);
+
+        var lstSupports = new List<int>();
+        for (var i = 1; i <= 1024000; i++)
+        {
+            if (driver.IsSampleRateSupported(i)) { lstSupports.Add(i); }
+        }
+
+        var dic = new Dictionary<int, AsioSampleType>();
+        foreach (var support in lstSupports)
+        {
+            driver.SetSampleRate(support);
+            dic[support] = driver.Capabilities.OutputChannelInfos.First().type;
+        }
+
+        var bp = 0;
+    }
+}

+ 24 - 0
Bmp.Poc/PoCs/PocCsCoreFFMPEGDecodeBit.cs

@@ -0,0 +1,24 @@
+using Bmp.Core.Playback.Inputs;
+using static Bmp.Poc.Const;
+
+namespace Bmp.Poc.PoCs;
+
+internal class PocCsCoreFFMPEGDecodeBit
+{
+    public static void MainFunc()
+    {
+        //var source1 = new NAudioFFMPEGAudioReader(UrlFlac24Bit96Khz);
+        //var rawBit = source1.BitPerRawSample; //24
+        //var decodeBit = source1.WaveFormat.BitsPerSample; //32
+
+        //var source2 = new FFMPEGAudioReader(UrlFlac24Bit48Khz); // 32bit(24)
+        //var source3 = new FFMPEGAudioReader(UrlFlac16Bit44Khz); // 16bit(16)
+
+        //var source4 = new FFMPEGAudioReader(UrlFlac8Bit24Khz);  // 16bit(8)
+        //var source4F = new FFMPEGAudioReader(FileFlac8Bit24Khz);  // 16bit(8)
+
+        //var source5 = new FFMPEGAudioReader(UrlMp3);  // 16bit
+        var source6 = new FFMPEGAudioReader(UrlM4A);  // 32bit
+        //var source7 = new FFMPEGAudioReader(UrlOgg);  // 32bit
+    }
+}

+ 14 - 0
Bmp.Poc/PoCs/PocCsCoreFFMPEGDecoderMeta.cs

@@ -0,0 +1,14 @@
+using Bmp.Core.FFMpeg.CsCorePorts.FFMpegWrap;
+using static Bmp.Poc.Const;
+
+namespace Bmp.Poc.PoCs;
+
+internal static class PocCsCoreFFMPEGDecoderMeta
+{
+    public static void MainFunc()
+    {
+        var decoder = new FfmpegDecoder(FileFlac);
+        var meta = decoder.Metadata;
+        var pics = decoder.AttachedPics;
+    }
+}

+ 31 - 0
Bmp.Poc/PoCs/PocNAudioOutDevices.cs

@@ -0,0 +1,31 @@
+using Bmp.Core.Playback.Outputs;
+
+namespace Bmp.Poc.PoCs;
+
+internal static class PocNAudioOutDevices
+{
+    public static void MainFunc()
+    {
+        var outputDevices = OutputDeviceProvider.GetAllSupportedDevices();
+
+        var bp = 0;
+        //var allAsioDevice = AsioOut.GetDriverNames();
+        //var asioOut = new Bmp.Core.Outputs.NAudioASIO.AsioOut(allAsioDevice.First());
+
+        //var allMmDevices = new MMDeviceEnumerator().EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active).ToArray();
+        //var wasapiOut = new WasapiOut(allMmDevices.First(), AudioClientShareMode.Shared, false, 100);
+
+        //var wavOutDeviceCount = WaveOut.DeviceCount;
+        //var waveOutDevices = Enumerable.Range(0, wavOutDeviceCount).Select(WaveOut.GetCapabilities).ToArray();
+        //var x = new WaveOut();
+
+        //var waveOutEvent = new WaveOutEvent();
+
+        //var directSoundDeviceInfos = DirectSoundOut.Devices.ToArray();
+        //var dsOut = new DirectSoundOut(directSoundDeviceInfos.First().Guid);
+
+        //var numberOfMidiDevices = MidiOut.NumberOfDevices;
+        //var midiDevices = Enumerable.Range(0, numberOfMidiDevices).Select(MidiOut.DeviceInfo).ToArray();
+        //var midiOut = new MidiOut(0);
+    }
+}

+ 13 - 0
Bmp.Poc/PoCs/PocReadDff.cs

@@ -0,0 +1,13 @@
+using Bmp.Core.Playback.Inputs;
+
+namespace Bmp.Poc.PoCs;
+
+internal static class PocReadDff
+{
+    public static void MainFunc()
+    {
+        var dsfFilePath =Const.FileDff;
+        var dsfStream = new DffSourceStream(dsfFilePath);
+        var dur = dsfStream.TotalTime;
+    }
+}

+ 13 - 0
Bmp.Poc/PoCs/PocReadDsf.cs

@@ -0,0 +1,13 @@
+using Bmp.Core.Playback.Inputs;
+
+namespace Bmp.Poc.PoCs;
+
+internal static class PocReadDsf
+{
+    public static void MainFunc()
+    {
+        var dsfFilePath = Const.FileDsf;
+        var dsfStream = new DsfSourceStream(dsfFilePath);
+        var dur = dsfStream.TotalTime;
+    }
+}

+ 18 - 0
Bmp.Poc/Progarm.cs

@@ -0,0 +1,18 @@
+using System;
+using Bmp.Poc.PoCs;
+using Console = System.Console;
+
+namespace Bmp.Poc;
+
+internal static class Program
+{
+    [STAThread]
+    public static void Main(string[] args)
+    {
+        PocAsioDFFPlay.MainFunc();
+
+        Console.WriteLine();
+        Console.Write("Press ENTER to exit...");
+        Console.ReadLine();
+    }
+}