mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-27 01:02:48 +01:00
audio_core: Streams need unique names for CoreTiming.
This commit is contained in:
parent
2b06301dbf
commit
9f846d3aa4
5 changed files with 14 additions and 10 deletions
|
@ -27,16 +27,16 @@ static Stream::Format ChannelsToStreamFormat(u32 num_channels) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamPtr AudioOut::OpenStream(u32 sample_rate, u32 num_channels,
|
StreamPtr AudioOut::OpenStream(u32 sample_rate, u32 num_channels, std::string&& name,
|
||||||
Stream::ReleaseCallback&& release_callback) {
|
Stream::ReleaseCallback&& release_callback) {
|
||||||
if (!sink) {
|
if (!sink) {
|
||||||
const SinkDetails& sink_details = GetSinkDetails(Settings::values.sink_id);
|
const SinkDetails& sink_details = GetSinkDetails(Settings::values.sink_id);
|
||||||
sink = sink_details.factory(Settings::values.audio_device_id);
|
sink = sink_details.factory(Settings::values.audio_device_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::make_shared<Stream>(sample_rate, ChannelsToStreamFormat(num_channels),
|
return std::make_shared<Stream>(
|
||||||
std::move(release_callback),
|
sample_rate, ChannelsToStreamFormat(num_channels), std::move(release_callback),
|
||||||
sink->AcquireSinkStream(sample_rate, num_channels));
|
sink->AcquireSinkStream(sample_rate, num_channels), std::move(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Buffer::Tag> AudioOut::GetTagsAndReleaseBuffers(StreamPtr stream, size_t max_count) {
|
std::vector<Buffer::Tag> AudioOut::GetTagsAndReleaseBuffers(StreamPtr stream, size_t max_count) {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "audio_core/buffer.h"
|
#include "audio_core/buffer.h"
|
||||||
|
@ -20,7 +21,7 @@ namespace AudioCore {
|
||||||
class AudioOut {
|
class AudioOut {
|
||||||
public:
|
public:
|
||||||
/// Opens a new audio stream
|
/// Opens a new audio stream
|
||||||
StreamPtr OpenStream(u32 sample_rate, u32 num_channels,
|
StreamPtr OpenStream(u32 sample_rate, u32 num_channels, std::string&& name,
|
||||||
Stream::ReleaseCallback&& release_callback);
|
Stream::ReleaseCallback&& release_callback);
|
||||||
|
|
||||||
/// Returns a vector of recently released buffers specified by tag for the specified stream
|
/// Returns a vector of recently released buffers specified by tag for the specified stream
|
||||||
|
|
|
@ -37,12 +37,12 @@ u32 Stream::GetSampleSize() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream::Stream(u32 sample_rate, Format format, ReleaseCallback&& release_callback,
|
Stream::Stream(u32 sample_rate, Format format, ReleaseCallback&& release_callback,
|
||||||
SinkStream& sink_stream)
|
SinkStream& sink_stream, std::string&& name_)
|
||||||
: sample_rate{sample_rate}, format{format}, release_callback{std::move(release_callback)},
|
: sample_rate{sample_rate}, format{format}, release_callback{std::move(release_callback)},
|
||||||
sink_stream{sink_stream} {
|
sink_stream{sink_stream}, name{std::move(name_)} {
|
||||||
|
|
||||||
release_event = CoreTiming::RegisterEvent(
|
release_event = CoreTiming::RegisterEvent(
|
||||||
"Stream::Release", [this](u64 userdata, int cycles_late) { ReleaseActiveBuffer(); });
|
name, [this](u64 userdata, int cycles_late) { ReleaseActiveBuffer(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::Play() {
|
void Stream::Play() {
|
||||||
|
@ -104,6 +104,7 @@ void Stream::PlayNextBuffer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Stream::ReleaseActiveBuffer() {
|
void Stream::ReleaseActiveBuffer() {
|
||||||
|
ASSERT(active_buffer);
|
||||||
released_buffers.push(std::move(active_buffer));
|
released_buffers.push(std::move(active_buffer));
|
||||||
release_callback();
|
release_callback();
|
||||||
PlayNextBuffer();
|
PlayNextBuffer();
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ public:
|
||||||
using ReleaseCallback = std::function<void()>;
|
using ReleaseCallback = std::function<void()>;
|
||||||
|
|
||||||
Stream(u32 sample_rate, Format format, ReleaseCallback&& release_callback,
|
Stream(u32 sample_rate, Format format, ReleaseCallback&& release_callback,
|
||||||
SinkStream& sink_stream);
|
SinkStream& sink_stream, std::string&& name_);
|
||||||
|
|
||||||
/// Plays the audio stream
|
/// Plays the audio stream
|
||||||
void Play();
|
void Play();
|
||||||
|
@ -96,6 +97,7 @@ private:
|
||||||
std::queue<BufferPtr> queued_buffers; ///< Buffers queued to be played in the stream
|
std::queue<BufferPtr> queued_buffers; ///< Buffers queued to be played in the stream
|
||||||
std::queue<BufferPtr> released_buffers; ///< Buffers recently released from the stream
|
std::queue<BufferPtr> released_buffers; ///< Buffers recently released from the stream
|
||||||
SinkStream& sink_stream; ///< Output sink for the stream
|
SinkStream& sink_stream; ///< Output sink for the stream
|
||||||
|
std::string name; ///< Name of the stream, must be unique
|
||||||
};
|
};
|
||||||
|
|
||||||
using StreamPtr = std::shared_ptr<Stream>;
|
using StreamPtr = std::shared_ptr<Stream>;
|
||||||
|
|
|
@ -48,7 +48,7 @@ public:
|
||||||
buffer_event = Kernel::Event::Create(Kernel::ResetType::Sticky, "IAudioOutBufferReleased");
|
buffer_event = Kernel::Event::Create(Kernel::ResetType::Sticky, "IAudioOutBufferReleased");
|
||||||
|
|
||||||
stream = audio_core.OpenStream(audio_params.sample_rate, audio_params.channel_count,
|
stream = audio_core.OpenStream(audio_params.sample_rate, audio_params.channel_count,
|
||||||
[=]() { buffer_event->Signal(); });
|
"IAudioOut", [=]() { buffer_event->Signal(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue