]> git.sesse.net Git - nageru/blobdiff - mixer.cpp
Hook up the level compressor auto checkbox.
[nageru] / mixer.cpp
index 61050067b7b9dd60c652a855336eea54f68dec9d..dd8cc6013d72559bb08b89c6d5605953ac6b4269 100644 (file)
--- a/mixer.cpp
+++ b/mixer.cpp
@@ -74,10 +74,27 @@ void insert_new_frame(RefCountedFrame frame, unsigned field_num, bool interlaced
        }
 }
 
+string generate_local_dump_filename(int frame)
+{
+       time_t now = time(NULL);
+       tm now_tm;
+       localtime_r(&now, &now_tm);
+
+       char timestamp[256];
+       strftime(timestamp, sizeof(timestamp), "%F-%T%z", &now_tm);
+
+       // Use the frame number to disambiguate between two cuts starting
+       // on the same second.
+       char filename[256];
+       snprintf(filename, sizeof(filename), "%s%s-f%02d%s",
+               LOCAL_DUMP_PREFIX, timestamp, frame % 100, LOCAL_DUMP_SUFFIX);
+       return filename;
+}
+
 }  // namespace
 
 Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards)
-       : httpd(LOCAL_DUMP_FILE_NAME, WIDTH, HEIGHT),
+       : httpd(WIDTH, HEIGHT),
          num_cards(num_cards),
          mixer_surface(create_surface(format)),
          h264_encoder_surface(create_surface(format)),
@@ -85,6 +102,7 @@ Mixer::Mixer(const QSurfaceFormat &format, unsigned num_cards)
          limiter(OUTPUT_FREQUENCY),
          compressor(OUTPUT_FREQUENCY)
 {
+       httpd.open_output_file(generate_local_dump_filename(/*frame=*/0).c_str());
        httpd.start(9095);
 
        CHECK(init_movit(MOVIT_SHADER_DIR, MOVIT_DEBUG_OFF));
@@ -204,7 +222,7 @@ float find_peak(const float *samples, size_t num_samples)
 {
        float m = fabs(samples[0]);
        for (size_t i = 1; i < num_samples; ++i) {
-               m = std::max(m, fabs(samples[i]));
+               m = max(m, fabs(samples[i]));
        }
        return m;
 }
@@ -626,6 +644,15 @@ void Mixer::thread_func()
                //      chain->print_phase_timing();
                }
 
+               if (should_cut.exchange(false)) {  // Test and clear.
+                       string filename = generate_local_dump_filename(frame);
+                       printf("Starting new recording: %s\n", filename.c_str());
+                       h264_encoder->shutdown();
+                       httpd.close_output_file();
+                       httpd.open_output_file(filename.c_str());
+                       h264_encoder.reset(new H264Encoder(h264_encoder_surface, WIDTH, HEIGHT, &httpd));
+               }
+
 #if 0
                // Reset every 100 frames, so that local variations in frame times
                // (especially for the first few frames, when the shaders are
@@ -688,8 +715,7 @@ void Mixer::process_audio_one_frame(int64_t frame_pts_int, int num_samples)
        // then apply a makeup gain to get it to -14 dBFS. -14 dBFS is, of course,
        // entirely arbitrary, but from practical tests with speech, it seems to
        // put ut around -23 LUFS, so it's a reasonable starting point for later use.
-       float ref_level_dbfs = -14.0f;
-       {
+       if (level_compressor_enabled) {
                float threshold = 0.01f;   // -40 dBFS.
                float ratio = 20.0f;
                float attack_time = 0.5f;