From ddc1d966940f5b78139f0bb93209bd70be64b4d8 Mon Sep 17 00:00:00 2001 From: LAGonauta Date: Fri, 13 Apr 2018 07:46:47 -0300 Subject: [PATCH 1/7] Manually set 32LSB output. For testing. --- ASIORecAndPlay/MainWindow.xaml.cs | 51 ++++++++++++++++--------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/ASIORecAndPlay/MainWindow.xaml.cs b/ASIORecAndPlay/MainWindow.xaml.cs index 2123fdf..d9502ca 100644 --- a/ASIORecAndPlay/MainWindow.xaml.cs +++ b/ASIORecAndPlay/MainWindow.xaml.cs @@ -17,7 +17,6 @@ using System; using System.Windows; using NAudio.Wave; -using System.Diagnostics; using System.Windows.Controls; using System.Threading; @@ -32,8 +31,7 @@ public partial class MainWindow : Window private AsioOut asio_rec; private AsioOut asio_play; private BufferedWaveProvider buffer; - private float[] samples = new float[1024 * 1024]; - private float[] samples_correct = new float[1024 * 1024]; + private int[] samples_correct = new int[1024 * 1024]; private byte[] byte_samples = new byte[1024 * 1024 * 4]; private int channels = 2; private bool running; @@ -168,12 +166,12 @@ private void OnButtonBeginClick(object sender, RoutedEventArgs e) } comboChannelConfig.IsEnabled = false; - var format = NAudio.Wave.WaveFormat.CreateIeeeFloatWaveFormat(48000, channels); + var format = new NAudio.Wave.WaveFormat(48000, 32, channels); buffer = new NAudio.Wave.BufferedWaveProvider(format); asio_rec.InitRecordAndPlayback(null, channels, 48000); asio_rec.AudioAvailable += new EventHandler(OnAudioAvailable); - + asio_play.Init(buffer); asio_rec.Play(); @@ -229,61 +227,64 @@ private void Stop() void OnAudioAvailable(object sender, AsioAudioAvailableEventArgs e) { - e.GetAsInterleavedSamples(samples); - // Correct channel mapping if (channels == 6) { for (int i = 0; i < e.SamplesPerBuffer; ++i) { samples_correct[i * channels + 0 /*FRONT LEFT*/] = - samples[i * channels + 0 /*FRONT LEFT*/]; + GetInputSampleInt32LSB(e.InputBuffers[0], i); samples_correct[i * channels + 1 /*FRONT RIGHT*/] = - samples[i * channels + 1 /*FRONT RIGHT*/]; + GetInputSampleInt32LSB(e.InputBuffers[1], i); samples_correct[i * channels + 2 /*FRONT CENTER*/] = - samples[i * channels + 4 /*FRONT CENTER*/]; + GetInputSampleInt32LSB(e.InputBuffers[4], i); samples_correct[i * channels + 3 /*sub/lfe*/] = - samples[i * channels + 5 /*sub/lfe*/]; + GetInputSampleInt32LSB(e.InputBuffers[5], i); samples_correct[i * channels + 4 /*REAR LEFT*/] = - samples[i * channels + 2 /*REAR LEFT*/]; + GetInputSampleInt32LSB(e.InputBuffers[2], i); samples_correct[i * channels + 5 /*REAR RIGHT*/] = - samples[i * channels + 3 /*REAR RIGHT*/]; + GetInputSampleInt32LSB(e.InputBuffers[3], i); } - Buffer.BlockCopy(samples_correct, 0, byte_samples, 0, e.SamplesPerBuffer * channels * sizeof(float)); + Buffer.BlockCopy(samples_correct, 0, byte_samples, 0, e.SamplesPerBuffer * channels * sizeof(int)); } else if (channels == 8) { for (int i = 0; i < e.SamplesPerBuffer; ++i) { samples_correct[i * channels + 0 /*FRONT LEFT*/] = - samples[i * channels + 0 /*FRONT LEFT*/]; + GetInputSampleInt32LSB(e.InputBuffers[0], i); samples_correct[i * channels + 1 /*FRONT RIGHT*/] = - samples[i * channels + 1 /*FRONT RIGHT*/]; + GetInputSampleInt32LSB(e.InputBuffers[1], i); samples_correct[i * channels + 2 /*FRONT CENTER*/] = - samples[i * channels + 4 /*FRONT CENTER*/]; + GetInputSampleInt32LSB(e.InputBuffers[4], i); samples_correct[i * channels + 3 /*sub/lfe*/] = - samples[i * channels + 5 /*sub/lfe*/]; + GetInputSampleInt32LSB(e.InputBuffers[5], i); samples_correct[i * channels + 4 /*REAR LEFT*/] = - samples[i * channels + 2 /*REAR LEFT*/]; + GetInputSampleInt32LSB(e.InputBuffers[2], i); samples_correct[i * channels + 5 /*REAR RIGHT*/] = - samples[i * channels + 3 /*REAR RIGHT*/]; + GetInputSampleInt32LSB(e.InputBuffers[3], i); // Not sure about these two samples_correct[i * channels + 6 /*SIDE LEFT*/] = - samples[i * channels + 6 /*SIDE LEFT*/]; + GetInputSampleInt32LSB(e.InputBuffers[6], i); samples_correct[i * channels + 7 /*SIDE RIGHT*/] = - samples[i * channels + 7 /*SIDE RIGHT*/]; + GetInputSampleInt32LSB(e.InputBuffers[7], i); } - Buffer.BlockCopy(samples_correct, 0, byte_samples, 0, e.SamplesPerBuffer * channels * sizeof(float)); + Buffer.BlockCopy(samples_correct, 0, byte_samples, 0, e.SamplesPerBuffer * channels * sizeof(int)); } else { - Buffer.BlockCopy(samples, 0, byte_samples, 0, e.SamplesPerBuffer * channels * sizeof(float)); + Buffer.BlockCopy(samples_correct, 0, byte_samples, 0, e.SamplesPerBuffer * channels * sizeof(int)); } - buffer.AddSamples(byte_samples, 0, e.SamplesPerBuffer * channels * sizeof(float)); + buffer.AddSamples(byte_samples, 0, e.SamplesPerBuffer * channels * sizeof(int)); + } + + private unsafe int GetInputSampleInt32LSB(IntPtr inputBuffer, int n) + { + return *((int*)inputBuffer + n); } } } From 0fbb2e840d47a5c5f0902ef249953fe502675913 Mon Sep 17 00:00:00 2001 From: LAGonauta Date: Sun, 21 Jul 2019 23:12:56 -0300 Subject: [PATCH 2/7] Initial support for mapping channels and volume meter. Not working yet. --- ASIORecAndPlay.sln | 9 +- ASIORecAndPlay/ASIORecAndPlay.csproj | 22 +- ASIORecAndPlay/App.config | 2 +- ASIORecAndPlay/Asio.cs | 20 ++ ASIORecAndPlay/MainWindow.xaml | 161 ++++++++++++-- ASIORecAndPlay/MainWindow.xaml.cs | 202 ++++++------------ .../Properties/Settings.Designer.cs | 2 +- ASIORecAndPlay/RecAndPlay.cs | 178 +++++++++++++++ ASIORecAndPlay/packages.config | 4 - 9 files changed, 427 insertions(+), 173 deletions(-) create mode 100644 ASIORecAndPlay/Asio.cs create mode 100644 ASIORecAndPlay/RecAndPlay.cs delete mode 100644 ASIORecAndPlay/packages.config diff --git a/ASIORecAndPlay.sln b/ASIORecAndPlay.sln index e5306b3..f2a090b 100644 --- a/ASIORecAndPlay.sln +++ b/ASIORecAndPlay.sln @@ -8,21 +8,18 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {496F0D9F-591C-4213-B0CC-9489714E2DEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {496F0D9F-591C-4213-B0CC-9489714E2DEB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {496F0D9F-591C-4213-B0CC-9489714E2DEB}.Debug|x64.ActiveCfg = Debug|x64 - {496F0D9F-591C-4213-B0CC-9489714E2DEB}.Debug|x64.Build.0 = Debug|x64 {496F0D9F-591C-4213-B0CC-9489714E2DEB}.Release|Any CPU.ActiveCfg = Release|Any CPU {496F0D9F-591C-4213-B0CC-9489714E2DEB}.Release|Any CPU.Build.0 = Release|Any CPU - {496F0D9F-591C-4213-B0CC-9489714E2DEB}.Release|x64.ActiveCfg = Release|x64 - {496F0D9F-591C-4213-B0CC-9489714E2DEB}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {24AA2A5E-78C6-4817-8A99-1017A740BE1C} + EndGlobalSection EndGlobal diff --git a/ASIORecAndPlay/ASIORecAndPlay.csproj b/ASIORecAndPlay/ASIORecAndPlay.csproj index 787a26f..6c88c46 100644 --- a/ASIORecAndPlay/ASIORecAndPlay.csproj +++ b/ASIORecAndPlay/ASIORecAndPlay.csproj @@ -8,7 +8,7 @@ WinExe ASIORecAndPlay ASIORecAndPlay - v4.0 + v4.7.2 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 @@ -24,6 +24,8 @@ DEBUG;TRACE prompt 4 + false + false AnyCPU @@ -33,6 +35,8 @@ TRACE prompt 4 + false + false true @@ -43,6 +47,7 @@ prompt MinimumRecommendedRules.ruleset true + false bin\x64\Release\ @@ -53,14 +58,12 @@ prompt MinimumRecommendedRules.ruleset true + false Graphicloads-Colorful-Long-Shadow-Sound.ico - - ..\packages\NAudio.1.8.4\lib\net35\NAudio.dll - @@ -88,6 +91,8 @@ App.xaml Code + + MainWindow.xaml Code @@ -111,7 +116,6 @@ ResXFileCodeGenerator Resources.Designer.cs - SettingsSingleFileGenerator Settings.Designer.cs @@ -123,5 +127,13 @@ + + + 1.0.1 + + + 1.9.0 + + \ No newline at end of file diff --git a/ASIORecAndPlay/App.config b/ASIORecAndPlay/App.config index 74ade9d..ecdcf8a 100644 --- a/ASIORecAndPlay/App.config +++ b/ASIORecAndPlay/App.config @@ -1,6 +1,6 @@ - + diff --git a/ASIORecAndPlay/Asio.cs b/ASIORecAndPlay/Asio.cs new file mode 100644 index 0000000..3abc09f --- /dev/null +++ b/ASIORecAndPlay/Asio.cs @@ -0,0 +1,20 @@ +using NAudio.Wave; + +namespace ASIORecAndPlay +{ + internal static class Asio + { + public static string[] GetDevices() + { + return AsioOut.GetDriverNames(); + } + + public static void ShowControlPanel(string device) + { + using (var asio = new AsioOut(device)) + { + asio.ShowControlPanel(); + } + } + } +} \ No newline at end of file diff --git a/ASIORecAndPlay/MainWindow.xaml b/ASIORecAndPlay/MainWindow.xaml index 12709dc..ef2ccae 100644 --- a/ASIORecAndPlay/MainWindow.xaml +++ b/ASIORecAndPlay/MainWindow.xaml @@ -4,8 +4,9 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ASIORecAndPlay" + xmlns:controls="clr-namespace:AudioVUMeter.Controls;assembly=AudioVUMeterWPFControl" mc:Ignorable="d" - Title="ASIO Rec and Play" Height="300" Width="300" MinWidth="300" MinHeight="300" + Title="ASIO Rec and Play" Height="380" Width="410" MinWidth="300" MinHeight="300" Closing="Window_Closing"> @@ -15,35 +16,155 @@ - - - - - - - - -