Exemple #1
0
        /// <summary>
        /// Saves the individual file to the hard drive as a WAV file.
        /// </summary>
        public unsafe void SaveFile(string folderPath)
        {
            // Create a WAV Sound.
            var         wavSound = WAVSound.FromPACSound(Sound);
            List <byte> bytes    = new List <byte>(Sound.SoundHeader.DataSize + sizeof(File) + sizeof(Sound));

            bytes.AddRange(StructUtilities.ConvertStructureToByteArray(ref wavSound.SoundHeader));
            bytes.AddRange(wavSound.SoundData.ToArray());

            System.IO.File.WriteAllBytes($"{folderPath}\\{GetFileNameWithExtension()}", bytes.ToArray());
        }
Exemple #2
0
        /// <summary>
        /// Creates a new WAVE sound from a specified file path.
        /// </summary>
        public static WAVSound FromFile(string filePath)
        {
            byte[] wavBytes    = System.IO.File.ReadAllBytes(filePath);
            int    filePointer = 0;

            WAVSound wavSound = new WAVSound();

            wavSound.SoundHeader = StructUtilities.ArrayToStructure <WaveSound>(ref wavBytes, filePointer, ref filePointer);
            wavSound.SoundData   = ((Memory <byte>)(wavBytes)).Slice(filePointer, wavSound.SoundHeader.DataSize);

            return(wavSound);
        }
Exemple #3
0
        /// <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);
        }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
        /// <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);
        }