Bv2.1 7.2.3: Check that subtitle <StartTime> exists and is 0.
[libdcp.git] / src / sound_frame.cc
index 83b053b2c92efdc85b5a7503487fc012dc4ab60e..821a88660155c8e8d162068582d61bedee4ced25 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
     files in the program, then also delete it here.
 */
 
-/** @file  src/sound_frame.cc
- *  @brief SoundFrame class.
- */
-
 #include "sound_frame.h"
-#include "exceptions.h"
 #include <asdcp/AS_DCP.h>
-#include <asdcp/KM_fileio.h>
+#include <iostream>
 
-using namespace std;
+using std::cout;
 using namespace dcp;
 
-SoundFrame::SoundFrame (ASDCP::PCM::MXFReader* reader, int n, ASDCP::AESDecContext* c)
+SoundFrame::SoundFrame (ASDCP::PCM::MXFReader* reader, int n, std::shared_ptr<const DecryptionContext> c)
+       : Frame<ASDCP::PCM::MXFReader, ASDCP::PCM::FrameBuffer> (reader, n, c)
 {
-       /* XXX: unfortunate guesswork on this buffer size */
-       _buffer = new ASDCP::PCM::FrameBuffer (1 * Kumu::Megabyte);
-
-       if (ASDCP_FAILURE (reader->ReadFrame (n, *_buffer, c))) {
-               boost::throw_exception (DCPReadError ("could not read audio frame"));
-       }
+       ASDCP::PCM::AudioDescriptor desc;
+       reader->FillAudioDescriptor (desc);
+       _channels = desc.ChannelCount;
 }
 
-SoundFrame::~SoundFrame ()
+int32_t
+SoundFrame::get (int channel, int frame) const
 {
-       delete _buffer;
+       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;
 }
 
-uint8_t const *
-SoundFrame::data () const
+int
+SoundFrame::channels () const
 {
-       return _buffer->RoData();
+       return _channels;
 }
 
 int
-SoundFrame::size () const
+SoundFrame::samples () const
 {
-       return _buffer->Size ();
+       return size() / (_channels * 3);
 }