Read 16-bit audio DCPs correctly.
authorCarl Hetherington <cth@carlh.net>
Fri, 24 May 2024 21:50:03 +0000 (23:50 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 24 May 2024 21:50:04 +0000 (23:50 +0200)
As far as I can tell they are totally non-standard, but apparently
the IMS3000 plays them so I guess we should too.

cscript
src/lib/dcp_decoder.cc

diff --git a/cscript b/cscript
index 3bb77e1787c5985385d5b4df26807b1edcbc6fa9..60d1825ca162c43ff3c72e5e0b5dcd4c2e456206 100644 (file)
--- a/cscript
+++ b/cscript
@@ -533,7 +533,7 @@ def make_spec(filename, version, target, options, requires=None):
     print('/usr/bin/gtk-update-icon-cache %{_datadir}/icons/hicolor &>/dev/null || :', file=f)
 
 def dependencies(target, options):
-    deps = [('libdcp', 'cc6a2fe7ee05718d549e72eb740d0eae290f8ecb', {'c++17': target.platform == 'osx'})]
+    deps = [('libdcp', 'v1.9.8', {'c++17': target.platform == 'osx'})]
     deps.append(('libsub', 'v1.6.47'))
     deps.append(('leqm-nrt', '30dcaea1373ac62fba050e02ce5b0c1085797a23'))
     deps.append(('rtaudio', 'f619b76'))
index 84b51cae8a3011f4916b18f0eb3192a62b49f6ad..e9db479d19cb94c118145ab127163fabc2744351 100644 (file)
@@ -235,15 +235,32 @@ DCPDecoder::pass ()
                auto sf = _sound_reader->get_frame (entry_point + frame);
                auto from = sf->data ();
 
-               int const channels = _dcp_content->audio->stream()->channels ();
-               int const frames = sf->size() / (3 * channels);
+               int const channels = _dcp_content->audio->stream()->channels();
+               int const frames = sf->size() / (sf->bits() * channels / 8);
                auto data = make_shared<AudioBuffers>(channels, frames);
                auto data_data = data->data();
-               for (int i = 0; i < frames; ++i) {
-                       for (int j = 0; j < channels; ++j) {
-                               data_data[j][i] = static_cast<int> ((from[0] << 8) | (from[1] << 16) | (from[2] << 24)) / static_cast<float> (INT_MAX - 256);
-                               from += 3;
+
+               switch (sf->bits()) {
+               case 24:
+               {
+                       for (int i = 0; i < frames; ++i) {
+                               for (int j = 0; j < channels; ++j) {
+                                       data_data[j][i] = static_cast<int>((from[0] << 8) | (from[1] << 16) | (from[2] << 24)) / static_cast<float> (INT_MAX - 256);
+                                       from += 3;
+                               }
+                       }
+                       break;
+               }
+               case 16:
+               {
+                       for (int i = 0; i < frames; ++i) {
+                               for (int j = 0; j < channels; ++j) {
+                                       data_data[j][i] = static_cast<int>(from[0] << 16 | (from[1] << 24)) / static_cast<float> (INT_MAX - 256);
+                                       from += 2;
+                               }
                        }
+                       break;
+               }
                }
 
                audio->emit (film(), _dcp_content->audio->stream(), data, ContentTime::from_frames (_offset, vfr) + _next);