diff options
| author | Mary <me@thog.eu> | 2021-02-26 01:11:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-26 01:11:56 +0100 |
| commit | f556c80d0230056335632b60c71f1567e177239e (patch) | |
| tree | 748aa6be62b93a8e941e25dbd83f39e1dbb37035 /Ryujinx.Audio/Renderers/OpenAL/OpenALAudioTrack.cs | |
| parent | 1c49089ff00fc87dc4872f135dc6a0d36169a970 (diff) | |
Haydn: Part 1 (#2007)
* Haydn: Part 1
Based on my reverse of audio 11.0.0.
As always, core implementation under LGPLv3 for the same reasons as for Amadeus.
This place the bases of a more flexible audio system while making audout & audin accurate.
This have the following improvements:
- Complete reimplementation of audout and audin.
- Audin currently only have a dummy backend.
- Dramatically reduce CPU usage by up to 50% in common cases (SoundIO and OpenAL).
- Audio Renderer now can output to 5.1 devices when supported.
- Audio Renderer init its backend on demand instead of keeping two up all the time.
- All backends implementation are now in their own project.
- Ryujinx.Audio.Renderer was renamed Ryujinx.Audio and was refactored because of this.
As a note, games having issues with OpenAL haven't improved and will not
because of OpenAL design (stopping when buffers finish playing causing
possible audio "pops" when buffers are very small).
* Update for latest hexkyz's edits on Switchbrew
* audren: Rollback channel configuration changes
* Address gdkchan's comments
* Fix typo in OpenAL backend driver
* Address last comments
* Fix a nit
* Address gdkchan's comments
Diffstat (limited to 'Ryujinx.Audio/Renderers/OpenAL/OpenALAudioTrack.cs')
| -rw-r--r-- | Ryujinx.Audio/Renderers/OpenAL/OpenALAudioTrack.cs | 183 |
1 files changed, 0 insertions, 183 deletions
diff --git a/Ryujinx.Audio/Renderers/OpenAL/OpenALAudioTrack.cs b/Ryujinx.Audio/Renderers/OpenAL/OpenALAudioTrack.cs deleted file mode 100644 index 690129eb..00000000 --- a/Ryujinx.Audio/Renderers/OpenAL/OpenALAudioTrack.cs +++ /dev/null @@ -1,183 +0,0 @@ -using OpenTK.Audio.OpenAL; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; - -namespace Ryujinx.Audio -{ - internal class OpenALAudioTrack : IDisposable - { - public int SourceId { get; private set; } - public int SampleRate { get; private set; } - public ALFormat Format { get; private set; } - public PlaybackState State { get; set; } - - public int HardwareChannels { get; } - public int VirtualChannels { get; } - public uint BufferCount => (uint)_buffers.Count; - public ulong PlayedSampleCount { get; set; } - - private ReleaseCallback _callback; - - private ConcurrentDictionary<long, int> _buffers; - - private Queue<long> _queuedTagsQueue; - private Queue<long> _releasedTagsQueue; - - private bool _disposed; - - public OpenALAudioTrack(int sampleRate, ALFormat format, int hardwareChannels, int virtualChannels, ReleaseCallback callback) - { - SampleRate = sampleRate; - Format = format; - State = PlaybackState.Stopped; - SourceId = AL.GenSource(); - - HardwareChannels = hardwareChannels; - VirtualChannels = virtualChannels; - - _callback = callback; - - _buffers = new ConcurrentDictionary<long, int>(); - - _queuedTagsQueue = new Queue<long>(); - _releasedTagsQueue = new Queue<long>(); - } - - public bool ContainsBuffer(long tag) - { - foreach (long queuedTag in _queuedTagsQueue) - { - if (queuedTag == tag) - { - return true; - } - } - - return false; - } - - public long[] GetReleasedBuffers(int count) - { - AL.GetSource(SourceId, ALGetSourcei.BuffersProcessed, out int releasedCount); - - releasedCount += _releasedTagsQueue.Count; - - if (count > releasedCount) - { - count = releasedCount; - } - - List<long> tags = new List<long>(); - - while (count-- > 0 && _releasedTagsQueue.TryDequeue(out long tag)) - { - tags.Add(tag); - } - - while (count-- > 0 && _queuedTagsQueue.TryDequeue(out long tag)) - { - AL.SourceUnqueueBuffers(SourceId, 1); - - tags.Add(tag); - } - - return tags.ToArray(); - } - - public int AppendBuffer(long tag) - { - if (_disposed) - { - throw new ObjectDisposedException(GetType().Name); - } - - int id = AL.GenBuffer(); - - _buffers.AddOrUpdate(tag, id, (key, oldId) => - { - AL.DeleteBuffer(oldId); - - return id; - }); - - _queuedTagsQueue.Enqueue(tag); - - return id; - } - - public void CallReleaseCallbackIfNeeded() - { - AL.GetSource(SourceId, ALGetSourcei.BuffersProcessed, out int releasedCount); - - if (releasedCount > 0) - { - // If we signal, then we also need to have released buffers available - // to return when GetReleasedBuffers is called. - // If playback needs to be re-started due to all buffers being processed, - // then OpenAL zeros the counts (ReleasedCount), so we keep it on the queue. - while (releasedCount-- > 0 && _queuedTagsQueue.TryDequeue(out long tag)) - { - AL.SourceUnqueueBuffers(SourceId, 1); - - _releasedTagsQueue.Enqueue(tag); - } - - _callback(); - } - } - - public bool FlushBuffers() - { - while (_queuedTagsQueue.TryDequeue(out long tag)) - { - _releasedTagsQueue.Enqueue(tag); - } - - _callback(); - - foreach (var buffer in _buffers) - { - AL.DeleteBuffer(buffer.Value); - } - - bool heldBuffers = _buffers.Count > 0; - - _buffers.Clear(); - - return heldBuffers; - } - - public void SetVolume(float volume) - { - AL.Source(SourceId, ALSourcef.Gain, volume); - } - - public float GetVolume() - { - AL.GetSource(SourceId, ALSourcef.Gain, out float volume); - - return volume; - } - - public void Dispose() - { - Dispose(true); - } - - protected virtual void Dispose(bool disposing) - { - if (disposing && !_disposed) - { - _disposed = true; - - AL.DeleteSource(SourceId); - - foreach (int id in _buffers.Values) - { - AL.DeleteBuffer(id); - } - } - } - } -}
\ No newline at end of file |
