]> git.sesse.net Git - bmusb/commitdiff
If we get a broken audio frame, keep the previous sample rate instead of assuming...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 28 Apr 2017 23:45:30 +0000 (01:45 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 28 Apr 2017 23:45:30 +0000 (01:45 +0200)
bmusb.cpp

index 663a235f05a75698283d6dd5f5ea59295c2f0db3..e9f89e251452ed3bccf88b0dd7f5a2697a8b8d34 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -243,7 +243,7 @@ bool decode_video_format(uint16_t video_format, VideoFormat *decoded_video_forma
 
 // There are seemingly no direct indicators of sample rate; you just get
 // one frame's worth and have to guess from that.
-int guess_sample_rate(const VideoFormat &video_format, size_t len)
+int guess_sample_rate(const VideoFormat &video_format, size_t len, int default_rate)
 {
        size_t num_samples = len / 3 / 8;
        size_t num_samples_per_second = num_samples * video_format.frame_rate_nom / video_format.frame_rate_den;
@@ -256,9 +256,9 @@ int guess_sample_rate(const VideoFormat &video_format, size_t len)
                }
        }
 
-       fprintf(stderr, "%ld samples at %d/%d fps (%ld Hz) matches no known sample rate, assuming 48000 Hz\n",
-               num_samples, video_format.frame_rate_nom, video_format.frame_rate_den, num_samples_per_second);
-       return 48000;
+       fprintf(stderr, "%ld samples at %d/%d fps (%ld Hz) matches no known sample rate, keeping capture at %d Hz\n",
+               num_samples, video_format.frame_rate_nom, video_format.frame_rate_den, num_samples_per_second, default_rate);
+       return default_rate;
 }
 
 }  // namespace
@@ -406,7 +406,7 @@ void BMUSBCapture::dequeue_thread_func()
                        audio_format.id = audio_frame.format;
                        if (decode_video_format(video_frame.format, &video_format)) {
                                if (audio_frame.frame.len != 0) {
-                                       audio_format.sample_rate = guess_sample_rate(video_format, audio_frame.frame.len);
+                                       audio_format.sample_rate = guess_sample_rate(video_format, audio_frame.frame.len, last_sample_rate);
                                        last_sample_rate = audio_format.sample_rate;
                                }
                                frame_callback(video_timecode,