示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WaveBank"/> class and loads the wave data from the provided stream.
        /// </summary>
        /// <param name="audioManager">The associated audio manager.</param>
        /// <param name="stream">The stream from which to read the wave data.</param>
        /// <exception cref="ArgumentNullException">Is thrown when either <paramref name="audioManager"/> or <paramref name="stream"/> are null.</exception>
        private WaveBank(AudioManager audioManager, Stream stream)
        {
            if (audioManager == null)
            {
                throw new ArgumentNullException("audioManager");
            }

            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            using (var reader = new WaveBankReader(stream))
            {
                effects       = new SoundEffect[reader.Count];
                effectsByName = new Dictionary <string, SoundEffect>();

                for (uint i = 0; i < reader.Count; i++)
                {
                    var    format             = reader.GetWaveFormat(i);
                    var    metadata           = reader.GetMetadata(i); // why it is not used?
                    var    name               = reader.GetName(i);
                    var    data               = reader.GetWaveData(i);
                    uint[] decodedPacketsInfo = null;

                    if (format.Encoding == Multimedia.WaveFormatEncoding.Wmaudio2 || format.Encoding == Multimedia.WaveFormatEncoding.Wmaudio3)
                    {
                        Multimedia.WaveFormatEncoding tag;
                        decodedPacketsInfo = reader.GetSeekTable(i, out tag);
                    }

                    var buffer = DataStream.Create <byte>(data, true, false);

                    var effect = effects[i] = new SoundEffect(audioManager, name, format, buffer, decodedPacketsInfo);

                    if (!string.IsNullOrEmpty(name))
                    {
                        effectsByName.Add(name, effect);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WaveBank"/> class and loads the wave data from the provided stream.
        /// </summary>
        /// <param name="audioManager">The associated audio manager.</param>
        /// <param name="stream">The stream from which to read the wave data.</param>
        /// <exception cref="ArgumentNullException">Is thrown when either <paramref name="audioManager"/> or <paramref name="stream"/> are null.</exception>
        private WaveBank(AudioManager audioManager, Stream stream)
        {
            if (audioManager == null)
                throw new ArgumentNullException("audioManager");

            if (stream == null)
                throw new ArgumentNullException("stream");

            using (var reader = new WaveBankReader(stream))
            {
                effects = new SoundEffect[reader.Count];
                effectsByName = new Dictionary<string, SoundEffect>();

                for (uint i = 0; i < reader.Count; i++)
                {
                    var format = reader.GetWaveFormat(i);
                    var metadata = reader.GetMetadata(i); // why it is not used?
                    var name = reader.GetName(i);
                    var data = reader.GetWaveData(i);
                    uint[] decodedPacketsInfo = null;

                    if (format.Encoding == Multimedia.WaveFormatEncoding.Wmaudio2 || format.Encoding == Multimedia.WaveFormatEncoding.Wmaudio3)
                    {
                        Multimedia.WaveFormatEncoding tag;
                        decodedPacketsInfo = reader.GetSeekTable(i, out tag);
                    }

                    var buffer = DataStream.Create<byte>(data, true, false);

                    var effect = effects[i] = new SoundEffect(audioManager, name, format, buffer, decodedPacketsInfo);

                    if (!string.IsNullOrEmpty(name))
                        effectsByName.Add(name, effect);
                }
            }
        }