Access sound asset sampling rate, channels; access sound asset from DCP; fix bad...
[libdcp.git] / src / sound_asset.cc
index 71d1d9ff0a29e0f5185a98ea818e1c677da7cfb3..a8b6372748c83069221fc95790bc5b8b36f6215e 100644 (file)
@@ -232,7 +232,7 @@ SoundAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
                        }
 
                        if (buffer_A.Size() != buffer_B.Size()) {
-                               notes.push_back ("sizes of video data for frame " + lexical_cast<string>(i) + " differ");
+                               notes.push_back ("sizes of audio data for frame " + lexical_cast<string>(i) + " differ");
                                continue;
                        }
 
@@ -245,3 +245,22 @@ SoundAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt) const
 
        return notes;
 }
+
+
+int
+SoundAsset::sampling_rate () const
+{
+       ASDCP::PCM::MXFReader reader;
+       if (ASDCP_FAILURE (reader.OpenRead (mxf_path().string().c_str()))) {
+               throw FileError ("could not open MXF file for reading", mxf_path().string());
+       }
+
+       
+       ASDCP::PCM::AudioDescriptor desc;
+       if (ASDCP_FAILURE (reader.FillAudioDescriptor (desc))) {
+               throw DCPReadError ("could not read audio MXF information");
+       }
+
+       return desc.AudioSamplingRate.Numerator / desc.AudioSamplingRate.Denominator;
+}
+