]> granicus.if.org Git - taglib/commitdiff
Added sampleFrames to FLACProperties
authorStephen F. Booth <me@sbooth.org>
Sat, 4 Feb 2012 16:34:40 +0000 (11:34 -0500)
committerStephen F. Booth <me@sbooth.org>
Sat, 4 Feb 2012 16:34:40 +0000 (11:34 -0500)
taglib/flac/flacproperties.cpp
taglib/flac/flacproperties.h

index d36d26ec640625041d304429dcee02a749df6fd7..8bdc5d8dc19531085a178f772b50f909b5dc3c07 100644 (file)
@@ -42,7 +42,8 @@ public:
     bitrate(0),
     sampleRate(0),
     sampleWidth(0),
-    channels(0) {}
+    channels(0),
+    sampleFrames(0) {}
 
   ByteVector data;
   long streamLength;
@@ -52,6 +53,7 @@ public:
   int sampleRate;
   int sampleWidth;
   int channels;
+  unsigned long long sampleFrames;
   ByteVector signature;
 };
 
@@ -101,6 +103,11 @@ int FLAC::Properties::channels() const
   return d->channels;
 }
 
+unsigned long long FLAC::Properties::sampleFrames() const
+{
+  return d->sampleFrames;
+}
+
 ByteVector FLAC::Properties::signature() const
 {
   return d->signature;
@@ -132,6 +139,8 @@ void FLAC::Properties::read()
   pos += 3;
 
   uint flags = d->data.mid(pos, 4).toUInt(true);
+  pos += 4;
+
   d->sampleRate = flags >> 12;
   d->channels = ((flags >> 9) & 7) + 1;
   d->sampleWidth = ((flags >> 4) & 31) + 1;
@@ -139,12 +148,14 @@ void FLAC::Properties::read()
   // The last 4 bits are the most significant 4 bits for the 36 bit
   // stream length in samples. (Audio files measured in days)
 
-  uint highLength =d->sampleRate > 0 ? (((flags & 0xf) << 28) / d->sampleRate) << 4 : 0;
+  unsigned long long hi = flags & 0xf;
+  unsigned long long lo = d->data.mid(pos, 4).toUInt(true);
   pos += 4;
 
-  d->length = d->sampleRate > 0 ?
-      (d->data.mid(pos, 4).toUInt(true)) / d->sampleRate + highLength : 0;
-  pos += 4;
+  d->sampleFrames = (hi << 32) | lo;
+
+  if(d->sampleRate > 0)
+    d->length = int(d->sampleFrames / d->sampleRate);
 
   // Uncompressed bitrate:
 
index a8a02e7cd100c0c36a82eafbb5606eef007f1551..c1458981994684db009c9a79b4475b4ca21d3ac7 100644 (file)
@@ -77,6 +77,11 @@ namespace TagLib {
        */
       int sampleWidth() const;
 
+      /*!
+       * Return the number of sample frames
+       */
+      unsigned long long sampleFrames() const;
+
       /*!
        * Returns the MD5 signature of the uncompressed audio stream as read
        * from the stream info header header.