示例#1
0
        public Context(Device device, Dictionary <int, int> attributes)
            : this()
        {
            if (device == Device.Null)
            {
                throw new ArgumentNullException("device");
            }

            unsafe
            {
                var  attribs_length = attributes == null ? 0 : attributes.Count * 2;
                int *attribs        = stackalloc int[attribs_length + 1];

                if (attributes != null)
                {
                    int index = 0;
                    foreach (var pair in attributes)
                    {
                        attribs[index++] = pair.Key;
                        attribs[index++] = pair.Value;
                    }
                    attribs[attribs_length] = 0;
                }
                else
                {
                    attribs = null;
                }

                Handle = Alc.CreateContext(device.Handle, attribs);
                AlHelper.GetAlcError(Alc.GetError(device.Handle));
            }
        }
示例#2
0
文件: Source.cs 项目: bonomali/Ibasa
        public static void Create(Source[] sources, int index, int count)
        {
            if (sources == null)
            {
                throw new ArgumentNullException("sources");
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException("index", index, "index is less than 0.");
            }
            if (index + count > sources.Length)
            {
                throw new ArgumentOutOfRangeException("count", count, "index + count is greater than buffers.Length.");
            }

            unsafe
            {
                uint *ids = stackalloc uint[count];
                Al.GenSources(count, ids);
                AlHelper.GetAlError(Al.GetError());
                for (int i = 0; i < count; ++i)
                {
                    AlHelper.CheckName(ids[i], "source");
                    sources[index + i] = new Source(ids[i]);
                }
            }
        }
示例#3
0
 public void Read(IntPtr buffer, int samples)
 {
     AlHelper.ThrowNullException(Handle);
     unsafe
     {
         Alc.CaptureSamples(Handle, buffer.ToPointer(), samples);
         AlHelper.GetAlcError(Alc.GetError(Handle));
     }
 }
示例#4
0
文件: Source.cs 项目: bonomali/Ibasa
 public override bool Equals(object obj)
 {
     AlHelper.ThrowNullException(Id);
     if (obj is Source)
     {
         return(Equals((Source)obj));
     }
     return(false);
 }
示例#5
0
 public override bool Equals(object obj)
 {
     AlHelper.ThrowNullException(Handle);
     if (obj is Device)
     {
         return(Equals((Device)obj));
     }
     return(false);
 }
示例#6
0
文件: Source.cs 项目: bonomali/Ibasa
 public void Delete()
 {
     AlHelper.ThrowNullException(Id);
     unsafe
     {
         uint id = Id;
         Al.DeleteSources(1, &id);
     }
 }
示例#7
0
        public static IntPtr GetFunctionPointer(string fname)
        {
            unsafe
            {
                int   length = Encoding.ASCII.GetByteCount(fname);
                byte *chars  = stackalloc byte[length];
                AlHelper.StringToAnsi(fname, chars, length);

                return(new IntPtr(Al.GetProcAddress(chars)));
            }
        }
示例#8
0
文件: Source.cs 项目: bonomali/Ibasa
 public static Source Create()
 {
     unsafe
     {
         uint id;
         Al.GenSources(1, &id);
         AlHelper.GetAlError(Al.GetError());
         AlHelper.CheckName(id, "source");
         return(new Source(id));
     }
 }
示例#9
0
 public static Buffer Create()
 {
     unsafe
     {
         uint id;
         Al.GenBuffers(1, &id);
         AlHelper.GetAlError(Al.GetError());
         AlHelper.CheckName(id, "buffer");
         return(new Buffer(id));
     }
 }
示例#10
0
        public static int GetEnumValue(string enumname)
        {
            unsafe
            {
                int   length = Encoding.ASCII.GetByteCount(enumname);
                byte *chars  = stackalloc byte[length];
                AlHelper.StringToAnsi(enumname, chars, length);

                return(Al.GetEnumValue(chars));
            }
        }
示例#11
0
文件: Source.cs 项目: bonomali/Ibasa
        public Buffer Unqueue()
        {
            AlHelper.ThrowNullException(Id);

            unsafe
            {
                uint bid;
                Al.SourceUnqueueBuffers(Id, 1, &bid);
                return(new OpenAL.Buffer(bid));
            }
        }
示例#12
0
        public static bool IsExtensionPresent(string extension)
        {
            unsafe
            {
                int   length = Encoding.ASCII.GetByteCount(extension);
                byte *chars  = stackalloc byte[length];
                AlHelper.StringToAnsi(extension, chars, length);

                return(Al.IsExtensionPresent(chars));
            }
        }
示例#13
0
 public void Read(byte[] buffer, int samples)
 {
     AlHelper.ThrowNullException(Handle);
     unsafe
     {
         fixed(byte *pointer = buffer)
         {
             Alc.CaptureSamples(Handle, pointer, samples);
             AlHelper.GetAlcError(Alc.GetError(Handle));
         }
     }
 }
示例#14
0
 public bool Close()
 {
     AlHelper.ThrowNullException(Handle);
     if (Alc.CloseDevice(Handle) != 0)
     {
         Handle = IntPtr.Zero;
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#15
0
文件: Source.cs 项目: bonomali/Ibasa
        public void Queue(Buffer buffer)
        {
            AlHelper.ThrowNullException(Id);
            if (buffer == Buffer.Null)
            {
                throw new ArgumentNullException("buffer");
            }

            unsafe
            {
                uint bid = buffer.Id;
                Al.SourceQueueBuffers(Id, 1, &bid);
            }
        }
示例#16
0
        public Context(Device device)
            : this()
        {
            if (device == Device.Null)
            {
                throw new ArgumentNullException("device");
            }

            unsafe
            {
                Handle = Alc.CreateContext(device.Handle, null);
                AlHelper.GetAlcError(Alc.GetError(device.Handle));
            }
        }
示例#17
0
        public void BufferData(Format format, IntPtr data, int size, int frequency)
        {
            AlHelper.ThrowNullException(Id);
            if (data == IntPtr.Zero)
            {
                throw new ArgumentNullException("data");
            }

            unsafe
            {
                uint id = Id;
                Al.BufferData(Id, (int)format, data.ToPointer(), size, frequency);
            }
        }
示例#18
0
文件: Source.cs 项目: bonomali/Ibasa
        public void Queue(Buffer[] buffers)
        {
            AlHelper.ThrowNullException(Id);
            if (buffers == null)
            {
                throw new ArgumentNullException("buffers");
            }

            unsafe
            {
                uint *bids = stackalloc uint[buffers.Length];
                for (int i = 0; i < buffers.Length; ++i)
                {
                    bids[i] = buffers[i].Id;
                }
                Al.SourceQueueBuffers(Id, buffers.Length, bids);
            }
        }
示例#19
0
        public CaptureDevice(string name, uint frequency, Format format, int buffersize)
            : this()
        {
            unsafe
            {
                int   name_length = name == null ? 0 : Encoding.ASCII.GetByteCount(name);
                byte *name_ansi   = stackalloc byte[name_length + 1];
                AlHelper.StringToAnsi(name, name_ansi, name_length);
                name_ansi = name == null ? null : name_ansi;

                Handle = Alc.CaptureOpenDevice(name_ansi, frequency, (int)format, buffersize);
                if (Handle == IntPtr.Zero)
                {
                    throw new OpenALException(string.Format(
                                                  "CaptureOpenDevice({0}, {1}, {2}, {3}) failed.", name, frequency, format, buffersize));
                }
            }
        }
示例#20
0
        public Device(string name)
            : this()
        {
            unsafe
            {
                int   name_length = name == null ? 0 : Encoding.ASCII.GetByteCount(name);
                byte *name_ansi   = stackalloc byte[name_length + 1];
                AlHelper.StringToAnsi(name, name_ansi, name_length);
                name_ansi = name == null ? null : name_ansi;

                Handle = Alc.OpenDevice(name_ansi);
                if (Handle == IntPtr.Zero)
                {
                    throw new OpenALException(string.Format(
                                                  "OpenDevice({0}) failed.", name));
                }
            }
        }
示例#21
0
        public void BufferData(Format format, byte[] data, int size, int frequency)
        {
            AlHelper.ThrowNullException(Id);
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            unsafe
            {
                fixed(byte *pointer = data)
                {
                    uint id = Id;

                    Al.BufferData(Id, (int)format, pointer, size, frequency);
                }
            }
        }
示例#22
0
文件: Source.cs 项目: bonomali/Ibasa
        public                        Buffer[] Unqueue(int count)
        {
            AlHelper.ThrowNullException(Id);
            if (count <= 0)
            {
                throw new ArgumentException("count is less than or equal to 0.", "count");
            }

            unsafe
            {
                uint *bids = stackalloc uint[count];
                Al.SourceUnqueueBuffers(Id, count, bids);

                Buffer[] buffers = new Buffer[count];
                for (int i = 0; i < count; ++i)
                {
                    buffers[i] = new Buffer(bids[i]);
                }
                return(buffers);
            }
        }
示例#23
0
文件: Source.cs 项目: bonomali/Ibasa
 public void Rewind()
 {
     AlHelper.ThrowNullException(Id);
     Al.SourceRewind(Id);
 }
示例#24
0
文件: Source.cs 项目: bonomali/Ibasa
 public override string ToString()
 {
     AlHelper.ThrowNullException(Id);
     return(string.Format("Source: {0}", Id.ToString()));
 }
示例#25
0
文件: Source.cs 项目: bonomali/Ibasa
 public bool Equals(Source other)
 {
     AlHelper.ThrowNullException(Id);
     return(Id == other.Id);
 }
示例#26
0
文件: Source.cs 项目: bonomali/Ibasa
 public override int GetHashCode()
 {
     AlHelper.ThrowNullException(Id);
     return(Id.GetHashCode());
 }
示例#27
0
 public override string ToString()
 {
     AlHelper.ThrowNullException(Handle);
     return(string.Format("Device: {0}", Handle.ToString()));
 }
示例#28
0
文件: Source.cs 项目: bonomali/Ibasa
 public void Stop()
 {
     AlHelper.ThrowNullException(Id);
     Al.SourceStop(Id);
 }
示例#29
0
文件: Source.cs 项目: bonomali/Ibasa
 public void Play()
 {
     AlHelper.ThrowNullException(Id);
     Al.SourcePlay(Id);
 }
示例#30
0
文件: Source.cs 项目: bonomali/Ibasa
 public void Pause()
 {
     AlHelper.ThrowNullException(Id);
     Al.SourcePause(Id);
 }