diff options
author | bonmas14 <bonmas14@gmail.com> | 2023-10-24 20:59:19 +0300 |
---|---|---|
committer | bonmas14 <bonmas14@gmail.com> | 2023-10-24 20:59:19 +0300 |
commit | bb22f05857bf5358343de294e98a655370e327aa (patch) | |
tree | 482f7f193105619006fb552616224ec1712908b3 /AudioTester | |
parent | aad3d0382c498f6a39e5dbf5c9682e18127df353 (diff) | |
download | RayRoom-bb22f05857bf5358343de294e98a655370e327aa.tar.gz RayRoom-bb22f05857bf5358343de294e98a655370e327aa.zip |
- raycasting
- System.Drawing visualization
- some tests
Diffstat (limited to 'AudioTester')
-rw-r--r-- | AudioTester/AudioTester.csproj | 25 | ||||
-rw-r--r-- | AudioTester/Core/Extensions/Matrix2x2Extensions.cs | 14 | ||||
-rw-r--r-- | AudioTester/Core/RenderStreamer.cs | 44 | ||||
-rw-r--r-- | AudioTester/Program.cs | 56 | ||||
-rw-r--r-- | AudioTester/RayRoomSettings.cs | 17 | ||||
-rw-r--r-- | AudioTester/Resources/test.wav | bin | 0 -> 672214 bytes |
6 files changed, 156 insertions, 0 deletions
diff --git a/AudioTester/AudioTester.csproj b/AudioTester/AudioTester.csproj new file mode 100644 index 0000000..fc07b92 --- /dev/null +++ b/AudioTester/AudioTester.csproj @@ -0,0 +1,25 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <OutputType>Exe</OutputType> + <TargetFramework>net6.0</TargetFramework> + <ImplicitUsings>enable</ImplicitUsings> + <Nullable>enable</Nullable> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="NAudio" Version="2.2.1" /> + <PackageReference Include="System.Drawing.Common" Version="7.0.0" /> + </ItemGroup> + <ItemGroup> + <Content Include="Resources\*"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </Content> + </ItemGroup> + <ItemGroup> + <None Remove="Resources\test.wav" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\RayRoom\RayRoom.csproj" /> + </ItemGroup> +</Project> diff --git a/AudioTester/Core/Extensions/Matrix2x2Extensions.cs b/AudioTester/Core/Extensions/Matrix2x2Extensions.cs new file mode 100644 index 0000000..0e0b405 --- /dev/null +++ b/AudioTester/Core/Extensions/Matrix2x2Extensions.cs @@ -0,0 +1,14 @@ +using System.Drawing; +using System.Numerics; + +namespace AudioTester.Core.Extensions +{ + internal static class PointExtensions + { + public static Point GetPoint(this Vector2 vector) + { + return new Point((int)MathF.Round(vector.X), (int)MathF.Round(vector.Y)); + } + } + +} diff --git a/AudioTester/Core/RenderStreamer.cs b/AudioTester/Core/RenderStreamer.cs new file mode 100644 index 0000000..85f76a5 --- /dev/null +++ b/AudioTester/Core/RenderStreamer.cs @@ -0,0 +1,44 @@ +using NAudio.Codecs; +using NAudio.Wave; +using NAudio.Wave.SampleProviders; + +namespace AudioTester.Core +{ + internal class RenderStreamer : ISampleProvider + { + public WaveFormat WaveFormat { get; } + + private const int ReadBufferSize = 1024; + private int sample; + private Random rand; + + private AudioFileReader streamReader; + private ISampleProvider provider; + + public RenderStreamer() + { + rand = new Random(); + WaveFormat = WaveFormat.CreateIeeeFloatWaveFormat(44100, 2); + sample = 0; + + streamReader = new AudioFileReader(@"Resources\test.wav"); + + provider = streamReader.ToSampleProvider(); + } + + public int Read(float[] buffer, int offset, int count) + { + int length = provider.Read(buffer, offset, count); + + Console.WriteLine("i: {0}; o:{1}", count, length); + + if (length < count) + { + streamReader.Position = 0; + length += provider.Read(buffer, length, count - length); + } + + return length; + } + } +} diff --git a/AudioTester/Program.cs b/AudioTester/Program.cs new file mode 100644 index 0000000..7557142 --- /dev/null +++ b/AudioTester/Program.cs @@ -0,0 +1,56 @@ +using AudioTester.Core; +using AudioTester.Core.Extensions; +using NAudio.Wave; +using RayRoom.Core; +using System.Drawing; +using System.Numerics; + +namespace AudioTester +{ + internal class Program + { +#pragma warning disable CA1416 // Проверка совместимости платформы + static void Main(string[] args) + { + AudioSimulator a = new AudioSimulator(); + + var array = a.Simulate(Vector2.Zero, 360); + var bitmap = new Bitmap(2000, 2000); + + Matrix2x2 mat = new Matrix2x2(Vector2.UnitX * 100f, Vector2.UnitY * -100f); + + Pen background = new Pen(Color.FromArgb(5, Color.White), 4); + Pen foreground = new Pen(Color.FromArgb(25, Color.White), 1); + + using (Graphics g = Graphics.FromImage(bitmap)) + { + g.Clear(Color.Black); + + for (int i = 0; i < array.Length; i++) + { + g.DrawLine(background, (mat * array[i].a + new Vector2(1000, 1000)).GetPoint(), (mat * array[i].b + new Vector2(1000, 1000)).GetPoint()); + g.DrawLine(foreground, (mat * array[i].a + new Vector2(1000, 1000)).GetPoint(), (mat * array[i].b + new Vector2(1000, 1000)).GetPoint()); + } + } + + bitmap.Save("bitmap.bmp"); +#pragma warning restore CA1416 // Проверка совместимости платформы + return; + var device = new RenderStreamer(); + + using (var wo = new WasapiOut(NAudio.CoreAudioApi.AudioClientShareMode.Shared, 150)) + { + wo.Init(device); + wo.Play(); + + while (wo.PlaybackState == PlaybackState.Playing) + { + Thread.Sleep(100); + + if (Console.KeyAvailable) + wo.Stop(); + } + } + } + } +}
\ No newline at end of file diff --git a/AudioTester/RayRoomSettings.cs b/AudioTester/RayRoomSettings.cs new file mode 100644 index 0000000..c469279 --- /dev/null +++ b/AudioTester/RayRoomSettings.cs @@ -0,0 +1,17 @@ +using NAudio.Wave; +using RayRoom.Core; + +namespace AudioTester +{ + internal static class RayRoomSettings + { + public static Settings GetSettingsFromWaveFromat(WaveFormat format, Settings baseSettings) + { + return new Settings(format.SampleRate, + baseSettings.maxRayReflections, + baseSettings.maxDiffusionRays, + baseSettings.fadeFactorPerMeter, + baseSettings.speedOfSoundMetersPerSec); + } + } +} diff --git a/AudioTester/Resources/test.wav b/AudioTester/Resources/test.wav Binary files differnew file mode 100644 index 0000000..8ca09a1 --- /dev/null +++ b/AudioTester/Resources/test.wav |