/// <summary> /// Creates a PAC sound from a supplied byte array. /// The byte array should start at the start of the Sound file, and can end at any place; as long as the entirety /// of the RAW PCM data is contained inside. /// </summary> public static PACSound FromByteArray(Memory <byte> byteArray) { PACSound pacSound = new PACSound(); int filePointer = 0; pacSound.SoundHeader = StructUtilities.ArrayToStructure <Sound>(ref byteArray, filePointer, ref filePointer); pacSound.SoundData = byteArray.Slice(filePointer, pacSound.SoundHeader.DataSize); return(pacSound); }
/// <summary> /// Converts a PAC sound into a WAV sound. /// </summary> /// <param name="pacSound">PAC sound to convert from.</param> public static WAVSound FromPACSound(PACSound pacSound) { // Copy Over Sound Details. WAVSound wavSound = new WAVSound(); wavSound.SoundHeader.AudioFormat = pacSound.SoundHeader.AudioFormat; wavSound.SoundHeader.BitsPerSample = pacSound.SoundHeader.BitsPerSample; wavSound.SoundHeader.BlockAlign = pacSound.SoundHeader.BlockAlign; wavSound.SoundHeader.ByteRate = pacSound.SoundHeader.ByteRate; wavSound.SoundHeader.DataSize = pacSound.SoundHeader.DataSize; wavSound.SoundHeader.SampleRate = pacSound.SoundHeader.SampleRate; wavSound.SoundHeader.NumberOfChannels = pacSound.SoundHeader.NumberOfChannels; // Raw Data wavSound.SoundData = pacSound.SoundData; return(wavSound); }
/// <summary> /// Converts a WAV sound into a PAC sound. /// </summary> /// <param name="wavSound">WAV sound to convert from.</param> public static PACSound FromWAVSound(WAVSound wavSound) { // Copy Over Sound Details. PACSound pacSound = new PACSound(); pacSound.SoundHeader.AudioFormat = wavSound.SoundHeader.AudioFormat; pacSound.SoundHeader.BitsPerSample = wavSound.SoundHeader.BitsPerSample; pacSound.SoundHeader.BlockAlign = wavSound.SoundHeader.BlockAlign; pacSound.SoundHeader.ByteRate = wavSound.SoundHeader.ByteRate; pacSound.SoundHeader.DataSize = wavSound.SoundHeader.DataSize; pacSound.SoundHeader.SampleRate = wavSound.SoundHeader.SampleRate; pacSound.SoundHeader.NumberOfChannels = wavSound.SoundHeader.NumberOfChannels; // Raw Data pacSound.SoundData = wavSound.SoundData; return(pacSound); }
/// <summary> /// Replaces the current PAC Sound with a new WAVE file. /// </summary> public unsafe void ReplaceFromFile(string wavPath) { var wavSound = WAVSound.FromFile(wavPath); Sound = PACSound.FromWAVSound(wavSound); }
/// <summary> /// Creates a PACFile from an array containing the whole PAC archive the file is contained in /// and the File structure from said array. /// </summary> public PACFile(byte[] pacArchive, File file) { this.File = file; Sound = PACSound.FromByteArray(file.GetSoundBytes(pacArchive)); }