From: Steinar H. Gunderson Date: Sat, 27 Feb 2016 15:08:01 +0000 (+0100) Subject: Send the audio format explicitly down, not just the ID. X-Git-Tag: 1.2.0~58 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=7d23b62323aba8fa396f6abc617c39e8c634b023;p=nageru Send the audio format explicitly down, not just the ID. --- diff --git a/bmusb b/bmusb index b3aaee8..30a75fd 160000 --- a/bmusb +++ b/bmusb @@ -1 +1 @@ -Subproject commit b3aaee8df3039891d79f4f673e6a8050d3fb65b5 +Subproject commit 30a75fd8110601c89ecc7c1a0832a96878917cd4 diff --git a/decklink_capture.cpp b/decklink_capture.cpp index e7f8eba..6680de1 100644 --- a/decklink_capture.cpp +++ b/decklink_capture.cpp @@ -149,6 +149,7 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived( FrameAllocator::Frame current_video_frame, current_audio_frame; VideoFormat video_format; + AudioFormat audio_format; if (video_frame) { video_format.has_signal = !(video_frame->GetFlags() & bmdFrameHasNoInputSource); @@ -174,12 +175,27 @@ HRESULT STDMETHODCALLTYPE DeckLinkCapture::VideoInputFrameArrived( } } + if (audio_frame) { + int num_samples = audio_frame->GetSampleFrameCount(); + + current_audio_frame = audio_frame_allocator->alloc_frame(); + if (current_audio_frame.data != nullptr) { + const uint8_t *frame_bytes; + audio_frame->GetBytes((void **)&frame_bytes); + + memcpy(current_audio_frame.data, frame_bytes, sizeof(int32_t) * 2 * num_samples); + + audio_format.bits_per_sample = 32; + audio_format.num_channels = 2; + } + } + if (current_video_frame.data != nullptr || current_audio_frame.data != nullptr) { // TODO: Put into a queue and put into a dequeue thread, if the // BlackMagic drivers don't already do that for us? frame_callback(timecode, current_video_frame, /*video_offset=*/0, video_format, - current_audio_frame, /*audio_offset=*/0, 0x0000); + current_audio_frame, /*audio_offset=*/0, audio_format); } timecode++; diff --git a/mixer.cpp b/mixer.cpp index 3b602bf..e8c9a75 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -310,7 +310,7 @@ void deinterleave_samples(const vector &in, vector *out_l, vector< void Mixer::bm_frame(unsigned card_index, uint16_t timecode, FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format, - FrameAllocator::Frame audio_frame, size_t audio_offset, uint16_t audio_format) + FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format) { CaptureCard *card = &cards[card_index]; @@ -339,7 +339,14 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode, // Convert the audio to stereo fp32 and add it. vector audio; audio.resize(num_samples * 2); - convert_fixed24_to_fp32(&audio[0], 2, audio_frame.data + audio_offset, 8, num_samples); + switch (audio_format.bits_per_sample) { + case 24: + convert_fixed24_to_fp32(&audio[0], 2, audio_frame.data + audio_offset, audio_format.num_channels, num_samples); + break; + default: + fprintf(stderr, "Cannot handle audio with %u bits per sample\n", audio_format.bits_per_sample); + assert(false); + } // Add the audio. { diff --git a/mixer.h b/mixer.h index 8f37f38..00b10f8 100644 --- a/mixer.h +++ b/mixer.h @@ -245,7 +245,7 @@ private: void configure_card(unsigned card_index, const QSurfaceFormat &format, CaptureInterface *capture); void bm_frame(unsigned card_index, uint16_t timecode, FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format, - FrameAllocator::Frame audio_frame, size_t audio_offset, uint16_t audio_format); + FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format); void place_rectangle(movit::Effect *resample_effect, movit::Effect *padding_effect, float x0, float y0, float x1, float y1); void thread_func(); void audio_thread_func();