VGAudio
VGAudio copied to clipboard
Super slow on .NET 5 WebAsm
I'm building a web app for export acb for d4dj in one key with blazor wasm, but it's super slow, that takes lots of mins to encode a 2min audio file.
Even the WaveReader.Read()
takes about 20 sec!
here's my code:
async Task<(byte[], int)> EncodeHCA(byte[] audio)
{
var reader = new WaveReader();
var writer = new HcaWriter
{
Configuration = new HcaConfiguration
{
Bitrate = 128 * 1024,
Quality = CriHcaQuality.Highest,
TrimFile = false,
EncryptionKey = new CriHcaKey(0x59f449354d063308)
}
};
var audioData = await Task.Run<AudioData>(() => reader.Read(audio));
var format = audioData.GetFormat<Pcm16Format>();
byte[] output = null;
using (var ms = new MemoryStream())
{
await Task.Run(() => writer.WriteToStream(audioData, ms));
await ms.FlushAsync();
output = ms.ToArray();
}
return (output, (int)(format.SampleCount / (float)format.SampleRate * 1000));
}
Or maybe it's a issue from dotnet5 idk
I'm not sure why that would happen. Is there any sort of profiling available for .NET wasm?
I'm not sure why that would happen. Is there any sort of profiling available for .NET wasm?
I found a topic about this https://remibou.github.io/Profiling-in-Blazor/
What does it tell you when you profile the slow code?
Problem solved! after upgrading to .NET 7 and enabling AOT, it is lighting fast