card_copy[card_index].new_data_ready = card->new_data_ready;
card_copy[card_index].new_frame = card->new_frame;
card_copy[card_index].new_data_ready_fence = card->new_data_ready_fence;
- card_copy[card_index].new_frame_audio = move(card->new_frame_audio);
card_copy[card_index].dropped_frames = card->dropped_frames;
card->new_data_ready = false;
card->new_data_ready_changed.notify_all();
}
// Resample the audio as needed, including from previously dropped frames.
- vector<float> samples_out;
- // TODO: Allow using audio from the other card(s) as well.
for (unsigned frame_num = 0; frame_num < card_copy[0].dropped_frames + 1; ++frame_num) {
- for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
- samples_out.resize((48000 / 60) * 2);
- {
- unique_lock<mutex> lock(cards[card_index].audio_mutex);
- if (!cards[card_index].resampler->get_output_samples(pts(), &samples_out[0], 48000 / 60)) {
- printf("Card %d reported previous underrun.\n", card_index);
- }
- }
- if (card_index == 0) {
- vector<float> left, right;
- peak = std::max(peak, find_peak(samples_out));
- deinterleave_samples(samples_out, &left, &right);
- float *ptrs[] = { left.data(), right.data() };
- r128.process(left.size(), ptrs);
- h264_encoder->add_audio(pts_int, move(samples_out));
- }
- }
+ process_audio_one_frame();
if (frame_num != card_copy[0].dropped_frames) {
// For dropped frames, increase the pts.
++dropped_frames;
resource_pool->clean_context();
}
+void Mixer::process_audio_one_frame()
+{
+ vector<float> samples_card;
+ vector<float> samples_out;
+ for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
+ samples_card.resize((48000 / 60) * 2);
+ {
+ unique_lock<mutex> lock(cards[card_index].audio_mutex);
+ if (!cards[card_index].resampler->get_output_samples(pts(), &samples_card[0], 48000 / 60)) {
+ printf("Card %d reported previous underrun.\n", card_index);
+ }
+ }
+ // TODO: Allow using audio from the other card(s) as well.
+ if (card_index == 0) {
+ samples_out = move(samples_card);
+ }
+ }
+
+ // Find peak and R128 levels.
+ peak = std::max(peak, find_peak(samples_out));
+ vector<float> left, right;
+ deinterleave_samples(samples_out, &left, &right);
+ float *ptrs[] = { left.data(), right.data() };
+ r128.process(left.size(), ptrs);
+
+ // Actually add the samples to the output.
+ h264_encoder->add_audio(pts_int, move(samples_out));
+}
+
void Mixer::subsample_chroma(GLuint src_tex, GLuint dst_tex)
{
GLuint vao;