aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Audio/Renderers/SoundIo
diff options
context:
space:
mode:
authorAc_K <Acoustik666@gmail.com>2020-11-20 21:59:01 +0100
committerGitHub <noreply@github.com>2020-11-20 21:59:01 +0100
commit57c4e6ef21d1f281b172aedcfd993a2ac43456ef (patch)
tree8ee5e5b42ab14bd8df52e823f3fcb4027e5ed873 /Ryujinx.Audio/Renderers/SoundIo
parent9493cdfe553d77d8f37927ef2acf87cfbab1c467 (diff)
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
Diffstat (limited to 'Ryujinx.Audio/Renderers/SoundIo')
-rw-r--r--Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioOut.cs82
-rw-r--r--Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioTrack.cs34
2 files changed, 91 insertions, 25 deletions
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
@@ -16,16 +16,6 @@ namespace Ryujinx.Audio
private const int MaximumTracks = 256;
/// <summary>
- /// The volume of audio renderer
- /// </summary>
- private float _volume = 1.0f;
-
- /// <summary>
- /// True if the volume of audio renderer have changed
- /// </summary>
- private bool _volumeChanged;
-
- /// <summary>
/// The <see cref="SoundIO"/> audio context
/// </summary>
private SoundIO _audioContext;
@@ -155,14 +145,7 @@ namespace Ryujinx.Audio
public void AppendBuffer<T>(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,24 +175,73 @@ namespace Ryujinx.Audio
}
/// <summary>
- /// Get playback volume
+ /// Get track buffer count
/// </summary>
- public float GetVolume() => _volume;
+ /// <param name="trackId">The ID of the track to get buffer count</param>
+ public uint GetBufferCount(int trackId)
+ {
+ if (_trackPool.TryGet(trackId, out SoundIoAudioTrack track))
+ {
+ return track.BufferCount;
+ }
+
+ return 0;
+ }
/// <summary>
- /// Set playback volume
+ /// Get track played sample count
+ /// </summary>
+ /// <param name="trackId">The ID of the track to get played sample</param>
+ public ulong GetPlayedSampleCount(int trackId)
+ {
+ if (_trackPool.TryGet(trackId, out SoundIoAudioTrack track))
+ {
+ return track.PlayedSampleCount;
+ }
+
+ return 0;
+ }
+
+ /// <summary>
+ /// Flush all track buffers
+ /// </summary>
+ /// <param name="trackId">The ID of the track to flush</param>
+ public bool FlushBuffers(int trackId)
+ {
+ if (_trackPool.TryGet(trackId, out SoundIoAudioTrack track))
+ {
+ return track.FlushBuffers();
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// Set track volume
/// </summary>
/// <param name="volume">The volume of the playback</param>
- 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);
}
}
/// <summary>
+ /// Get track volume
+ /// </summary>
+ public float GetVolume(int trackId)
+ {
+ if (_trackPool.TryGet(trackId, out SoundIoAudioTrack track))
+ {
+ return track.AudioStream.Volume;
+ }
+
+ return 1.0f;
+ }
+
+ /// <summary>
/// Gets the current playback state of the specified track
/// </summary>
/// <param name="trackId">The track to retrieve the playback state for</param>
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
/// </summary>
public ConcurrentQueue<long> ReleasedBuffers { get; private set; }
+ /// <summary>
+ /// Buffer count of the track
+ /// </summary>
+ public uint BufferCount => (uint)m_ReservedBuffers.Count;
+
+ /// <summary>
+ /// Played sample count of the track
+ /// </summary>
+ 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);
}
@@ -572,6 +584,28 @@ namespace Ryujinx.Audio.SoundIo
}
/// <summary>
+ /// Flush all track buffers
+ /// </summary>
+ 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;
+ }
+
+ /// <summary>
/// Closes the <see cref="SoundIoAudioTrack"/>
/// </summary>
public void Close()