Various fixes to resampling.
[dcpomatic.git] / src / lib / film_state.cc
index e0ad20417adbee8f450d241df6df144e70918cf1..0c1ac87dc76d28f6470fd624300d15d6c8db8a60 100644 (file)
@@ -35,6 +35,7 @@
 #include "format.h"
 #include "dcp_content_type.h"
 #include "util.h"
+#include "exceptions.h"
 
 using namespace std;
 using namespace boost;
@@ -165,11 +166,6 @@ FilmState::read_metadata (string k, string v)
        } else if (k == "content_digest") {
                content_digest = v;
        }
-       
-       /* Itsy bitsy hack: compute digest here if don't have one (for backwards compatibility) */
-       if (content_digest.empty() && !content.empty()) {
-               content_digest = md5_digest (content_path ());
-       }
 }
 
 
@@ -256,10 +252,13 @@ ContentType
 FilmState::content_type () const
 {
 #if BOOST_FILESYSTEM_VERSION == 3
-       string const ext = filesystem::path(content).extension().string();
+       string ext = filesystem::path(content).extension().string();
 #else
-       string const ext = filesystem::path(content).extension();
+       string ext = filesystem::path(content).extension();
 #endif
+
+       transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
+       
        if (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png") {
                return STILL;
        }
@@ -280,3 +279,23 @@ FilmState::bytes_per_sample () const
 
        return 0;
 }
+
+int
+FilmState::target_sample_rate () const
+{
+       double t = dcp_audio_sample_rate (audio_sample_rate);
+       if (rint (frames_per_second) != frames_per_second) {
+               if (fabs (frames_per_second - 23.976) < 1e-6) {
+                       /* 24fps drop-frame ie 24 * 1000 / 1001 frames per second;
+                          hence we need to resample the audio to dcp_audio_sample_rate * 1000 / 1001
+                          so that when we play it back at dcp_audio_sample_rate it is sped up
+                          by the same amount that the video is
+                       */
+                       t *= double(1000) / 1001;
+               } else {
+                       throw EncodeError ("unknown fractional frame rate");
+               }
+       }
+
+       return rint (t);
+}