/// <summary> /// Reconstruct a stream from WBH data. /// </summary> /// <param name="entry"></param> /// <param name="convertToPcm"></param> /// <returns></returns> public Memory <byte> ReconstructWave(WBHEntry entry, bool convertToPcm) { var data = Data.Span.Slice(entry.Offset, entry.Size); var entryMutate = entry; // ReSharper disable once InvertIf if (convertToPcm && entry.Codec != WAVECodec.PCM && entry.Channels == 1) { data = entry.Codec switch { WAVECodec.MSADPCM => MSADPCM.Decode(data, entryMutate.BlockAlign), WAVECodec.GCADPCM when entry.Setup is short[] coefficients => GCADPCM.Decode(data, coefficients, entry.Samples), _ => data }; entryMutate.BlockAlign = 2; entryMutate.Codec = WAVECodec.PCM; } return(PCM.ConstructWAVE((short)entryMutate.Codec, entry.Channels, entryMutate.Frequency, entryMutate.BlockAlign, entryMutate.Codec switch { WAVECodec.PCM => 16, WAVECodec.MSADPCM => 4, WAVECodec.GCADPCM => 4, _ => 4 }, data));
/// <summary> /// Reconstructs stream to a WAV /// </summary> /// <returns></returns> public List <Memory <byte> > ReconstructWave(bool convertPcm) { // TODO: BFWAV? if (!convertPcm) { return(ReconstructAsIndividual()); } var streams = new List <Memory <byte> >(); for (var index = 0; index < AudioBuffers.Count; index++) { var buffer = AudioBuffers[index]; var coeffs = new Span <GCADPCMCoefficient>(new[] { Table[index].Coefficient1, Table[index].Coefficient2 }); var data = buffer.Span; data = GCADPCM.Decode(data, MemoryMarshal.Cast <GCADPCMCoefficient, short>(coeffs).ToArray(), Table[index].SampleCount); streams.Add(new Memory <byte>(PCM.ConstructWAVE(0x0001, 1, Header.SampleRate, 0x2, 16, data).ToArray())); } return(streams); }
/// <summary> /// Reconstructs stream to a WAV /// </summary> /// <returns></returns> public List <Memory <byte> > ReconstructWave(bool convertPcm) { var streams = new List <Memory <byte> >(); foreach (var buffer in AudioBuffers) { var data = buffer.Span; var codec = 0x0002; var blockAlign = Info.FrameSize; if (convertPcm) { data = MSADPCM.Decode(data, blockAlign); codec = 0x0001; blockAlign = 0x2; } streams.Add(new Memory <byte>(PCM.ConstructWAVE((short)codec, 1, Header.SampleRate, blockAlign, (WAVECodec)codec switch { WAVECodec.PCM => 16, WAVECodec.MSADPCM => 4, WAVECodec.GCADPCM => 4, _ => 4 }, data).ToArray()));