Call processor process_end methods as required. Remove questionable padding of audio...
authorCarl Hetherington <cth@carlh.net>
Sun, 18 Nov 2012 21:03:32 +0000 (21:03 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 18 Nov 2012 21:03:32 +0000 (21:03 +0000)
src/lib/external_audio_decoder.cc
src/lib/j2k_wav_encoder.cc
src/lib/matcher.cc
src/lib/transcoder.cc

index 29668d922836fc5ceea9100d28e041690a4a7cd4..136e00fb27985d02d1a897d6ddd7731998e4d7fb 100644 (file)
@@ -106,9 +106,10 @@ ExternalAudioDecoder::pass ()
                return true;
        }
 
-       sf_count_t const block = 65536;
-
-       cout << frames << " audio frames.\n";
+       /* Do things in half second blocks as I think there may be limits
+          to what FFmpeg (and in particular the resampler) can cope with.
+       */
+       sf_count_t const block = _audio_stream->sample_rate() / 2;
 
        shared_ptr<AudioBuffers> audio (new AudioBuffers (_audio_stream->channels(), block));
        while (frames > 0) {
@@ -121,6 +122,7 @@ ExternalAudioDecoder::pass ()
                        }
                }
 
+               audio->set_frames (this_time);
                Audio (audio);
                frames -= this_time;
        }
index be1f96fd4d6e9a8d64a96daaf2e6f14608eff421..134d74623d7087cf3d508778d6ae4cfcc096d40e 100644 (file)
@@ -337,12 +337,6 @@ J2KWAVEncoder::process_end ()
 #endif
 
        if (_film->audio_stream()) {
-               int const dcp_sr = dcp_audio_sample_rate (_film->audio_stream()->sample_rate ());
-               int64_t const extra_audio_frames = dcp_sr - (_audio_frames_written % dcp_sr);
-               shared_ptr<AudioBuffers> silence (new AudioBuffers (_film->audio_stream()->channels(), extra_audio_frames));
-               silence->make_silent ();
-               write_audio (silence);
-               
                close_sound_files ();
                
                /* Rename .wav.tmp files to .wav */
index 24514bee248d31d30b6dfc2d50b444b64b4e00f6..7b443453922bf537e6e2694929f50c0363ba7579 100644 (file)
@@ -21,6 +21,7 @@
 #include "image.h"
 #include "log.h"
 
+using std::min;
 using boost::shared_ptr;
 
 Matcher::Matcher (Log* log, int sample_rate, float frames_per_second)
@@ -92,9 +93,21 @@ Matcher::process_end ()
        
        if (audio_short_by_frames > 0) {
                _log->log (String::compose ("Emitted %1 too few audio frames", audio_short_by_frames));
-               shared_ptr<AudioBuffers> b (new AudioBuffers (_channels.get(), audio_short_by_frames));
+
+               /* Do things in half second blocks as I think there may be limits
+                  to what FFmpeg (and in particular the resampler) can cope with.
+               */
+               int64_t const block = _sample_rate / 2;
+               shared_ptr<AudioBuffers> b (new AudioBuffers (_channels.get(), block));
                b->make_silent ();
-               Audio (b);
-               _audio_frames += b->frames ();
+               
+               int64_t to_do = audio_short_by_frames;
+               while (to_do > 0) {
+                       int64_t const this_time = min (to_do, block);
+                       b->set_frames (this_time);
+                       Audio (b);
+                       _audio_frames += b->frames ();
+                       to_do -= this_time;
+               }
        }
 }
index cad76af6e5e7152cbb8ed6e98dd9737b33cc273e..537b9b66452d6f4b8e30dbe4f824b9983166fb0b 100644 (file)
@@ -109,12 +109,18 @@ Transcoder::go ()
                }
                
        } catch (...) {
-               /* process_end() is important as the decoder may have worker
-                  threads that need to be cleaned up.
-               */
                _encoder->process_end ();
                throw;
        }
-
+       
+       if (_delay_line) {
+               _delay_line->process_end ();
+       }
+       if (_matcher) {
+               _matcher->process_end ();
+       }
+       if (_gain) {
+               _gain->process_end ();
+       }
        _encoder->process_end ();
 }