mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-06-01 12:07:08 +02:00
[audio] remove recursive_mutex, replace with std::mutex<>
Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
29fad5a89e
commit
3ed25005c7
8 changed files with 84 additions and 174 deletions
|
|
@ -85,7 +85,7 @@ public:
|
||||||
/// Whether the sessions have been started
|
/// Whether the sessions have been started
|
||||||
bool sessions_started{};
|
bool sessions_started{};
|
||||||
/// Protect state due to audio manager callback
|
/// Protect state due to audio manager callback
|
||||||
std::recursive_mutex mutex{};
|
std::mutex mutex{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace AudioCore::AudioIn
|
} // namespace AudioCore::AudioIn
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ public:
|
||||||
/// Whether the sessions have been started
|
/// Whether the sessions have been started
|
||||||
bool sessions_started{};
|
bool sessions_started{};
|
||||||
/// Protect state due to audio manager callback
|
/// Protect state due to audio manager callback
|
||||||
std::recursive_mutex mutex{};
|
std::mutex mutex{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace AudioCore::AudioOut
|
} // namespace AudioCore::AudioOut
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ constexpr s32 BufferAppendLimit = 4;
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
class AudioBuffers {
|
class AudioBuffers {
|
||||||
public:
|
public:
|
||||||
explicit AudioBuffers(size_t limit) : append_limit{static_cast<u32>(limit)} {}
|
explicit AudioBuffers(size_t limit) : append_limit{u32(limit)} {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Append a new audio buffer to the ring.
|
* Append a new audio buffer to the ring.
|
||||||
|
|
@ -308,7 +308,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Buffer lock
|
/// Buffer lock
|
||||||
mutable std::recursive_mutex lock{};
|
mutable std::mutex lock{};
|
||||||
/// The audio buffers
|
/// The audio buffers
|
||||||
std::array<AudioBuffer, N> buffers{};
|
std::array<AudioBuffer, N> buffers{};
|
||||||
/// Current released index
|
/// Current released index
|
||||||
|
|
|
||||||
|
|
@ -123,10 +123,6 @@ void DeviceSession::SetVolume(f32 volume) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 DeviceSession::GetPlayedSampleCount() const {
|
|
||||||
return played_sample_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<std::chrono::nanoseconds> DeviceSession::ThreadFunc() {
|
std::optional<std::chrono::nanoseconds> DeviceSession::ThreadFunc() {
|
||||||
played_sample_count = stream->GetExpectedPlayedSampleCount();
|
played_sample_count = stream->GetExpectedPlayedSampleCount();
|
||||||
if (type == Sink::StreamType::Out) {
|
if (type == Sink::StreamType::Out) {
|
||||||
|
|
|
||||||
|
|
@ -112,7 +112,9 @@ public:
|
||||||
*
|
*
|
||||||
* @return Samples played by this session.
|
* @return Samples played by this session.
|
||||||
*/
|
*/
|
||||||
u64 GetPlayedSampleCount() const;
|
u64 GetPlayedSampleCount() const noexcept {
|
||||||
|
return played_sample_count;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CoreTiming callback to increment played_sample_count over time.
|
* CoreTiming callback to increment played_sample_count over time.
|
||||||
|
|
|
||||||
|
|
@ -8,15 +8,18 @@
|
||||||
namespace AudioCore::AudioIn {
|
namespace AudioCore::AudioIn {
|
||||||
|
|
||||||
In::In(Core::System& system_, Manager& manager_, Kernel::KEvent* event_, size_t session_id_)
|
In::In(Core::System& system_, Manager& manager_, Kernel::KEvent* event_, size_t session_id_)
|
||||||
: manager{manager_}, parent_mutex{manager.mutex}, event{event_}, system{system_, event,
|
: manager{manager_}
|
||||||
session_id_} {}
|
, parent_mutex{manager.mutex}
|
||||||
|
, event{event_}
|
||||||
|
, system{system_, event, session_id_}
|
||||||
|
{}
|
||||||
|
|
||||||
void In::Free() {
|
void In::Free() {
|
||||||
std::scoped_lock l{parent_mutex};
|
std::scoped_lock l{parent_mutex};
|
||||||
manager.ReleaseSessionId(system.GetSessionId());
|
manager.ReleaseSessionId(system.GetSessionId());
|
||||||
}
|
}
|
||||||
|
|
||||||
System& In::GetSystem() {
|
System& In::GetSystem() noexcept {
|
||||||
return system;
|
return system;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,10 +45,8 @@ Result In::StopSystem() {
|
||||||
|
|
||||||
Result In::AppendBuffer(const AudioInBuffer& buffer, u64 tag) {
|
Result In::AppendBuffer(const AudioInBuffer& buffer, u64 tag) {
|
||||||
std::scoped_lock l{parent_mutex};
|
std::scoped_lock l{parent_mutex};
|
||||||
|
if (system.AppendBuffer(buffer, tag))
|
||||||
if (system.AppendBuffer(buffer, tag)) {
|
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
|
||||||
return Service::Audio::ResultBufferCountReached;
|
return Service::Audio::ResultBufferCountReached;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,125 +19,80 @@ class KReadableEvent;
|
||||||
namespace AudioCore::AudioIn {
|
namespace AudioCore::AudioIn {
|
||||||
class Manager;
|
class Manager;
|
||||||
|
|
||||||
/**
|
/// @brief Interface between the service and audio in system. Mainly responsible for forwarding service
|
||||||
* Interface between the service and audio in system. Mainly responsible for forwarding service
|
/// calls to the system.
|
||||||
* calls to the system.
|
|
||||||
*/
|
|
||||||
class In {
|
class In {
|
||||||
public:
|
public:
|
||||||
explicit In(Core::System& system, Manager& manager, Kernel::KEvent* event, size_t session_id);
|
explicit In(Core::System& system, Manager& manager, Kernel::KEvent* event, size_t session_id);
|
||||||
|
|
||||||
/**
|
/// @brief Free this audio in from the audio in manager.
|
||||||
* Free this audio in from the audio in manager.
|
|
||||||
*/
|
|
||||||
void Free();
|
void Free();
|
||||||
|
|
||||||
/**
|
/// @brief Get this audio in's system.
|
||||||
* Get this audio in's system.
|
System& GetSystem() noexcept;
|
||||||
*/
|
|
||||||
System& GetSystem();
|
|
||||||
|
|
||||||
/**
|
/// @brief Get the current state.
|
||||||
* Get the current state.
|
/// @return Started or Stopped.
|
||||||
*
|
|
||||||
* @return Started or Stopped.
|
|
||||||
*/
|
|
||||||
AudioIn::State GetState();
|
AudioIn::State GetState();
|
||||||
|
|
||||||
/**
|
/// @brief Start the system
|
||||||
* Start the system
|
/// @return Result code
|
||||||
*
|
|
||||||
* @return Result code
|
|
||||||
*/
|
|
||||||
Result StartSystem();
|
Result StartSystem();
|
||||||
|
|
||||||
/**
|
/// @brief Start the system's device session.
|
||||||
* Start the system's device session.
|
|
||||||
*/
|
|
||||||
void StartSession();
|
void StartSession();
|
||||||
|
|
||||||
/**
|
/// @brief Stop the system.
|
||||||
* Stop the system.
|
/// @return Result code
|
||||||
*
|
|
||||||
* @return Result code
|
|
||||||
*/
|
|
||||||
Result StopSystem();
|
Result StopSystem();
|
||||||
|
|
||||||
/**
|
/// @brief Append a new buffer to the system, the buffer event will be signalled when it is filled.
|
||||||
* Append a new buffer to the system, the buffer event will be signalled when it is filled.
|
/// @param buffer - The new buffer to append.
|
||||||
*
|
/// @param tag - Unique tag for this buffer.
|
||||||
* @param buffer - The new buffer to append.
|
/// @return Result code.
|
||||||
* @param tag - Unique tag for this buffer.
|
|
||||||
* @return Result code.
|
|
||||||
*/
|
|
||||||
Result AppendBuffer(const AudioInBuffer& buffer, u64 tag);
|
Result AppendBuffer(const AudioInBuffer& buffer, u64 tag);
|
||||||
|
|
||||||
/**
|
/// @brief Release all completed buffers, and register any appended.
|
||||||
* Release all completed buffers, and register any appended.
|
|
||||||
*/
|
|
||||||
void ReleaseAndRegisterBuffers();
|
void ReleaseAndRegisterBuffers();
|
||||||
|
|
||||||
/**
|
/// @brief Flush all buffers.
|
||||||
* Flush all buffers.
|
|
||||||
*/
|
|
||||||
bool FlushAudioInBuffers();
|
bool FlushAudioInBuffers();
|
||||||
|
|
||||||
/**
|
/// @brief Get all of the currently released buffers.
|
||||||
* Get all of the currently released buffers.
|
/// @param tags - Output container for the buffer tags which were released.
|
||||||
*
|
/// @return The number of buffers released.
|
||||||
* @param tags - Output container for the buffer tags which were released.
|
|
||||||
* @return The number of buffers released.
|
|
||||||
*/
|
|
||||||
u32 GetReleasedBuffers(std::span<u64> tags);
|
u32 GetReleasedBuffers(std::span<u64> tags);
|
||||||
|
|
||||||
/**
|
/// @brief Get the buffer event for this audio in, this event will be signalled when a buffer is filled.
|
||||||
* Get the buffer event for this audio in, this event will be signalled when a buffer is filled.
|
/// @return The buffer event.
|
||||||
*
|
|
||||||
* @return The buffer event.
|
|
||||||
*/
|
|
||||||
Kernel::KReadableEvent& GetBufferEvent();
|
Kernel::KReadableEvent& GetBufferEvent();
|
||||||
|
|
||||||
/**
|
/// @brief Get the current system volume.
|
||||||
* Get the current system volume.
|
/// @return The current volume.
|
||||||
*
|
|
||||||
* @return The current volume.
|
|
||||||
*/
|
|
||||||
f32 GetVolume() const;
|
f32 GetVolume() const;
|
||||||
|
|
||||||
/**
|
/// @brief Set the system volume.
|
||||||
* Set the system volume.
|
/// @param volume - The volume to set.
|
||||||
*
|
|
||||||
* @param volume - The volume to set.
|
|
||||||
*/
|
|
||||||
void SetVolume(f32 volume);
|
void SetVolume(f32 volume);
|
||||||
|
|
||||||
/**
|
/// @brief Check if a buffer is in the system.
|
||||||
* Check if a buffer is in the system.
|
/// @param tag - The tag to search for.
|
||||||
*
|
/// @return True if the buffer is in the system, otherwise false.
|
||||||
* @param tag - The tag to search for.
|
|
||||||
* @return True if the buffer is in the system, otherwise false.
|
|
||||||
*/
|
|
||||||
bool ContainsAudioBuffer(u64 tag) const;
|
bool ContainsAudioBuffer(u64 tag) const;
|
||||||
|
|
||||||
/**
|
/// @brief Get the maximum number of buffers.
|
||||||
* Get the maximum number of buffers.
|
/// @return The maximum number of buffers.
|
||||||
*
|
|
||||||
* @return The maximum number of buffers.
|
|
||||||
*/
|
|
||||||
u32 GetBufferCount() const;
|
u32 GetBufferCount() const;
|
||||||
|
|
||||||
/**
|
/// @brief Get the total played sample count for this audio in.
|
||||||
* Get the total played sample count for this audio in.
|
/// @return The played sample count.
|
||||||
*
|
|
||||||
* @return The played sample count.
|
|
||||||
*/
|
|
||||||
u64 GetPlayedSampleCount() const;
|
u64 GetPlayedSampleCount() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// The AudioIn::Manager this audio in is registered with
|
/// The AudioIn::Manager this audio in is registered with
|
||||||
Manager& manager;
|
Manager& manager;
|
||||||
/// Manager's mutex
|
/// Manager's mutex
|
||||||
std::recursive_mutex& parent_mutex;
|
std::mutex& parent_mutex;
|
||||||
/// Buffer event, signalled when buffers are ready to be released
|
/// Buffer event, signalled when buffers are ready to be released
|
||||||
Kernel::KEvent* event;
|
Kernel::KEvent* event;
|
||||||
/// Main audio in system
|
/// Main audio in system
|
||||||
|
|
|
||||||
|
|
@ -19,125 +19,81 @@ class KReadableEvent;
|
||||||
namespace AudioCore::AudioOut {
|
namespace AudioCore::AudioOut {
|
||||||
class Manager;
|
class Manager;
|
||||||
|
|
||||||
/**
|
/// @brief Interface between the service and audio out system. Mainly responsible for forwarding service
|
||||||
* Interface between the service and audio out system. Mainly responsible for forwarding service
|
/// calls to the system.
|
||||||
* calls to the system.
|
|
||||||
*/
|
|
||||||
class Out {
|
class Out {
|
||||||
public:
|
public:
|
||||||
explicit Out(Core::System& system, Manager& manager, Kernel::KEvent* event, size_t session_id);
|
explicit Out(Core::System& system, Manager& manager, Kernel::KEvent* event, size_t session_id);
|
||||||
|
|
||||||
/**
|
/// @brief Free this audio out from the audio out manager.
|
||||||
* Free this audio out from the audio out manager.
|
|
||||||
*/
|
|
||||||
void Free();
|
void Free();
|
||||||
|
|
||||||
/**
|
/// @brief Get this audio out's system.
|
||||||
* Get this audio out's system.
|
|
||||||
*/
|
|
||||||
System& GetSystem();
|
System& GetSystem();
|
||||||
|
|
||||||
/**
|
/// @brief Get the current state.
|
||||||
* Get the current state.
|
/// @return Started or Stopped.
|
||||||
*
|
|
||||||
* @return Started or Stopped.
|
|
||||||
*/
|
|
||||||
AudioOut::State GetState();
|
AudioOut::State GetState();
|
||||||
|
|
||||||
/**
|
/// @brief Start the system
|
||||||
* Start the system
|
/// @return Result code
|
||||||
*
|
|
||||||
* @return Result code
|
|
||||||
*/
|
|
||||||
Result StartSystem();
|
Result StartSystem();
|
||||||
|
|
||||||
/**
|
/// @brief Start the system's device session.
|
||||||
* Start the system's device session.
|
|
||||||
*/
|
|
||||||
void StartSession();
|
void StartSession();
|
||||||
|
|
||||||
/**
|
/// @brief Stop the system.
|
||||||
* Stop the system.
|
/// @return Result code
|
||||||
*
|
|
||||||
* @return Result code
|
|
||||||
*/
|
|
||||||
Result StopSystem();
|
Result StopSystem();
|
||||||
|
|
||||||
/**
|
/// @brief Append a new buffer to the system, the buffer event will be signalled when it is filled.
|
||||||
* Append a new buffer to the system, the buffer event will be signalled when it is filled.
|
/// @param buffer - The new buffer to append.
|
||||||
*
|
/// @param tag - Unique tag for this buffer.
|
||||||
* @param buffer - The new buffer to append.
|
/// @return Result code.
|
||||||
* @param tag - Unique tag for this buffer.
|
|
||||||
* @return Result code.
|
|
||||||
*/
|
|
||||||
Result AppendBuffer(const AudioOutBuffer& buffer, u64 tag);
|
Result AppendBuffer(const AudioOutBuffer& buffer, u64 tag);
|
||||||
|
|
||||||
/**
|
/// @brief Release all completed buffers, and register any appended.
|
||||||
* Release all completed buffers, and register any appended.
|
|
||||||
*/
|
|
||||||
void ReleaseAndRegisterBuffers();
|
void ReleaseAndRegisterBuffers();
|
||||||
|
|
||||||
/**
|
/// @brief Flush all buffers.
|
||||||
* Flush all buffers.
|
|
||||||
*/
|
|
||||||
bool FlushAudioOutBuffers();
|
bool FlushAudioOutBuffers();
|
||||||
|
|
||||||
/**
|
/// @brief Get all of the currently released buffers.
|
||||||
* Get all of the currently released buffers.
|
/// @param tags - Output container for the buffer tags which were released.
|
||||||
*
|
/// @return The number of buffers released.
|
||||||
* @param tags - Output container for the buffer tags which were released.
|
|
||||||
* @return The number of buffers released.
|
|
||||||
*/
|
|
||||||
u32 GetReleasedBuffers(std::span<u64> tags);
|
u32 GetReleasedBuffers(std::span<u64> tags);
|
||||||
|
|
||||||
/**
|
/// @brief Get the buffer event for this audio out, this event will be signalled when a buffer is
|
||||||
* Get the buffer event for this audio out, this event will be signalled when a buffer is
|
/// filled.
|
||||||
* filled.
|
/// @return The buffer event.
|
||||||
* @return The buffer event.
|
|
||||||
*/
|
|
||||||
Kernel::KReadableEvent& GetBufferEvent();
|
Kernel::KReadableEvent& GetBufferEvent();
|
||||||
|
|
||||||
/**
|
/// @brief Get the current system volume.
|
||||||
* Get the current system volume.
|
/// @return The current volume.
|
||||||
*
|
|
||||||
* @return The current volume.
|
|
||||||
*/
|
|
||||||
f32 GetVolume() const;
|
f32 GetVolume() const;
|
||||||
|
|
||||||
/**
|
/// @brief Set the system volume.
|
||||||
* Set the system volume.
|
/// @param volume - The volume to set.
|
||||||
*
|
|
||||||
* @param volume - The volume to set.
|
|
||||||
*/
|
|
||||||
void SetVolume(f32 volume);
|
void SetVolume(f32 volume);
|
||||||
|
|
||||||
/**
|
/// @brief Check if a buffer is in the system.
|
||||||
* Check if a buffer is in the system.
|
/// @param tag - The tag to search for.
|
||||||
*
|
/// @return True if the buffer is in the system, otherwise false.
|
||||||
* @param tag - The tag to search for.
|
|
||||||
* @return True if the buffer is in the system, otherwise false.
|
|
||||||
*/
|
|
||||||
bool ContainsAudioBuffer(u64 tag) const;
|
bool ContainsAudioBuffer(u64 tag) const;
|
||||||
|
|
||||||
/**
|
/// @brief Get the maximum number of buffers.
|
||||||
* Get the maximum number of buffers.
|
/// @return The maximum number of buffers.
|
||||||
*
|
|
||||||
* @return The maximum number of buffers.
|
|
||||||
*/
|
|
||||||
u32 GetBufferCount() const;
|
u32 GetBufferCount() const;
|
||||||
|
|
||||||
/**
|
/// @brief Get the total played sample count for this audio out.
|
||||||
* Get the total played sample count for this audio out.
|
/// @return The played sample count.
|
||||||
*
|
|
||||||
* @return The played sample count.
|
|
||||||
*/
|
|
||||||
u64 GetPlayedSampleCount() const;
|
u64 GetPlayedSampleCount() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// The AudioOut::Manager this audio out is registered with
|
/// The AudioOut::Manager this audio out is registered with
|
||||||
Manager& manager;
|
Manager& manager;
|
||||||
/// Manager's mutex
|
/// Manager's mutex
|
||||||
std::recursive_mutex& parent_mutex;
|
std::mutex& parent_mutex;
|
||||||
/// Buffer event, signalled when buffers are ready to be released
|
/// Buffer event, signalled when buffers are ready to be released
|
||||||
Kernel::KEvent* event;
|
Kernel::KEvent* event;
|
||||||
/// Main audio out system
|
/// Main audio out system
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue