Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 645ed5a

Browse files
committed
Refactor audio conversion and enhance playback experience
Updated `AudioConverter` to streamline null checks and return empty arrays. Added OGG to WAV conversion in `AssetAPI` for better audio handling. Modified `AudioTab` to preload audio automatically, improving user experience. Related: AssetRipper#1877
1 parent 206f0ec commit 645ed5a

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

Source/AssetRipper.Export.Modules.Audio/AudioConverter.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ public static class AudioConverter
88
{
99
public static byte[] OggToWav(byte[] oggData)
1010
{
11-
if (oggData == null)
12-
{
13-
throw new ArgumentNullException(nameof(oggData));
14-
}
11+
ArgumentNullException.ThrowIfNull(oggData);
1512

1613
if (oggData.Length == 0)
1714
{
18-
return Array.Empty<byte>();
15+
return [];
1916
}
2017

2118
try
@@ -28,7 +25,7 @@ public static byte[] OggToWav(byte[] oggData)
2825
catch (Exception ex)
2926
{
3027
Logger.Error(LogCategory.Export, "Failed to convert audio from OGG to WAV", ex);
31-
return Array.Empty<byte>();
28+
return [];
3229
}
3330
}
3431
}

Source/AssetRipper.GUI.Web/Pages/Assets/AssetAPI.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ public static Task GetAudioData(HttpContext context)
181181
}
182182
else if (AudioClipDecoder.TryDecode(clip, out byte[]? decodedAudioData, out string? extension, out _))
183183
{
184+
if (extension is "ogg")
185+
{
186+
byte[] wavData = AudioConverter.OggToWav(decodedAudioData);
187+
if (wavData.Length > 0)
188+
{
189+
decodedAudioData = wavData;
190+
extension = "wav";
191+
}
192+
}
184193
return Results.Bytes(decodedAudioData, $"audio/{extension}").ExecuteAsync(context);
185194
}
186195
else

Source/AssetRipper.GUI.Web/Pages/Assets/AudioTab.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override void Write(TextWriter writer)
2828
{
2929
using (new Td(writer).WithAlign("center").WithCustomAttribute("valign", "middle").End())
3030
{
31-
new Audio(writer).WithControls("").WithClass("mt-4").WithSrc(Source).Close();
31+
new Audio(writer).WithControls("").WithPreload("auto").WithClass("mt-4").WithSrc(Source).Close();
3232
}
3333
}
3434
}

0 commit comments

Comments
 (0)