Merge branch 'resample-drop-frame'
authorCarl Hetherington <cth@carlh.net>
Tue, 2 Oct 2012 15:14:29 +0000 (16:14 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 2 Oct 2012 15:14:29 +0000 (16:14 +0100)
1  2 
src/lib/decoder.cc
src/lib/j2k_wav_encoder.cc

Simple merge
index 08c796350c54746b586fb8b6706e98a69936b534,9b25717ef3d1cb84b2633fd342ee1081218fc6ce..87514bf14eff5999a9dc78e8eb995f6ed039c849
@@@ -267,9 -294,38 +298,36 @@@ J2KWAVEncoder::process_end (
                        e->write (_opt, (*i)->frame ());
                        frame_done ((*i)->frame ());
                } catch (std::exception& e) {
 -                      stringstream s;
 -                      s << "Local encode failed " << e.what() << ".";
 -                      _log->log (s.str ());
 +                      _log->log (String::compose ("Local encode failed (%1)", e.what ()));
                }
        }
+ #if HAVE_SWRESAMPLE   
+       if (_swr_context) {
+               while (1) {
+                       uint8_t buffer[256 * _fs->bytes_per_sample() * _fs->audio_channels];
+                       uint8_t* out[2] = {
+                               buffer,
+                               0
+                       };
+                       int const frames = swr_convert (_swr_context, out, 256, 0, 0);
+                       if (frames < 0) {
+                               throw EncodeError ("could not run sample-rate converter");
+                       }
+                       if (frames == 0) {
+                               break;
+                       }
+                       write_audio (buffer, frames * _fs->bytes_per_sample() * _fs->audio_channels);
+               }
+               swr_free (&_swr_context);
+       }
+ #endif        
        
        close_sound_files ();