Remove create-by-files method for sound and picture assets.
[libdcp.git] / src / sound_asset.cc
index 602f036ced933cdde3efe3581c679d0c6f148b49..5a1ce06b19c9bbf424126d9cd09f049dee2b5180 100644 (file)
@@ -50,12 +50,6 @@ SoundAsset::SoundAsset (boost::filesystem::path directory, boost::filesystem::pa
 
 }
 
-void
-SoundAsset::create (vector<boost::filesystem::path> const & files)
-{
-       create (boost::bind (&SoundAsset::path_from_channel, this, _1, files));
-}
-
 void
 SoundAsset::read ()
 {
@@ -77,132 +71,6 @@ SoundAsset::read ()
        _intrinsic_duration = desc.ContainerDuration;
 }
 
-boost::filesystem::path
-SoundAsset::path_from_channel (Channel channel, vector<boost::filesystem::path> const & files)
-{
-       unsigned int const c = int (channel);
-       assert (c < files.size ());
-       return files[c];
-}
-
-void
-SoundAsset::create (boost::function<boost::filesystem::path (Channel)> get_path)
-{
-       ASDCP::Rational asdcp_edit_rate (_edit_rate, 1);
-
-       assert (_channels > 0);
-       ASDCP::PCM::WAVParser* pcm_parser_channel[_channels];
-       for (int i = 0; i < _channels; ++i) {
-               pcm_parser_channel[i] = new ASDCP::PCM::WAVParser ();
-       }
-
-       Kumu::Result_t r = pcm_parser_channel[0]->OpenRead (get_path(LEFT).string().c_str(), asdcp_edit_rate);
-       if (ASDCP_FAILURE (r)) {
-               boost::throw_exception (FileError ("could not open WAV file for reading", get_path(LEFT), r));
-       }
-       
-       ASDCP::PCM::AudioDescriptor audio_desc;
-       pcm_parser_channel[0]->FillAudioDescriptor (audio_desc);
-       audio_desc.ChannelCount = 0;
-       audio_desc.BlockAlign = 0;
-       audio_desc.EditRate = asdcp_edit_rate;
-       audio_desc.AvgBps = audio_desc.AvgBps * _channels;
-
-       Channel channels[] = {
-               LEFT,
-               RIGHT,
-               CENTRE,
-               LFE,
-               LS,
-               RS,
-               /* XXX: not quite sure what these should be yet */
-               CHANNEL_7,
-               CHANNEL_8
-       };
-
-       assert (int(_channels) <= int(sizeof(channels) / sizeof(Channel)));
-
-       ASDCP::PCM::FrameBuffer* frame_buffer_channel[_channels];
-       ASDCP::PCM::AudioDescriptor* audio_desc_channel[_channels];
-       for (int i = 0; i < _channels; ++i) {
-               frame_buffer_channel[i] = new ASDCP::PCM::FrameBuffer ();
-               audio_desc_channel[i] = new ASDCP::PCM::AudioDescriptor ();
-       }
-
-       for (int i = 0; i < _channels; ++i) {
-
-               boost::filesystem::path const path = get_path (channels[i]);
-               
-               Kumu::Result_t r = pcm_parser_channel[i]->OpenRead (path.string().c_str(), asdcp_edit_rate);
-               if (ASDCP_FAILURE (r)) {
-                       boost::throw_exception (FileError ("could not open WAV file for reading", path, r));
-               }
-
-               pcm_parser_channel[i]->FillAudioDescriptor (*audio_desc_channel[i]);
-               frame_buffer_channel[i]->Capacity (ASDCP::PCM::CalcFrameBufferSize (*audio_desc_channel[i]));
-
-               audio_desc.ChannelCount += audio_desc_channel[i]->ChannelCount;
-               audio_desc.BlockAlign += audio_desc_channel[i]->BlockAlign;
-       }
-
-       ASDCP::PCM::FrameBuffer frame_buffer;
-       frame_buffer.Capacity (ASDCP::PCM::CalcFrameBufferSize (audio_desc));
-       frame_buffer.Size (ASDCP::PCM::CalcFrameBufferSize (audio_desc));
-
-       ASDCP::WriterInfo writer_info;
-       MXFAsset::fill_writer_info (&writer_info);
-
-       ASDCP::PCM::MXFWriter mxf_writer;
-       r = mxf_writer.OpenWrite (path().string().c_str(), writer_info, audio_desc);
-       if (ASDCP_FAILURE (r)) {
-               boost::throw_exception (FileError ("could not open audio MXF for writing", path().string(), r));
-       }
-       
-       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]))) {
-                               boost::throw_exception (MiscError ("could not read audio frame"));
-                       }
-               }
-
-               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;
-                               memcpy (data_s, frame, sample_size);
-                               data_s += sample_size;
-                       }
-                       offset += sample_size;
-               }
-
-               if (ASDCP_FAILURE (mxf_writer.WriteFrame (frame_buffer, _encryption_context, 0))) {
-                       boost::throw_exception (MiscError ("could not write audio MXF frame"));
-               }
-
-               if (_progress) {
-                       (*_progress) (0.5 * float (i) / _intrinsic_duration);
-               }
-       }
-
-       bool const failed = ASDCP_FAILURE (mxf_writer.Finalize());
-
-       for (int i = 0; i < _channels; ++i) {
-               delete pcm_parser_channel[i];
-               delete frame_buffer_channel[i];
-               delete audio_desc_channel[i];
-       }
-
-       if (failed) {
-               boost::throw_exception (MiscError ("could not finalise audio MXF"));
-       }
-}
-
 string
 SoundAsset::cpl_node_name () const
 {