Skip to content

Commit 13f37ec

Browse files
committed
Fix audioClip converting
1 parent a0c2a7b commit 13f37ec

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

AssetStudio/Math/Clamp.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
4+
namespace AssetStudio
5+
{
6+
public static partial class MathHelper
7+
{
8+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
9+
public static float Clamp(float value, float minValue, float maxValue)
10+
{
11+
#if NETFRAMEWORK
12+
return Math.Max(minValue, Math.Min(value, maxValue));
13+
#else
14+
return Math.Clamp(value, minValue, maxValue);
15+
#endif
16+
}
17+
}
18+
}

AssetStudioGUI/AssetStudioGUIForm.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,11 +2866,7 @@ private void timer_Tick(object sender, EventArgs e)
28662866
}
28672867

28682868
FMODtimerLabel.Text = $"{ms / 1000 / 60:00}:{ms / 1000 % 60:00}.{ms / 10 % 100:00} / {FMODlenms / 1000 / 60:00}:{FMODlenms / 1000 % 60:00}.{FMODlenms / 10 % 100:00}";
2869-
#if NETFRAMEWORK
2870-
FMODprogressBar.Value = (int)Math.Max(0, Math.Min(ms * 1000f / FMODlenms, 1000));
2871-
#else
2872-
FMODprogressBar.Value = (int)Math.Clamp(ms * 1000f / FMODlenms, 0, 1000);
2873-
#endif
2869+
FMODprogressBar.Value = (int)AssetStudio.MathHelper.Clamp(ms * 1000f / FMODlenms, 0, 1000);
28742870
FMODstatusLabel.Text = paused ? "Paused " : playing ? "Playing" : "Stopped";
28752871

28762872
if (system.hasHandle() && channel.hasHandle())

AssetStudioUtility/Audio/AudioClipConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private static void ReadAsPcm16(IntPtr srcPtr, byte[] destBuffer, int offset, ui
148148
{
149149
pcmFloatSample[j] = Marshal.ReadByte(srcPtr, i + j);
150150
}
151-
var pcm16Sample = (short)(BitConverter.ToSingle(pcmFloatSample, 0) * 32767);
151+
var pcm16Sample = (short)MathHelper.Clamp(BitConverter.ToSingle(pcmFloatSample, 0) * short.MaxValue, short.MinValue, short.MaxValue);
152152
destBuffer[offset] = (byte)(pcm16Sample & 255);
153153
destBuffer[offset + 1] = (byte)(pcm16Sample >> 8);
154154
offset += 2;

0 commit comments

Comments
 (0)