Fix audioClip converting

This commit is contained in:
VaDiM 2025-04-16 12:47:33 +03:00
parent a0c2a7bdfe
commit 13f37ec260
3 changed files with 20 additions and 6 deletions

18
AssetStudio/Math/Clamp.cs Normal file
View File

@ -0,0 +1,18 @@
using System;
using System.Runtime.CompilerServices;
namespace AssetStudio
{
public static partial class MathHelper
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Clamp(float value, float minValue, float maxValue)
{
#if NETFRAMEWORK
return Math.Max(minValue, Math.Min(value, maxValue));
#else
return Math.Clamp(value, minValue, maxValue);
#endif
}
}
}

View File

@ -2866,11 +2866,7 @@ namespace AssetStudioGUI
}
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}";
#if NETFRAMEWORK
FMODprogressBar.Value = (int)Math.Max(0, Math.Min(ms * 1000f / FMODlenms, 1000));
#else
FMODprogressBar.Value = (int)Math.Clamp(ms * 1000f / FMODlenms, 0, 1000);
#endif
FMODprogressBar.Value = (int)AssetStudio.MathHelper.Clamp(ms * 1000f / FMODlenms, 0, 1000);
FMODstatusLabel.Text = paused ? "Paused " : playing ? "Playing" : "Stopped";
if (system.hasHandle() && channel.hasHandle())

View File

@ -148,7 +148,7 @@ namespace AssetStudio
{
pcmFloatSample[j] = Marshal.ReadByte(srcPtr, i + j);
}
var pcm16Sample = (short)(BitConverter.ToSingle(pcmFloatSample, 0) * 32767);
var pcm16Sample = (short)MathHelper.Clamp(BitConverter.ToSingle(pcmFloatSample, 0) * short.MaxValue, short.MinValue, short.MaxValue);
destBuffer[offset] = (byte)(pcm16Sample & 255);
destBuffer[offset + 1] = (byte)(pcm16Sample >> 8);
offset += 2;