Пример #1
0
        /// <summary>
        /// Helper method to get an entire WAV file in a memory stream.
        /// </summary>
        /// <param name="Sound">Sound index.</param>
        /// <returns>Wave file in MemoryStream.</returns>
        public MemoryStream GetStream(int Sound)
        {
            // Get sound
            DFSound dfSound = GetSound(Sound);

            if (dfSound.WaveHeader == null ||
                dfSound.WaveData == null)
            {
                return(null);
            }

            // Create stream
            byte[]       data = new byte[dfSound.WaveHeader.Length + dfSound.WaveData.Length];
            MemoryStream ms   = new MemoryStream(data);

            // Write header and data
            BinaryWriter writer = new BinaryWriter(ms);

            writer.Write(dfSound.WaveHeader);
            writer.Write(dfSound.WaveData);

            // Reset start position in stream
            ms.Position = 0;

            return(ms);
        }
Пример #2
0
        /// <summary>
        /// Get a sound from index.
        /// </summary>
        /// <param name="sound">SoundEffect.</param>
        /// <param name="soundOut">Sound data out.</param>
        /// <returns>True if successful.</returns>
        public bool GetSound(int sound, out DFSound soundOut)
        {
            soundOut = new DFSound();

            if (!IsValidIndex(sound))
            {
                return(false);
            }

            // Just return sound if already loaded
            if (sounds[sound].DFSound.WaveHeader != null &&
                sounds[sound].DFSound.WaveData != null)
            {
                soundOut = sounds[sound].DFSound;
                return(true);
            }

            // Load sound data
            sounds[sound].MemoryFile = bsaFile.GetRecordProxy(sound);
            if (sounds[sound].MemoryFile == null)
            {
                return(false);
            }

            // Attempt to read sound
            ReadSound(sound);
            soundOut = sounds[sound].DFSound;

            return(true);
        }
Пример #3
0
        /// <summary>
        /// Get a sound from index.
        /// </summary>
        /// <param name="sound">SoundEffect.</param>
        /// <param name="soundOut">Sound data out.</param>
        /// <returns>True if successful.</returns>
        public bool GetSound(int sound, out DFSound soundOut)
        {
            soundOut = new DFSound();

            if (sound < 0 || sound >= bsaFile.Count)
            {
                return(false);
            }

            // Just return sound if already loaded
            if (sounds[sound].DFSound.WaveHeader != null &&
                sounds[sound].DFSound.WaveData != null)
            {
                soundOut = sounds[sound].DFSound;
                return(true);
            }

            // Discard previous sound
            if (AutoDiscard == true && lastSound != -1)
            {
                DiscardSound(lastSound);
            }

            // Load sound data
            sounds[sound].MemoryFile = bsaFile.GetRecordProxy(sound);
            if (sounds[sound].MemoryFile == null)
            {
                return(false);
            }

            // Attempt to read sound
            ReadSound(sound);
            soundOut = sounds[sound].DFSound;

            return(true);
        }
Пример #4
0
        /// <summary>
        /// Get a sound from index.
        /// </summary>
        /// <param name="sound">SoundEffect.</param>
        /// <param name="soundOut">Sound data out.</param>
        /// <returns>True if successful.</returns>
        public bool GetSound(int sound, out DFSound soundOut)
        {
            soundOut = new DFSound();

            if (sound < 0 || sound >= bsaFile.Count)
                return false;

            // Just return sound if already loaded
            if (sounds[sound].DFSound.WaveHeader != null &&
                sounds[sound].DFSound.WaveData != null)
            {
                soundOut = sounds[sound].DFSound;
                return true;
            }

            // Discard previous sound
            if (AutoDiscard == true && lastSound != -1)
            {
                DiscardSound(lastSound);
            }

            // Load sound data
            sounds[sound].MemoryFile = bsaFile.GetRecordProxy(sound);
            if (sounds[sound].MemoryFile == null)
                return false;

            // Attempt to read sound
            ReadSound(sound);
            soundOut = sounds[sound].DFSound;

            return true;
        }