Report bit depth from sound frame, and handle 16-bit. v1.9.x v1.9.8
authorCarl Hetherington <cth@carlh.net>
Fri, 24 May 2024 21:41:53 +0000 (23:41 +0200)
committerCarl Hetherington <cth@carlh.net>
Fri, 24 May 2024 21:41:56 +0000 (23:41 +0200)
src/sound_frame.cc
src/sound_frame.h

index 25845d88332e0d02c73d1772fdeaecffc8f755b3..4d90c9c21ee13e5872aad31c943c6b1d8a883df2 100644 (file)
@@ -37,6 +37,7 @@
  */
 
 
+#include "dcp_assert.h"
 #include "sound_frame.h"
 #include <asdcp/AS_DCP.h>
 #include <iostream>
@@ -52,15 +53,28 @@ SoundFrame::SoundFrame (ASDCP::PCM::MXFReader* reader, int n, std::shared_ptr<co
        ASDCP::PCM::AudioDescriptor desc;
        reader->FillAudioDescriptor (desc);
        _channels = desc.ChannelCount;
+       _bits = desc.QuantizationBits;
 }
 
 
 int32_t
 SoundFrame::get (int channel, int frame) const
 {
-       uint8_t const * d = data() + (frame * _channels * 3) + (channel * 3);
-       /* This is slightly dubious I think */
-       return (d[0] << 8 | (d[1] << 16) | (d[2] << 24)) >> 8;
+       switch (_bits) {
+       case 24:
+       {
+               uint8_t const * d = data() + (frame * _channels * 3) + (channel * 3);
+               /* This is slightly dubious I think */
+               return (d[0] << 8 | (d[1] << 16) | (d[2] << 24)) >> 8;
+       }
+       case 16:
+       {
+               uint8_t const * d = data() + (frame * _channels * 2) + (channel * 2);
+               return d[0] | (d[1] << 8);
+       }
+       default:
+               DCP_ASSERT(false);
+       }
 }
 
 
@@ -74,5 +88,5 @@ SoundFrame::channels () const
 int
 SoundFrame::samples () const
 {
-       return size() / (_channels * 3);
+       return size() / (_channels * _bits / 8);
 }
index 0f5021e20d11fd53a2cd028585c8d9532fb447a2..72ab5925c13a510ba991225a84f393b0a667b7ac 100644 (file)
@@ -54,10 +54,16 @@ public:
        SoundFrame (ASDCP::PCM::MXFReader* reader, int n, std::shared_ptr<const DecryptionContext> c, bool check_hmac);
        int channels () const;
        int samples () const;
+
+       int bits() const {
+               return _bits;
+       }
+
        int32_t get (int channel, int sample) const;
 
 private:
-       int _channels = 0;
+       int _channels;
+       int _bits;
 };