Example #1
0
        private void PlaySelected()
        {
            if (listView1.SelectedIndices.Count != 1)
            {
                return;
            }
            byte[] sndData = datafile.LoadSound(listView1.SelectedIndices[0]);
            byte[] buffer  = new byte[sndData.Length * (isLowFi ? 8 : 4) + 44];

            WriteSound(new BinaryWriter(new MemoryStream(buffer, true)), sndData);

            using (MemoryStream memStream = new MemoryStream(buffer))
                using (SoundPlayer sp = new SoundPlayer(memStream))
                {
                    sp.Load();
                    sp.Play();
                };
        }
Example #2
0
        /// <summary>
        /// Helper function to create a sound cache from a given data file.
        /// </summary>
        /// <param name="datafile">The datafile to load from. Must have a valid stream.</param>
        /// <returns>The sound cache with the sound data.</returns>
        public static SoundCache CreateCacheFromFile(SNDFile datafile)
        {
            SoundCache cache = new SoundCache();

            for (int i = 0; i < datafile.Sounds.Count; i++)
            {
                cache.CacheSound(datafile.LoadSound(i));
            }

            return(cache);
        }