summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-08-03 20:50:53 +0200
committerbunnei <bunneidev@gmail.com>2018-08-04 21:30:10 +0200
commit02fccc09408de59629ea408d825a8978882a6e06 (patch)
tree722448cd89bbbb42189fb0d28d19931c013c2942 /src
parentaudio_core: Sinks need unique names as well. (diff)
downloadyuzu-02fccc09408de59629ea408d825a8978882a6e06.tar
yuzu-02fccc09408de59629ea408d825a8978882a6e06.tar.gz
yuzu-02fccc09408de59629ea408d825a8978882a6e06.tar.bz2
yuzu-02fccc09408de59629ea408d825a8978882a6e06.tar.lz
yuzu-02fccc09408de59629ea408d825a8978882a6e06.tar.xz
yuzu-02fccc09408de59629ea408d825a8978882a6e06.tar.zst
yuzu-02fccc09408de59629ea408d825a8978882a6e06.zip
Diffstat (limited to 'src')
-rw-r--r--src/audio_core/cubeb_sink.cpp40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp
index cf4839989..0b0e9a053 100644
--- a/src/audio_core/cubeb_sink.cpp
+++ b/src/audio_core/cubeb_sink.cpp
@@ -13,14 +13,24 @@ namespace AudioCore {
class SinkStreamImpl final : public SinkStream {
public:
- SinkStreamImpl(cubeb* ctx, cubeb_devid output_device, const std::string& name) : ctx{ctx} {
- cubeb_stream_params params;
- params.rate = 48000;
- params.channels = GetNumChannels();
+ SinkStreamImpl(cubeb* ctx, u32 sample_rate, u32 num_channels_, cubeb_devid output_device,
+ const std::string& name)
+ : ctx{ctx}, num_channels{num_channels_} {
+
+ if (num_channels == 6) {
+ // 6-channel audio does not seem to work with cubeb + SDL, so we downsample this to 2
+ // channel for now
+ is_6_channel = true;
+ num_channels = 2;
+ }
+
+ cubeb_stream_params params{};
+ params.rate = sample_rate;
+ params.channels = num_channels;
params.format = CUBEB_SAMPLE_S16NE;
- params.layout = CUBEB_LAYOUT_STEREO;
+ params.layout = num_channels == 1 ? CUBEB_LAYOUT_MONO : CUBEB_LAYOUT_STEREO;
- u32 minimum_latency = 0;
+ u32 minimum_latency{};
if (cubeb_get_min_latency(ctx, &params, &minimum_latency) != CUBEB_OK) {
LOG_CRITICAL(Audio_Sink, "Error getting minimum latency");
}
@@ -58,11 +68,7 @@ public:
queue.reserve(queue.size() + sample_count * GetNumChannels());
- if (num_channels == 2) {
- // Copy as-is
- std::copy(samples, samples + sample_count * GetNumChannels(),
- std::back_inserter(queue));
- } else if (num_channels == 6) {
+ if (is_6_channel) {
// Downsample 6 channels to 2
const size_t sample_count_copy_size = sample_count * num_channels * 2;
queue.reserve(sample_count_copy_size);
@@ -71,13 +77,14 @@ public:
queue.push_back(samples[i + 1]);
}
} else {
- ASSERT_MSG(false, "Unimplemented");
+ // Copy as-is
+ std::copy(samples, samples + sample_count * GetNumChannels(),
+ std::back_inserter(queue));
}
}
u32 GetNumChannels() const {
- // Only support 2-channel stereo output for now
- return 2;
+ return num_channels;
}
private:
@@ -85,6 +92,8 @@ private:
cubeb* ctx{};
cubeb_stream* stream_backend{};
+ u32 num_channels{};
+ bool is_6_channel{};
std::vector<s16> queue;
@@ -131,7 +140,8 @@ CubebSink::~CubebSink() {
SinkStream& CubebSink::AcquireSinkStream(u32 sample_rate, u32 num_channels,
const std::string& name) {
- sink_streams.push_back(std::make_unique<SinkStreamImpl>(ctx, output_device, name));
+ sink_streams.push_back(
+ std::make_unique<SinkStreamImpl>(ctx, sample_rate, num_channels, output_device, name));
return *sink_streams.back();
}