summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2024-05-24 23:41:53 +0200
committerCarl Hetherington <cth@carlh.net>2024-05-24 23:41:56 +0200
commit0bbb2e9c99845ce7b6056048356a9710119cdbd9 (patch)
treeeb70a2aa59f63de542ab4e813cec5785bb4f764a
parentcc6a2fe7ee05718d549e72eb740d0eae290f8ecb (diff)
Report bit depth from sound frame, and handle 16-bit.v1.9.8
-rw-r--r--src/sound_frame.cc22
-rw-r--r--src/sound_frame.h8
2 files changed, 25 insertions, 5 deletions
diff --git a/src/sound_frame.cc b/src/sound_frame.cc
index 25845d88..4d90c9c2 100644
--- a/src/sound_frame.cc
+++ b/src/sound_frame.cc
@@ -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);
}
diff --git a/src/sound_frame.h b/src/sound_frame.h
index 0f5021e2..72ab5925 100644
--- a/src/sound_frame.h
+++ b/src/sound_frame.h
@@ -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;
};