From 57c4e6ef21d1f281b172aedcfd993a2ac43456ef Mon Sep 17 00:00:00 2001 From: Ac_K Date: Fri, 20 Nov 2020 21:59:01 +0100 Subject: audout: Implement and fix some calls (#1725) * audout: Implement GetAudioOutBufferCount, GetAudioOutPlayedSampleCount and FlushAudioOutBuffers This PR implement audout service calls: - GetAudioOutBufferCount - GetAudioOutPlayedSampleCount - FlushAudioOutBuffers The RE calls just give some hints about no extra checks. Since we use a totally different implementation because of our backend, I can't do something better for now. SetAudioOutVolume and GetAudioOutVolume are fixed too by set/get the volume of the current opened track, previous implementation was wrong. This fix #1133, fix #1258 and fix #1519. Thanks to @jduncanator for this help during the implementation and all his precious advices. * Fix some debug leftovers * Address jD feedback --- Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioOut.cs | 82 +++++++++++++++------- .../Renderers/SoundIo/SoundIoAudioTrack.cs | 34 +++++++++ 2 files changed, 91 insertions(+), 25 deletions(-) (limited to 'Ryujinx.Audio/Renderers/SoundIo') diff --git a/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioOut.cs b/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioOut.cs index fa3961e4..eb6caa60 100644 --- a/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioOut.cs +++ b/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioOut.cs @@ -15,16 +15,6 @@ namespace Ryujinx.Audio /// private const int MaximumTracks = 256; - /// - /// The volume of audio renderer - /// - private float _volume = 1.0f; - - /// - /// True if the volume of audio renderer have changed - /// - private bool _volumeChanged; - /// /// The audio context /// @@ -155,14 +145,7 @@ namespace Ryujinx.Audio public void AppendBuffer(int trackId, long bufferTag, T[] buffer) where T : struct { if (_trackPool.TryGet(trackId, out SoundIoAudioTrack track)) - { - if (_volumeChanged) - { - track.AudioStream.SetVolume(_volume); - - _volumeChanged = false; - } - + { track.AppendBuffer(bufferTag, buffer); } } @@ -192,23 +175,72 @@ namespace Ryujinx.Audio } /// - /// Get playback volume + /// Get track buffer count /// - public float GetVolume() => _volume; + /// The ID of the track to get buffer count + public uint GetBufferCount(int trackId) + { + if (_trackPool.TryGet(trackId, out SoundIoAudioTrack track)) + { + return track.BufferCount; + } + + return 0; + } /// - /// Set playback volume + /// Get track played sample count + /// + /// The ID of the track to get played sample + public ulong GetPlayedSampleCount(int trackId) + { + if (_trackPool.TryGet(trackId, out SoundIoAudioTrack track)) + { + return track.PlayedSampleCount; + } + + return 0; + } + + /// + /// Flush all track buffers + /// + /// The ID of the track to flush + public bool FlushBuffers(int trackId) + { + if (_trackPool.TryGet(trackId, out SoundIoAudioTrack track)) + { + return track.FlushBuffers(); + } + + return false; + } + + /// + /// Set track volume /// /// The volume of the playback - public void SetVolume(float volume) + public void SetVolume(int trackId, float volume) { - if (!_volumeChanged) + if (_trackPool.TryGet(trackId, out SoundIoAudioTrack track)) { - _volume = volume; - _volumeChanged = true; + track.AudioStream.SetVolume(volume); } } + /// + /// Get track volume + /// + public float GetVolume(int trackId) + { + if (_trackPool.TryGet(trackId, out SoundIoAudioTrack track)) + { + return track.AudioStream.Volume; + } + + return 1.0f; + } + /// /// Gets the current playback state of the specified track /// diff --git a/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioTrack.cs b/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioTrack.cs index 6fdeb991..52c4ebc9 100644 --- a/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioTrack.cs +++ b/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioTrack.cs @@ -54,6 +54,16 @@ namespace Ryujinx.Audio.SoundIo /// public ConcurrentQueue ReleasedBuffers { get; private set; } + /// + /// Buffer count of the track + /// + public uint BufferCount => (uint)m_ReservedBuffers.Count; + + /// + /// Played sample count of the track + /// + public ulong PlayedSampleCount { get; private set; } + private int _hardwareChannels; private int _virtualChannels; @@ -430,6 +440,8 @@ namespace Ryujinx.Audio.SoundIo AudioStream.EndWrite(); + PlayedSampleCount += (ulong)samples.Length; + UpdateReleasedBuffers(samples.Length); } @@ -571,6 +583,28 @@ namespace Ryujinx.Audio.SoundIo return m_ReservedBuffers.Any(x => x.Tag == bufferTag); } + /// + /// Flush all track buffers + /// + public bool FlushBuffers() + { + m_Buffer.Clear(); + + if (m_ReservedBuffers.Count > 0) + { + foreach (var buffer in m_ReservedBuffers) + { + ReleasedBuffers.Enqueue(buffer.Tag); + } + + OnBufferReleased(); + + return true; + } + + return false; + } + /// /// Closes the /// -- cgit v1.2.3