public static byte[] readSound(USoundWave sound) { if (!sound.bStreaming) { if (sound.bCooked && sound.compressedFormatData.Count > 0) { FSoundFormatData data = sound.compressedFormatData[0]; return(data.data.data); } else if (sound.rawData.data != null) { return(sound.rawData.data); } } else if (sound.bStreaming && sound.streamedAudioChunks != null && !string.IsNullOrEmpty(sound.format)) { List <byte> bytes = new List <byte>(); foreach (FStreamedAudioChunk chunk in sound.streamedAudioChunks) { chunk.data.data.ToList().ForEach(x => bytes.Add(x)); } return(bytes.ToArray()); } return(new byte[0]); }
public static void Decode(this USoundWave soundWave, bool shouldDecompress, out string audioFormat, out byte[]?data) { audioFormat = string.Empty; byte[]? input = null; if (!soundWave.bStreaming) { if (soundWave.CompressedFormatData != null) { var compressedData = soundWave.CompressedFormatData.Formats.First(); audioFormat = compressedData.Key.Text; input = compressedData.Value.Data; } if (soundWave.RawData?.Data != null) // is this even a thing? { audioFormat = string.Empty; input = soundWave.RawData.Data; } } else if (soundWave.RunningPlatformData?.Chunks != null) { var offset = 0; var ret = new byte[soundWave.RunningPlatformData.Chunks.Sum(x => x.AudioDataSize)]; for (var i = 0; i < soundWave.RunningPlatformData.NumChunks; i++) { Buffer.BlockCopy(soundWave.RunningPlatformData.Chunks[i].BulkData.Data, 0, ret, offset, soundWave.RunningPlatformData.Chunks[i].AudioDataSize); offset += soundWave.RunningPlatformData.Chunks[i].AudioDataSize; } audioFormat = soundWave.RunningPlatformData.AudioFormat.Text; input = ret; } data = Decompress(shouldDecompress, ref audioFormat, input); }