protected override void CreateInternal(byte[] data) { // Check if WAV. if (WavFormat.IsWav(data)) { SoundData = WavFormat.Decode(data, out AudioFormat format); Format = format; Duration = format.GetSoundDuration(data.Length); } if (Format == null || SoundData.IsEmpty) { Engine.Log.Warning($"Couldn't load audio file - {Name}.", MessageSource.AssetLoader); } }
protected override void CreateInternal(ReadOnlyMemory <byte> data) { // Check if WAV. if (WavFormat.IsWav(data)) { // Get the data. ReadOnlySpan <byte> soundDataDecoded = WavFormat.Decode(data, out AudioFormat format).Span; if (format.SampleSize == 0) { Engine.Log.Error($"Error reading sound file {Name}.", MessageSource.Audio); return; } // Convert to float and store it as such. SoundData = new float[soundDataDecoded.Length / format.SampleSize]; for (var i = 0; i < SoundData.Length; i++) { SoundData[i] = AudioConverter.GetSampleAsFloat(i, soundDataDecoded, format); } OriginalFormat = format.Copy(); format.BitsPerSample = 32; format.IsFloat = true; ByteSize = SoundData.Length; Format = format; Duration = format.GetSoundDuration(SoundData.Length * sizeof(float)); AudioConverter = new AudioConverter(Format, SoundData, 10); if (Format.UnsupportedBitsPerSample()) { Engine.Log.Error($"The audio format of {Name} has an unsupported number of bits per sample ({Format.BitsPerSample}). Supported values are 8/16/32", MessageSource.Audio); } } if (Format == null || SoundData == null) { Engine.Log.Warning($"Couldn't load audio file - {Name}.", MessageSource.AssetLoader); } }