public void SetBufferFloatData( IALBuffer buffer, IntPtr data, int offset, int count ) { OpenALBuffer buf = buffer as OpenALBuffer; AL10.alBufferData( buf.Handle, XNAToFloat[buf.Channels], data + (offset * 4), count * 4, buf.SampleRate ); #if VERBOSE_AL_DEBUGGING CheckALError(); #endif }
public IALBuffer ConvertStereoToMono(IALBuffer buffer) { OpenALBuffer buf = buffer as OpenALBuffer; int bufLen, bits; AL10.alGetBufferi( buf.Handle, AL10.AL_SIZE, out bufLen ); AL10.alGetBufferi( buf.Handle, AL10.AL_BITS, out bits ); bits /= 8; #if VERBOSE_AL_DEBUGGING CheckALError(); #endif byte[] data = new byte[bufLen]; GCHandle dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned); IntPtr dataPtr = dataHandle.AddrOfPinnedObject(); ALEXT.alGetBufferSamplesSOFT( buf.Handle, 0, bufLen / bits / 2, ALEXT.AL_STEREO_SOFT, bits == 2 ? ALEXT.AL_SHORT_SOFT : ALEXT.AL_BYTE_SOFT, dataPtr ); #if VERBOSE_AL_DEBUGGING CheckALError(); #endif byte[] monoData = new byte[bufLen / 2]; GCHandle monoHandle = GCHandle.Alloc(monoData, GCHandleType.Pinned); IntPtr monoPtr = monoHandle.AddrOfPinnedObject(); unsafe { if (bits == 2) { short *src = (short *)dataPtr; short *dst = (short *)monoPtr; for (int i = 0; i < monoData.Length / 2; i += 1) { dst[i] = (short)(((int)src[0] + (int)src[1]) / 2); src += 2; } } else { sbyte *src = (sbyte *)dataPtr; sbyte *dst = (sbyte *)monoPtr; for (int i = 0; i < monoData.Length; i += 1) { dst[i] = (sbyte)(((short)src[0] + (short)src[1]) / 2); src += 2; } } } monoHandle.Free(); dataHandle.Free(); data = null; return(GenBuffer( monoData, (uint)buf.SampleRate, 1, 0, 0, false, (uint)bits - 1 )); }
public unsafe IALBuffer ConvertStereoToMono(IALBuffer buffer) { OpenALBuffer buf = buffer as OpenALBuffer; int bufLen, bits; AL10.alGetBufferi( buf.Handle, AL10.AL_SIZE, out bufLen ); AL10.alGetBufferi( buf.Handle, AL10.AL_BITS, out bits ); bits /= 8; #if VERBOSE_AL_DEBUGGING CheckALError(); #endif byte[] data = new byte[bufLen]; byte[] monoData = new byte[bufLen / 2]; fixed(byte *dataPtr = &data[0]) fixed(byte *monoPtr = &monoData[0]) { ALEXT.alGetBufferSamplesSOFT( buf.Handle, 0, bufLen / bits / 2, ALEXT.AL_STEREO_SOFT, bits == 2 ? ALEXT.AL_SHORT_SOFT : ALEXT.AL_BYTE_SOFT, (IntPtr)dataPtr ); #if VERBOSE_AL_DEBUGGING CheckALError(); #endif if (bits == 2) { short *src = (short *)dataPtr; short *dst = (short *)monoPtr; for (int i = 0; i < monoData.Length / 2; i += 1) { dst[i] = (short)(((int)src[0] + (int)src[1]) / 2); src += 2; } } else { sbyte *src = (sbyte *)dataPtr; sbyte *dst = (sbyte *)monoPtr; for (int i = 0; i < monoData.Length; i += 1) { dst[i] = (sbyte)(((short)src[0] + (short)src[1]) / 2); src += 2; } } } return(GenBuffer( monoData, (uint)buf.SampleRate, 1, 0, 0, false, (uint)bits - 1 )); }