yuzu-emu
/
yuzu
Archived
1
0
Fork 0

cubeb_sink: Downsample arbitrary number of channels

This commit is contained in:
MerryMage 2018-09-09 09:16:48 +01:00
parent 1aa195a9c0
commit 55af5bda55
1 changed files with 9 additions and 10 deletions

View File

@ -17,8 +17,8 @@ class CubebSinkStream final : public SinkStream {
public: public:
CubebSinkStream(cubeb* ctx, u32 sample_rate, u32 num_channels_, cubeb_devid output_device, CubebSinkStream(cubeb* ctx, u32 sample_rate, u32 num_channels_, cubeb_devid output_device,
const std::string& name) const std::string& name)
: ctx{ctx}, is_6_channel{num_channels_ == 6}, num_channels{std::min(num_channels_, 2u)}, : ctx{ctx}, num_channels{std::min(num_channels_, 2u)}, time_stretch{sample_rate,
time_stretch{sample_rate, num_channels} { num_channels} {
cubeb_stream_params params{}; cubeb_stream_params params{};
params.rate = sample_rate; params.rate = sample_rate;
@ -57,15 +57,15 @@ public:
cubeb_stream_destroy(stream_backend); cubeb_stream_destroy(stream_backend);
} }
void EnqueueSamples(u32 num_channels, const std::vector<s16>& samples) override { void EnqueueSamples(u32 source_num_channels, const std::vector<s16>& samples) override {
if (is_6_channel) { if (source_num_channels > num_channels) {
// Downsample 6 channels to 2 // Downsample 6 channels to 2
const size_t sample_count_copy_size = samples.size() * 2;
std::vector<s16> buf; std::vector<s16> buf;
buf.reserve(sample_count_copy_size); buf.reserve(samples.size() * num_channels / source_num_channels);
for (size_t i = 0; i < samples.size(); i += num_channels) { for (size_t i = 0; i < samples.size(); i += source_num_channels) {
buf.push_back(samples[i]); for (size_t ch = 0; ch < num_channels; ch++) {
buf.push_back(samples[i + 1]); buf.push_back(samples[i + ch]);
}
} }
queue.Push(buf); queue.Push(buf);
return; return;
@ -91,7 +91,6 @@ private:
cubeb* ctx{}; cubeb* ctx{};
cubeb_stream* stream_backend{}; cubeb_stream* stream_backend{};
u32 num_channels{}; u32 num_channels{};
bool is_6_channel{};
Common::RingBuffer<s16, 0x10000> queue; Common::RingBuffer<s16, 0x10000> queue;
std::array<s16, 2> last_frame; std::array<s16, 2> last_frame;