using namespace libdcp;
SoundAsset::SoundAsset (
- vector<string> const & files, string directory, string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int length
+ vector<string> const & files,
+ string directory,
+ string mxf_name,
+ boost::signals2::signal<void (float)>* progress,
+ int fps, int intrinsic_duration, int start_frame
)
- : MXFAsset (directory, mxf_name, progress, fps, 0, length)
+ : MXFAsset (directory, mxf_name, progress, fps, intrinsic_duration)
, _channels (files.size ())
, _sampling_rate (0)
+ , _start_frame (start_frame)
{
+ assert (_channels);
+
construct (boost::bind (&SoundAsset::path_from_channel, this, _1, files));
}
string directory,
string mxf_name,
boost::signals2::signal<void (float)>* progress,
- int fps, int length, int channels
+ int fps, int intrinsic_duration, int start_frame, int channels
)
- : MXFAsset (directory, mxf_name, progress, fps, 0, length)
+ : MXFAsset (directory, mxf_name, progress, fps, intrinsic_duration)
, _channels (channels)
, _sampling_rate (0)
+ , _start_frame (start_frame)
{
+ assert (_channels);
+
construct (get_path);
}
-SoundAsset::SoundAsset (string directory, string mxf_name, int fps, int entry_point, int length)
- : MXFAsset (directory, mxf_name, 0, fps, entry_point, length)
+SoundAsset::SoundAsset (string directory, string mxf_name, int fps, int intrinsic_duration)
+ : MXFAsset (directory, mxf_name, 0, fps, intrinsic_duration)
, _channels (0)
+ , _start_frame (0)
{
ASDCP::PCM::MXFReader reader;
if (ASDCP_FAILURE (reader.OpenRead (path().string().c_str()))) {
SoundAsset::construct (boost::function<string (Channel)> get_path)
{
ASDCP::Rational asdcp_fps (_fps, 1);
-
+
ASDCP::PCM::WAVParser pcm_parser_channel[_channels];
if (pcm_parser_channel[0].OpenRead (get_path(LEFT).c_str(), asdcp_fps)) {
throw FileError ("could not open WAV file for reading", get_path(LEFT));
frame_buffer.Size (ASDCP::PCM::CalcFrameBufferSize (audio_desc));
ASDCP::WriterInfo writer_info;
- fill_writer_info (&writer_info);
+ fill_writer_info (&writer_info, _uuid);
ASDCP::PCM::MXFWriter mxf_writer;
if (ASDCP_FAILURE (mxf_writer.OpenWrite (path().string().c_str(), writer_info, audio_desc))) {
throw FileError ("could not open audio MXF for writing", path().string());
}
- for (int i = 0; i < _length; ++i) {
-
- byte_t *data_s = frame_buffer.Data();
- byte_t *data_e = data_s + frame_buffer.Capacity();
- byte_t sample_size = ASDCP::PCM::CalcSampleSize (audio_desc_channel[0]);
- int offset = 0;
+ /* Skip through up to our _start_frame; this is pretty inefficient... */
+ for (int i = 0; i < _start_frame; ++i) {
+ for (int j = 0; j < _channels; ++j) {
+ if (ASDCP_FAILURE (pcm_parser_channel[j].ReadFrame (frame_buffer_channel[j]))) {
+ throw MiscError ("could not read audio frame");
+ }
+ }
+ }
+
+ for (int i = 0; i < _intrinsic_duration; ++i) {
for (int j = 0; j < _channels; ++j) {
memset (frame_buffer_channel[j].Data(), 0, frame_buffer_channel[j].Capacity());
if (ASDCP_FAILURE (pcm_parser_channel[j].ReadFrame (frame_buffer_channel[j]))) {
throw MiscError ("could not read audio frame");
}
-
- if (frame_buffer_channel[j].Size() != frame_buffer_channel[j].Capacity()) {
- stringstream s;
- s << "short audio frame; " << _channels << " channels, "
- << frame_buffer_channel[j].Size() << " vs " << frame_buffer_channel[j].Capacity();
- throw MiscError (s.str ());
- }
}
+ byte_t *data_s = frame_buffer.Data();
+ byte_t *data_e = data_s + frame_buffer.Capacity();
+ byte_t sample_size = ASDCP::PCM::CalcSampleSize (audio_desc_channel[0]);
+ int offset = 0;
+
while (data_s < data_e) {
for (int j = 0; j < _channels; ++j) {
byte_t* frame = frame_buffer_channel[j].Data() + offset;
}
if (_progress) {
- (*_progress) (0.5 * float (i) / _length);
+ (*_progress) (0.5 * float (i) / _intrinsic_duration);
}
}
<< " <Id>urn:uuid:" << _uuid << "</Id>\n"
<< " <AnnotationText>" << _file_name << "</AnnotationText>\n"
<< " <EditRate>" << _fps << " 1</EditRate>\n"
- << " <IntrinsicDuration>" << _length << "</IntrinsicDuration>\n"
- << " <EntryPoint>0</EntryPoint>\n"
- << " <Duration>" << _length << "</Duration>\n"
+ << " <IntrinsicDuration>" << _intrinsic_duration << "</IntrinsicDuration>\n"
+ << " <EntryPoint>" << _entry_point << "</EntryPoint>\n"
+ << " <Duration>" << _duration << "</Duration>\n"
<< " </MainSound>\n";
}
ASDCP::PCM::FrameBuffer buffer_A (1 * Kumu::Megabyte);
ASDCP::PCM::FrameBuffer buffer_B (1 * Kumu::Megabyte);
- for (int i = 0; i < _length; ++i) {
+ for (int i = 0; i < _intrinsic_duration; ++i) {
if (ASDCP_FAILURE (reader_A.ReadFrame (i, buffer_A))) {
throw DCPReadError ("could not read audio frame");
}