Anonymous avatar Anonymous committed 2051c79

* Metadata WAVE: don't use separate group for sound information
* Add ladouce_1h15.wav to testcase (WAVE with 6 channels, uncompressed, 32-bit float)

Comments (0)

Files changed (3)

hachoir-metadata/hachoir_metadata/riff.py

 from hachoir_core.error import warning
 from hachoir_core.i18n import _
 
-class WavMetadata(Metadata):
-    def extract(self, wav):
-        format = wav["format"]
-
-        # Number of channel, bits/sample, sample rate
-        self.nb_channel = format["nb_channel"].value
-        self.bits_per_sample = format["bit_per_sample"].value
-        self.sample_rate = format["sample_per_sec"].value
-
-        self.compression = format["codec"].display
-        if "nb_sample/nb_sample" in wav:
-            self.duration = float(wav["nb_sample/nb_sample"].value) * 1000 / self.sample_rate[0]
-        if format["codec"].value in (AUDIO_MICROSOFT_PCM, AUDIO_IEEE_FLOAT32):
-            # Codec with fixed bit rate
-            self.bit_rate = self.nb_channel[0] * self.bits_per_sample[0] * self.sample_rate[0]
-            if not hasattr(self, "duration"):
-                self.duration = float(wav["audio_data/size"].value * 8) * 1000 / self.bit_rate[0]
-
 class RiffMetadata(MultipleMetadata):
     tag_to_key = {
         "INAM": "title",
         key = self.tag_to_key[tag]
         setattr(self, key, value)
 
+    def extractWAVE(self, wav):
+        format = wav["format"]
+
+        # Number of channel, bits/sample, sample rate
+        self.nb_channel = format["nb_channel"].value
+        self.bits_per_sample = format["bit_per_sample"].value
+        self.sample_rate = format["sample_per_sec"].value
+
+        self.compression = format["codec"].display
+        if "nb_sample/nb_sample" in wav:
+            self.duration = wav["nb_sample/nb_sample"].value * 1000 // self.sample_rate[0]
+        if format["codec"].value in (AUDIO_MICROSOFT_PCM, AUDIO_IEEE_FLOAT32):
+            # Codec with fixed bit rate
+            self.bit_rate = self.nb_channel[0] * self.bits_per_sample[0] * self.sample_rate[0]
+            if not hasattr(self, "duration"):
+                self.duration = wav["audio_data/size"].value * 8 * 1000 // self.bit_rate[0]
+
     def extract(self, riff):
         type = riff["type"].value
         if type == "WAVE":
-            wav = WavMetadata()
-            wav.extract(riff)
-            self.addGroup("audio", wav, "Audio (WAV)")
+            self.extractWAVE(riff)
         elif type == "AVI ":
             self.extractAVI(riff)
         if "info" in riff:

hachoir-metadata/run_testcase.py

 def checkClickMeta(metadata): return (
     checkAttr(metadata, "producer", "Sound Forge 4.5"),
     checkAttr(metadata, "creation_date", "2001-02-21"),
-    checkAttr(metadata, "audio/duration", float(1724*8*1000) / 705600),
-    checkAttr(metadata, "audio/bit_rate", 705600),
-    checkAttr(metadata, "audio/sample_rate", 22050))
+    checkAttr(metadata, "duration", 19),
+    checkAttr(metadata, "bit_rate", 705600),
+    checkAttr(metadata, "sample_rate", 22050))
 
 def checkGzipMeta(metadata): return (
     checkAttr(metadata, "file_size", 99),
     checkAttr(meta, "compression", u"Little-endian, no compression"),
 )
 
+def checkLadouce(meta): return (
+    checkAttr(meta, "duration", 4592516),
+    checkAttr(meta, "nb_channel", 6),
+    checkAttr(meta, "sample_rate", 44100),
+    checkAttr(meta, "bits_per_sample", 32),
+    checkAttr(meta, "compression", "IEEE Float"),
+    checkAttr(meta, "bit_rate", 8467200),
+)
+
 testcase_files = (
     (u"logo-Kubuntu.png", checkLogoUbuntuMeta),
     (u"KDE_Click.wav", checkClickMeta),
     (u"hero.tga", checkHero),
     (u"firstrun.rm", checkFirstrun),
     (u"25min.aifc", check25min),
+    (u"ladouce_1h15.wav", checkLadouce),
 )
 
 def checkFile(filename, check_metadata):

hachoir-parser/tests/download_testcase.py

     (u"grasslogo_vector.emf", 6932, "6fe03cdf34ac3ee6e797c7aeb8c92e41"),
     (u"ocr10.laf", 17264, "4f0a15d2abe84c5e4bd1eca11195dc87"),
     (u"kino14s.laf", 30957, "9fbb52a92ff9db88b85a57cf4359acd8"),
+    (u"ladouce_1h15.wav", 5112, "964250e59d1967ab86d60e635a298bbe"),
 )
 
 def stringMD5(text):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.