mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
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: #1877
32 lines
707 B
C#
32 lines
707 B
C#
using AssetRipper.Import.Logging;
|
|
using NAudio.Vorbis;
|
|
using NAudio.Wave;
|
|
|
|
namespace AssetRipper.Export.Modules.Audio;
|
|
|
|
public static class AudioConverter
|
|
{
|
|
public static byte[] OggToWav(byte[] oggData)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(oggData);
|
|
|
|
if (oggData.Length == 0)
|
|
{
|
|
return [];
|
|
}
|
|
|
|
try
|
|
{
|
|
using VorbisWaveReader vorbisStream = new VorbisWaveReader(new MemoryStream(oggData), true);
|
|
using MemoryStream writeStream = new MemoryStream();
|
|
WaveFileWriter.WriteWavFileToStream(writeStream, vorbisStream);
|
|
return writeStream.ToArray();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Error(LogCategory.Export, "Failed to convert audio from OGG to WAV", ex);
|
|
return [];
|
|
}
|
|
}
|
|
}
|