From: Steinar H. Gunderson Date: Sun, 11 Sep 2016 16:48:32 +0000 (+0200) Subject: Make FakeCapture output 8-channel sound, to match the real cards. X-Git-Tag: 0.5.2~3 X-Git-Url: https://git.sesse.net/?p=bmusb;a=commitdiff_plain;h=a765e066b74ac52ff0abf239d430d6f8d83f792e Make FakeCapture output 8-channel sound, to match the real cards. --- diff --git a/bmusb/fake_capture.h b/bmusb/fake_capture.h index 17982ea..ad432f7 100644 --- a/bmusb/fake_capture.h +++ b/bmusb/fake_capture.h @@ -79,7 +79,7 @@ public: private: void producer_thread_func(); - void make_tone(int32_t *out, unsigned num_stereo_samples); + void make_tone(int32_t *out, unsigned num_stereo_samples, unsigned num_channels); unsigned width, height, fps, audio_sample_frequency; uint8_t y, cb, cr; diff --git a/fake_capture.cpp b/fake_capture.cpp index 961700e..5f53e95 100644 --- a/fake_capture.cpp +++ b/fake_capture.cpp @@ -259,19 +259,19 @@ void FakeCapture::producer_thread_func() AudioFormat audio_format; audio_format.bits_per_sample = 32; - audio_format.num_channels = 2; + audio_format.num_channels = 8; FrameAllocator::Frame audio_frame = audio_frame_allocator->alloc_frame(); if (audio_frame.data != nullptr) { const unsigned num_stereo_samples = audio_sample_frequency / fps; - assert(audio_frame.size >= 2 * sizeof(int32_t) * num_stereo_samples); - audio_frame.len = 2 * sizeof(int32_t) * num_stereo_samples; + assert(audio_frame.size >= audio_format.num_channels * sizeof(int32_t) * num_stereo_samples); + audio_frame.len = audio_format.num_channels * sizeof(int32_t) * num_stereo_samples; if (audio_sin == 0.0f) { // Silence. memset(audio_frame.data, 0, audio_frame.len); } else { - make_tone((int32_t *)audio_frame.data, num_stereo_samples); + make_tone((int32_t *)audio_frame.data, num_stereo_samples, audio_format.num_channels); } } @@ -284,14 +284,15 @@ void FakeCapture::producer_thread_func() } } -void FakeCapture::make_tone(int32_t *out, unsigned num_stereo_samples) +void FakeCapture::make_tone(int32_t *out, unsigned num_stereo_samples, unsigned num_channels) { int32_t *ptr = out; float r = audio_real, i = audio_imag; for (unsigned sample_num = 0; sample_num < num_stereo_samples; ++sample_num) { int32_t s = lrintf(r); - *ptr++ = s; - *ptr++ = s; + for (unsigned i = 0; i < num_channels; ++i) { + *ptr++ = s; + } // Rotate the phaser by one sample. float new_r = r * audio_cos - i * audio_sin;