public override unsafe void BufferData(IntPtr ptr, int sizeInBytes, AudioFormat format) { int fmt = (format.Channels == 2) ? AlNative.AL_FORMAT_STEREO8 : AlNative.AL_FORMAT_MONO8; if (format.BitsPerSample == 16) { fmt++; } AlNative.alBufferData(Buffer, fmt, ptr, sizeInBytes, format.SampleRate); ALEngine.checkAlError(); _format = format; }
public override unsafe void BufferData <T>(T[] buffer, AudioFormat format) { int fmt = (format.Channels == 2) ? AlNative.AL_FORMAT_STEREO8 : AlNative.AL_FORMAT_MONO8; int sizeInBytes = sizeof(T) * buffer.Length; if (format.BitsPerSample == 16) { fmt++; } var handle = GCHandle.Alloc(buffer); IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); AlNative.alBufferData(_buffer, fmt, ptr, sizeInBytes, format.SampleRate); ALEngine.checkAlError(); handle.Free(); _format = format; }