2019-10-11 11:54:29 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Concurrent;
|
2018-11-14 21:22:50 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Audio
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A Dummy audio renderer that does not output any audio
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DummyAudioOut : IAalOutput
|
|
|
|
|
{
|
2019-10-11 11:54:29 -04:00
|
|
|
|
private int _lastTrackId = 1;
|
|
|
|
|
private float _volume = 1.0f;
|
2018-11-18 20:24:15 -05:00
|
|
|
|
|
2019-10-11 11:54:29 -04:00
|
|
|
|
private ConcurrentQueue<int> _trackIds;
|
|
|
|
|
private ConcurrentQueue<long> _buffers;
|
|
|
|
|
private ConcurrentDictionary<int, ReleaseCallback> _releaseCallbacks;
|
2018-11-14 21:22:50 -05:00
|
|
|
|
|
|
|
|
|
public DummyAudioOut()
|
|
|
|
|
{
|
2019-10-11 11:54:29 -04:00
|
|
|
|
_buffers = new ConcurrentQueue<long>();
|
|
|
|
|
_trackIds = new ConcurrentQueue<int>();
|
|
|
|
|
_releaseCallbacks = new ConcurrentDictionary<int, ReleaseCallback>();
|
2018-11-14 21:22:50 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Dummy audio output is always available, Baka!
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static bool IsSupported => true;
|
|
|
|
|
|
|
|
|
|
public PlaybackState GetState(int trackId) => PlaybackState.Stopped;
|
|
|
|
|
|
2020-08-18 15:03:55 -04:00
|
|
|
|
public bool SupportsChannelCount(int channels)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int OpenHardwareTrack(int sampleRate, int hardwareChannels, int virtualChannels, ReleaseCallback callback)
|
2018-11-18 20:24:15 -05:00
|
|
|
|
{
|
2019-10-11 11:54:29 -04:00
|
|
|
|
if (!_trackIds.TryDequeue(out int trackId))
|
2018-11-18 20:24:15 -05:00
|
|
|
|
{
|
2019-10-11 11:54:29 -04:00
|
|
|
|
trackId = ++_lastTrackId;
|
2018-11-18 20:24:15 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-11 11:54:29 -04:00
|
|
|
|
_releaseCallbacks[trackId] = callback;
|
2018-11-18 20:24:15 -05:00
|
|
|
|
|
|
|
|
|
return trackId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CloseTrack(int trackId)
|
|
|
|
|
{
|
2019-10-11 11:54:29 -04:00
|
|
|
|
_trackIds.Enqueue(trackId);
|
|
|
|
|
_releaseCallbacks.Remove(trackId, out _);
|
2018-11-18 20:24:15 -05:00
|
|
|
|
}
|
2018-11-14 21:22:50 -05:00
|
|
|
|
|
2019-10-11 11:54:29 -04:00
|
|
|
|
public bool ContainsBuffer(int trackID, long bufferTag) => false;
|
2018-11-14 21:22:50 -05:00
|
|
|
|
|
|
|
|
|
public long[] GetReleasedBuffers(int trackId, int maxCount)
|
|
|
|
|
{
|
|
|
|
|
List<long> bufferTags = new List<long>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < maxCount; i++)
|
|
|
|
|
{
|
2019-10-11 11:54:29 -04:00
|
|
|
|
if (!_buffers.TryDequeue(out long tag))
|
2018-11-14 21:22:50 -05:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bufferTags.Add(tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return bufferTags.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 15:03:55 -04:00
|
|
|
|
public void AppendBuffer<T>(int trackId, long bufferTag, T[] buffer) where T : struct
|
2019-10-11 11:54:29 -04:00
|
|
|
|
{
|
|
|
|
|
_buffers.Enqueue(bufferTag);
|
|
|
|
|
|
2020-08-18 15:03:55 -04:00
|
|
|
|
if (_releaseCallbacks.TryGetValue(trackId, out var callback))
|
2019-10-11 11:54:29 -04:00
|
|
|
|
{
|
|
|
|
|
callback?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start(int trackId) { }
|
|
|
|
|
|
|
|
|
|
public void Stop(int trackId) { }
|
|
|
|
|
|
|
|
|
|
public float GetVolume() => _volume;
|
|
|
|
|
|
|
|
|
|
public void SetVolume(float volume)
|
|
|
|
|
{
|
|
|
|
|
_volume = volume;
|
|
|
|
|
}
|
2018-11-14 21:22:50 -05:00
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
2019-10-11 11:54:29 -04:00
|
|
|
|
_buffers.Clear();
|
2018-11-14 21:22:50 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-11 11:54:29 -04:00
|
|
|
|
}
|