[xiph-cvs] cvs commit: positron/positron MP3Info.py

Stan Seibert volsung at xiph.org
Wed Jul 2 21:42:05 PDT 2003



volsung     03/07/03 00:42:05

  Modified:    positron MP3Info.py
  Log:
  Fix to deal with a different frame size calculation that only affects
  MPEG 2/2.5 Layer III files.  Enormous thanks to Brendan for fishing this
  one out of the LAME source code.

Revision  Changes    Path
1.12      +15 -5     positron/positron/MP3Info.py

Index: MP3Info.py
===================================================================
RCS file: /usr/local/cvsroot/positron/positron/MP3Info.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- MP3Info.py	3 Jul 2003 02:14:08 -0000	1.11
+++ MP3Info.py	3 Jul 2003 04:42:05 -0000	1.12
@@ -372,14 +372,13 @@
                     next_off, next_header = \
                               self._find_header(file, seeklimit=0,
                                         seekstart=seekstart+offset
-                                                  +int(self.framelength),
+                                                  +self.framelength,
                                         check_next_header=check_next_header-1)
 
                     # Move the file pointer back
                     file.seek(file_pos,0)
                     
                     if next_off != -1:
-#                        print file.name, seekstart, seeklimit, offset, self.framelength
                         return seekstart+offset, header[offset:offset+4]
                     else:
                         curr_pos = offset+2
@@ -450,11 +449,22 @@
 
         try:
             if self.layer == 1:
-                self.framelength = ((  12 * (self.bitrate * 1000.0)/self.samplerate) + padding_bit) * 4
+                self.framelength = (12000 * self.bitrate // self.samplerate + padding_bit) * 4
                 self.samplesperframe = 384.0
-            else:
-                self.framelength =  ( 144 * (self.bitrate * 1000.0)/self.samplerate) + padding_bit
+            elif self.layer == 2:
+                self.framelength =  144000 * self.bitrate // self.samplerate + padding_bit
                 self.samplesperframe = 1152.0
+            else:
+                # MPEG 2 and 2.5 calculate framelength different
+                # (discovered in LAME source)
+                if mpeg_version == 0 or mpeg_version == 2:
+                    fake_samplerate = self.samplerate << 1
+                else:
+                    fake_samplerate = self.samplerate
+                    
+                self.framelength = 144000 * self.bitrate // fake_samplerate + padding_bit
+                self.samplesperframe = 1152.0 # This might be wrong
+                
             self.length = int(round((self.filesize / self.framelength) * (self.samplesperframe / self.samplerate)))
         except ZeroDivisionError:
             return  # Division by zero means the header is bad

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list