public void BindDataBuffer(byte[] dataBuffer, ALFormat format, int size, int sampleRate, int sampleAlignment = 0) { //if ((format == ALFormat.MonoMSAdpcm || format == ALFormat.StereoMSAdpcm) && !OpenALSoundController.Instance.SupportsAdpcm) // throw new InvalidOperationException("MS-ADPCM is not supported by this OpenAL driver"); /// if ((format == ALFormat.MonoIma4 || format == ALFormat.StereoIma4) && !OpenALSoundController.Instance.SupportsIma4) // throw new InvalidOperationException("IMA/ADPCM is not supported by this OpenAL driver"); openALFormat = format; dataSize = size; int unpackedSize = 0; if (sampleAlignment > 0) { // AL.Bufferi(openALDataBuffer, ALBufferi.UnpackBlockAlignmentSoft, sampleAlignment); ALHelper.CheckError("Failed to fill buffer."); } AL.BufferData(openALDataBuffer, openALFormat, dataBuffer, size, sampleRate); ALHelper.CheckError("Failed to fill buffer."); int bits, channels; Duration = -1; AL.GetBuffer(openALDataBuffer, ALGetBufferi.Bits, out bits); ALHelper.CheckError("Failed to get buffer bits"); AL.GetBuffer(openALDataBuffer, ALGetBufferi.Channels, out channels); ALHelper.CheckError("Failed to get buffer channels"); AL.GetBuffer(openALDataBuffer, ALGetBufferi.Size, out unpackedSize); ALHelper.CheckError("Failed to get buffer size"); Duration = (float)(unpackedSize / ((bits / 8) * channels)) / (float)sampleRate; }
private void FreeSource() { AL.SourceStop(openALSourceId); ALHelper.CheckError("Failed to stop source."); AL.Source(openALSourceId, ALSourcei.Buffer, 0); ALHelper.CheckError("Failed to free source from buffer."); Loader.FreeSource(this); }
protected virtual void Dispose(bool disposing) { if (!_isDisposed) { if (disposing) { // Clean up managed objects } // Release unmanaged resources if (AL.IsBuffer(openALDataBuffer)) { ALHelper.CheckError("Failed to fetch buffer state."); AL.DeleteBuffers(1, ref openALDataBuffer); ALHelper.CheckError("Failed to delete buffer."); } _isDisposed = true; } }
public void Play() { openALSourceId = 0; openALSourceId = Loader.ReserveSource(); AL.GetError();//clear errors AL.Source(openALSourceId, ALSourcei.Buffer, data.soundBuffer.OpenALDataBuffer); ALHelper.CheckError("Failed to bind buffer to source."); // Volume AL.Source(openALSourceId, ALSourcef.Gain, Audio.MasterVolume); ALHelper.CheckError("Failed to set source volume."); // Looping AL.Source(openALSourceId, ALSourceb.Looping, Looping); ALHelper.CheckError("Failed to set source loop state."); AL.SourcePlay(openALSourceId); ALHelper.CheckError("Failed to play source."); state = SoundState.Playing; }
public OALSoundBuffer() { AL.GetError(); AL.GenBuffers(1, out openALDataBuffer); ALHelper.CheckError("Failed to generate OpenAL data buffer."); }