Skip to content

Commit

Permalink
Code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Nov 10, 2023
1 parent dd20632 commit b58bcaa
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Cavern.Format/Common/AudioFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 1 addition & 1 deletion Cavern.Format/Decoders/Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal static unsafe void DecodeLittleEndianBlock(BlockBuffer<byte> 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++;
}
Expand Down
10 changes: 9 additions & 1 deletion Cavern/Remapping/CavernizeUpmixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ public class CavernizeUpmixer : Upmixer {
/// </summary>
readonly Listener pinger;

/// <summary>
/// Creates height information for ground sources with the <see cref="Cavernize"/> filter.
/// The default crossover frequency of 250 Hz will be used.
/// </summary>
/// <param name="sources">Mono sources to upconvert, not attached to any <see cref="Listener"/></param>
/// <param name="sampleRate">Content sample rate</param>
public CavernizeUpmixer(IList<Source> sources, int sampleRate) : this(sources, sampleRate, 250) { }

/// <summary>
/// Creates height information for ground sources with the <see cref="Cavernize"/> filter.
/// </summary>
/// <param name="sources">Mono sources to upconvert, not attached to any <see cref="Listener"/></param>
/// <param name="sampleRate">Content sample rate</param>
/// <param name="crossoverFrequency">Keep sounds below this frequency on the ground layer</param>
public CavernizeUpmixer(IList<Source> sources, int sampleRate, int crossoverFrequency = 250) :
public CavernizeUpmixer(IList<Source> sources, int sampleRate, int crossoverFrequency) :
base(2 * sources.Count, sampleRate) {
this.sources = sources.ToArray();

Expand Down
9 changes: 7 additions & 2 deletions Cavern/Utilities/FFTCachePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class FFTCachePool : IDisposable {
/// </summary>
readonly Stack<FFTCache> caches = new Stack<FFTCache>();

/// <summary>
/// Used for safe locking.
/// </summary>
readonly object locker = new object();

/// <summary>
/// Create an <see cref="FFTCache"/> pool for this FFT size.
/// </summary>
Expand All @@ -26,7 +31,7 @@ public class FFTCachePool : IDisposable {
/// Get an <see cref="FFTCache"/> to work with.
/// </summary>
public FFTCache Lease() {
lock (this) {
lock (locker) {
if (caches.Count == 0) {
return new ThreadSafeFFTCache(Size);
} else {
Expand All @@ -39,7 +44,7 @@ public FFTCache Lease() {
/// Store the <paramref name="cache"/> for later reuse.
/// </summary>
public void Return(FFTCache cache) {
lock (this) {
lock (locker) {
caches.Push(cache);
}
}
Expand Down

0 comments on commit b58bcaa

Please sign in to comment.