X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mixer.cpp;h=96668c840b2ca855e76e3a86f7e6b5956d0956ba;hb=20706e7944f3edd371504be43ebe76ce24778698;hp=fd33abbb18f35d3569b89f4d673c37e9e7a92365;hpb=6f4f5d4a13df2e4562cb9c145fa5b60be2ae63d0;p=nageru diff --git a/mixer.cpp b/mixer.cpp index fd33abb..96668c8 100644 --- a/mixer.cpp +++ b/mixer.cpp @@ -62,7 +62,7 @@ void convert_fixed24_to_fp32(float *dst, size_t out_channels, const uint8_t *src uint32_t s2 = *src++; uint32_t s3 = *src++; uint32_t s = s1 | (s1 << 8) | (s2 << 16) | (s3 << 24); - dst[i * out_channels + j] = int(s) * (1.0f / 4294967296.0f); + dst[i * out_channels + j] = int(s) * (1.0f / 2147483648.0f); } src += 3 * (in_channels - out_channels); } @@ -75,7 +75,7 @@ void convert_fixed32_to_fp32(float *dst, size_t out_channels, const uint8_t *src for (size_t j = 0; j < out_channels; ++j) { // Note: Assumes little-endian. int32_t s = *(int32_t *)src; - dst[i * out_channels + j] = s * (1.0f / 4294967296.0f); + dst[i * out_channels + j] = s * (1.0f / 2147483648.0f); src += 4; } src += 4 * (in_channels - out_channels); @@ -201,7 +201,8 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards) unsigned num_fake_cards = 0; for ( ; card_index < num_cards; ++card_index, ++num_fake_cards) { - configure_card(card_index, new FakeCapture(WIDTH, HEIGHT, FAKE_FPS, OUTPUT_FREQUENCY, card_index), /*is_fake_capture=*/true); + FakeCapture *capture = new FakeCapture(WIDTH, HEIGHT, FAKE_FPS, OUTPUT_FREQUENCY, card_index, global_flags.fake_cards_audio); + configure_card(card_index, capture, /*is_fake_capture=*/true); } if (num_fake_cards > 0) { @@ -817,7 +818,8 @@ void Mixer::handle_hotplugged_cards() CaptureCard *card = &cards[card_index]; if (card->capture->get_disconnected()) { fprintf(stderr, "Card %u went away, replacing with a fake card.\n", card_index); - configure_card(card_index, new FakeCapture(WIDTH, HEIGHT, FAKE_FPS, OUTPUT_FREQUENCY, card_index), /*is_fake_capture=*/true); + FakeCapture *capture = new FakeCapture(WIDTH, HEIGHT, FAKE_FPS, OUTPUT_FREQUENCY, card_index, global_flags.fake_cards_audio); + configure_card(card_index, capture, /*is_fake_capture=*/true); card->queue_length_policy.reset(card_index); card->capture->start_bm_capture(); } @@ -1058,21 +1060,6 @@ void Mixer::process_audio_one_frame(int64_t frame_pts_int, int num_samples) // printf("limiter=%+5.1f compressor=%+5.1f\n", 20.0*log10(limiter_att), 20.0*log10(compressor_att)); - // Upsample 4x to find interpolated peak. - peak_resampler.inp_data = samples_out.data(); - peak_resampler.inp_count = samples_out.size() / 2; - - vector interpolated_samples_out; - interpolated_samples_out.resize(samples_out.size()); - while (peak_resampler.inp_count > 0) { // About four iterations. - peak_resampler.out_data = &interpolated_samples_out[0]; - peak_resampler.out_count = interpolated_samples_out.size() / 2; - peak_resampler.process(); - size_t out_stereo_samples = interpolated_samples_out.size() / 2 - peak_resampler.out_count; - peak = max(peak, find_peak(interpolated_samples_out.data(), out_stereo_samples * 2)); - peak_resampler.out_data = nullptr; - } - // At this point, we are most likely close to +0 LU, but all of our // measurements have been on raw sample values, not R128 values. // So we have a final makeup gain to get us to +0 LU; the gain @@ -1113,6 +1100,21 @@ void Mixer::process_audio_one_frame(int64_t frame_pts_int, int num_samples) final_makeup_gain = m; } + // Upsample 4x to find interpolated peak. + peak_resampler.inp_data = samples_out.data(); + peak_resampler.inp_count = samples_out.size() / 2; + + vector interpolated_samples_out; + interpolated_samples_out.resize(samples_out.size()); + while (peak_resampler.inp_count > 0) { // About four iterations. + peak_resampler.out_data = &interpolated_samples_out[0]; + peak_resampler.out_count = interpolated_samples_out.size() / 2; + peak_resampler.process(); + size_t out_stereo_samples = interpolated_samples_out.size() / 2 - peak_resampler.out_count; + peak = max(peak, find_peak(interpolated_samples_out.data(), out_stereo_samples * 2)); + peak_resampler.out_data = nullptr; + } + // Find R128 levels and L/R correlation. vector left, right; deinterleave_samples(samples_out, &left, &right);