/*
- 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 "decryption_context.h"
#include <asdcp/AS_DCP.h>
-#include <asdcp/KM_fileio.h>
+#include <iostream>
+using std::cout;
using namespace dcp;
-using boost::shared_ptr;
-
-SoundFrame::SoundFrame (ASDCP::PCM::MXFReader* reader, int n, shared_ptr<DecryptionContext> c)
-{
- /* XXX: unfortunate guesswork on this buffer size */
- _buffer = new ASDCP::PCM::FrameBuffer (1 * Kumu::Megabyte);
-
- if (ASDCP_FAILURE (reader->ReadFrame (n, *_buffer, c->decryption()))) {
- boost::throw_exception (DCPReadError ("could not read audio frame"));
- }
-}
-SoundFrame::~SoundFrame ()
+SoundFrame::SoundFrame (ASDCP::PCM::MXFReader* reader, int n, boost::shared_ptr<const DecryptionContext> c)
+ : Frame<ASDCP::PCM::MXFReader, ASDCP::PCM::FrameBuffer> (reader, n, c)
{
- delete _buffer;
+ ASDCP::PCM::AudioDescriptor desc;
+ reader->FillAudioDescriptor (desc);
+ _channels = desc.ChannelCount;
}
-uint8_t const *
-SoundFrame::data () const
+int32_t
+SoundFrame::get (int channel, int frame) const
{
- return _buffer->RoData();
+ uint8_t const * d = data() + (frame * _channels * 3) + (channel * 3);
+ return d[0] | (d[1] << 8) | (d[2] << 16);
}
int
-SoundFrame::size () const
+SoundFrame::samples () const
{
- return _buffer->Size ();
+ return size() / (_channels * 3);
}