From b58bcaa4f0e89a5ef1d88e8e22a6ae7200f19c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Sg=C3=A1netz?= Date: Fri, 10 Nov 2023 12:01:47 +0100 Subject: [PATCH] Code quality --- Cavern.Format/Common/AudioFormat.cs | 8 ++++---- Cavern.Format/Decoders/Decoder.cs | 2 +- Cavern/Remapping/CavernizeUpmixer.cs | 10 +++++++++- Cavern/Utilities/FFTCachePool.cs | 9 +++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Cavern.Format/Common/AudioFormat.cs b/Cavern.Format/Common/AudioFormat.cs index f04e19d8..63642f89 100644 --- a/Cavern.Format/Common/AudioFormat.cs +++ b/Cavern.Format/Common/AudioFormat.cs @@ -59,9 +59,9 @@ public enum LAFMode { internal static class BitConversions { public const int int24Max = (1 << 23) - 1; - public const float fromInt8 = 1 / (float)sbyte.MaxValue; - public const float fromInt16 = 1 / (float)short.MaxValue; - public const float fromInt24 = 1 / (float)int24Max; - public const float fromInt32 = 1 / (float)int.MaxValue; + public const float fromInt8 = 1f / sbyte.MaxValue; + public const float fromInt16 = 1f / short.MaxValue; + public const float fromInt24 = 1f / int24Max; + public const float fromInt32 = 1f / int.MaxValue; } } \ No newline at end of file diff --git a/Cavern.Format/Decoders/Decoder.cs b/Cavern.Format/Decoders/Decoder.cs index e6f1d3e2..4c815ccb 100644 --- a/Cavern.Format/Decoders/Decoder.cs +++ b/Cavern.Format/Decoders/Decoder.cs @@ -91,7 +91,7 @@ internal static unsafe void DecodeLittleEndianBlock(BlockBuffer reader, fl byte* src = pSrc, end = src + source.Length; while (src != end) { - target[from++] = (((*(ushort*)src) << 8) | *(src += sizeof(ushort)) << 24) * + target[from++] = ((*(ushort*)src << 8) | *(src += sizeof(ushort)) << 24) * BitConversions.fromInt32; // This needs to be shifted into overflow for correct sign src++; } diff --git a/Cavern/Remapping/CavernizeUpmixer.cs b/Cavern/Remapping/CavernizeUpmixer.cs index 940ee938..5c59fa47 100644 --- a/Cavern/Remapping/CavernizeUpmixer.cs +++ b/Cavern/Remapping/CavernizeUpmixer.cs @@ -41,13 +41,21 @@ public class CavernizeUpmixer : Upmixer { /// readonly Listener pinger; + /// + /// Creates height information for ground sources with the filter. + /// The default crossover frequency of 250 Hz will be used. + /// + /// Mono sources to upconvert, not attached to any + /// Content sample rate + public CavernizeUpmixer(IList sources, int sampleRate) : this(sources, sampleRate, 250) { } + /// /// Creates height information for ground sources with the filter. /// /// Mono sources to upconvert, not attached to any /// Content sample rate /// Keep sounds below this frequency on the ground layer - public CavernizeUpmixer(IList sources, int sampleRate, int crossoverFrequency = 250) : + public CavernizeUpmixer(IList sources, int sampleRate, int crossoverFrequency) : base(2 * sources.Count, sampleRate) { this.sources = sources.ToArray(); diff --git a/Cavern/Utilities/FFTCachePool.cs b/Cavern/Utilities/FFTCachePool.cs index b882da9d..d5c3d85c 100644 --- a/Cavern/Utilities/FFTCachePool.cs +++ b/Cavern/Utilities/FFTCachePool.cs @@ -17,6 +17,11 @@ public class FFTCachePool : IDisposable { /// readonly Stack caches = new Stack(); + /// + /// Used for safe locking. + /// + readonly object locker = new object(); + /// /// Create an pool for this FFT size. /// @@ -26,7 +31,7 @@ public class FFTCachePool : IDisposable { /// Get an to work with. /// public FFTCache Lease() { - lock (this) { + lock (locker) { if (caches.Count == 0) { return new ThreadSafeFFTCache(Size); } else { @@ -39,7 +44,7 @@ public FFTCache Lease() { /// Store the for later reuse. /// public void Return(FFTCache cache) { - lock (this) { + lock (locker) { caches.Push(cache); } }