Пример #1
0
        /// <internal />
        /// <summary>Constructs a new SoundData object.</summary>
        /// <param name="format">The SoundFormat of these SoundData.</param>
        /// <param name="data">An array of PCM buffer.</param>
        internal SoundData(SoundFormat format, byte[] data)
        {
            if (data == null) throw new ArgumentNullException("buffer", "Must be a valid array of samples.");
            if (data.Length == 0) throw new ArgumentOutOfRangeException("buffer", "Data length must be higher than 0.");

            this.SoundFormat = format;

            buffer = new byte[data.Length];
            Array.Copy(data, buffer, data.Length);
        }
Пример #2
0
 private ALFormat getFormat(SoundFormat format)
 {
     switch (format)
     {
         case SoundFormat.Mono16: return ALFormat.Mono16;
         case SoundFormat.Mono8: return ALFormat.Mono8;
         case SoundFormat.Stereo16: return ALFormat.Stereo16;
         case SoundFormat.Stereo8: return ALFormat.Stereo8;
         default: throw new NotSupportedException(format.ToString());
     }
 }
Пример #3
0
        /// <internal />
        /// <summary>Constructs a new SoundData object.</summary>
        /// <param name="format">The SoundFormat of these SoundData.</param>
        /// <param name="data">An array of PCM buffer.</param>
        internal SoundData(SoundFormat format, byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("buffer", "Must be a valid array of samples.");
            }
            if (data.Length == 0)
            {
                throw new ArgumentOutOfRangeException("buffer", "Data length must be higher than 0.");
            }

            this.SoundFormat = format;

            buffer = new byte[data.Length];
            Array.Copy(data, buffer, data.Length);
        }
Пример #4
0
        /// <internal />
        /// <summary>Constructs a new SoundData object.</summary>
        /// <param name="format">The SoundFormat of these SoundData.</param>
        /// <param name="data">An array of PCM buffer.</param>
        internal SoundData(SoundFormat format, byte[] data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("buffer", "Must be a valid array of samples.");
            }
            if (data.Length == 0)
            {
                throw new ArgumentOutOfRangeException("buffer", "Data length must be higher than 0.");
            }
            //Type t = typeof(SampleType);
            //if (!(t == typeof(Byte) || t == typeof(SByte) || t == typeof(Int16) || t == typeof(UInt16) || t == typeof(Int32) ||
            //      t == typeof(UInt32) || t == typeof(Int64) || t == typeof(UInt64) || t == typeof(Single)))
            //    throw new ArgumentException(
            //        "SoundData must have one of the following types: byte, short, int, long, float or their unsigned equivalents.");

            this.SoundFormat = format;

            buffer = new byte[NextPowerOfTwo((uint)data.Length)];
            Array.Copy(data, buffer, data.Length);
            //buffer = (byte[])data.Clone();
        }
Пример #5
0
 public void BufferData(int bufferId, SoundFormat format, short[] buffer, int size, int freq)
 { 
     if (_context == null) return;
     AL.BufferData(bufferId, getFormat(format), buffer, size, freq);
 }
Пример #6
0
 public SoundData(SoundFormat format)
 {
     this.SoundFormat = format;
     this.buffer      = null;
 }