public OpenALAudioLayer(string name, OpenALAudioAdapter parent) : base(name) { if (_openALFormatId == 0) { _openALFormatId = _openALAudioFormat.BitsPerSample switch { 32 => Al.FORMAT_STEREO32F, 16 => _openALAudioFormat.Channels == 2 ? Al.FORMAT_STEREO16 : Al.FORMAT_MONO16, 8 => _openALAudioFormat.Channels == 2 ? Al.FORMAT_STEREO8 : Al.FORMAT_MONO8, _ => _openALFormatId } } ; if (_frameRequestSize == 0) { _frameRequestSize = _openALAudioFormat.GetFrameCount(BackendBufferExpectedAhead / 1000f); _frameRequestSize /= BUFFER_COUNT; } _parent = parent; Al.GenSource(out _source); _buffers = new uint[BUFFER_COUNT]; _bufferBusy = new bool[BUFFER_COUNT]; for (var i = 0; i < _buffers.Length; i++) { Al.GenBuffer(out _buffers[i]); } _uploadBuffer = new byte[_frameRequestSize * _openALAudioFormat.FrameSize]; }
public SoundSourcePool(int sourceCount = SoundManager.SOURCE_COUNT) { int alError = Al.NoError; ALSources = new uint[sourceCount]; for (int i = 0; i < sourceCount; i++) { Al.GenSource(out ALSources[i]); alError = Al.GetError(); if (alError != Al.NoError) { throw new Exception("Error generating alSource[" + i.ToString() + "]: " + Al.GetErrorString(alError)); } if (!Al.IsSource(ALSources[i])) { throw new Exception("Generated alSource[" + i.ToString() + "] is invalid!"); } Al.SourceStop(ALSources[i]); alError = Al.GetError(); if (alError != Al.NoError) { throw new Exception("Error stopping newly generated alSource[" + i.ToString() + "]: " + Al.GetErrorString(alError)); } Al.Sourcef(ALSources[i], Al.MinGain, 0.0f); alError = Al.GetError(); if (alError != Al.NoError) { throw new Exception("Error setting min gain: " + Al.GetErrorString(alError)); } Al.Sourcef(ALSources[i], Al.MaxGain, 1.0f); alError = Al.GetError(); if (alError != Al.NoError) { throw new Exception("Error setting max gain: " + Al.GetErrorString(alError)); } Al.Sourcef(ALSources[i], Al.RolloffFactor, 1.0f); alError = Al.GetError(); if (alError != Al.NoError) { throw new Exception("Error setting rolloff factor: " + Al.GetErrorString(alError)); } } }
public AudioSource(Sound sound) { Sound = sound; Al.GenSource(out source); Al.Sourcei(source, Al.Buffer, (int)sound.Buffer); }
public AudioSource() { Al.GenSource(out source); }