Back to index

eyed3  0.6.18
Classes | Functions | Variables
mp3 Namespace Reference

Classes

class  Mp3Exception
class  Header
class  XingHeader
class  LameTag

Functions

def is_valid_mp_header
 Pass in a 4 byte integer to determine if it matches a valid mp3 frame header.
def find_header
def computeTimePerFrame
def lamevercmp

Variables

tuple SAMPLE_FREQ_TABLE
tuple BIT_RATE_TABLE
tuple TIME_PER_FRAME_TABLE = (None, 384, 1152, 1152)
string EMPHASIS_NONE = "None"
string EMPHASIS_5015 = "50/15 ms"
string EMPHASIS_CCIT = "CCIT J.17"
string MODE_STEREO = "Stereo"
string MODE_JOINT_STEREO = "Joint stereo"
string MODE_DUAL_CHANNEL_STEREO = "Dual channel stereo"
string MODE_MONO = "Mono"
int FRAMES_FLAG = 0x0001
int BYTES_FLAG = 0x0002
int TOC_FLAG = 0x0004
int VBR_SCALE_FLAG = 0x0008

Class Documentation

class mp3::Mp3Exception
Error reading mp3

Definition at line 24 of file mp3.py.


Function Documentation

def mp3.computeTimePerFrame (   frameHeader)

Definition at line 133 of file mp3.py.

00133 
00134 def computeTimePerFrame(frameHeader):
00135    return (float(TIME_PER_FRAME_TABLE[frameHeader.layer]) /
00136            float(frameHeader.sampleFreq))

def mp3.find_header (   fp,
  start_pos = 0 
)

Definition at line 108 of file mp3.py.

00108 
00109 def find_header(fp, start_pos=0):
00110     def find_sync(fp, start_pos=0):
00111         CHUNK_SIZE = 65536
00112 
00113         fp.seek(start_pos)
00114         data = fp.read(CHUNK_SIZE)
00115         data_len = len(data)
00116 
00117         while data:
00118             sync_pos = data.find('\xff', 0)
00119             if sync_pos >= 0:
00120                 header = data[sync_pos:sync_pos + 4]
00121                 if len(header) == 4:
00122                     return (start_pos + sync_pos, header)
00123             data = fp.read(CHUNK_SIZE)
00124             data_len = len(data)
00125         return (None, None)
00126     sync_pos, header_bytes = find_sync(fp, start_pos)
00127     while sync_pos is not None:
00128         header = bytes2dec(header_bytes)
00129         if is_valid_mp_header(header):
00130             return (sync_pos, header, header_bytes)
00131         sync_pos, header_bytes = find_sync(fp, start_pos + sync_pos + 2)
00132     return (None, None, None)

Here is the call graph for this function:

def mp3.is_valid_mp_header (   header)

Pass in a 4 byte integer to determine if it matches a valid mp3 frame header.

Definition at line 75 of file mp3.py.

00075 
00076 def is_valid_mp_header(header):
00077     # Test for the mp3 frame sync: 11 set bits.
00078     sync = (header >> 16)
00079     if sync & 0xFFE0 != 0xFFE0:
00080         # ffe0 is 11 sync bits, and supports identifying mpeg v2.5
00081         return False
00082 
00083     version = (header >> 19) & 0x3
00084     if version == 1:
00085         # This is a "reserved" version
00086         TRACE_MSG("invalid mpeg version")
00087         return False
00088 
00089     layer = (header >> 17) & 0x3
00090     if layer == 0:
00091         # This is a "reserved" layer
00092         TRACE_MSG("invalid mpeg layer")
00093         return False
00094 
00095     bitrate = (header >> 12) & 0xf
00096     if bitrate in (0, 0xf):
00097         # free and bad bitrate values
00098         TRACE_MSG("invalid mpeg bitrate")
00099         return False
00100 
00101     sample_rate = (header >> 10) & 0x3
00102     if sample_rate == 0x3:
00103         # this is a "reserved" sample rate
00104         TRACE_MSG("invalid mpeg sample rate")
00105         return False
00106 
00107     return True

Here is the call graph for this function:

Here is the caller graph for this function:

def mp3.lamevercmp (   x,
  y 
)
Compare LAME version strings.

alpha and beta versions are considered older.
versions with sub minor parts or end with 'r' are considered newer.

Return negative if x<y, zero if x==y, positive if x>y.

Definition at line 729 of file mp3.py.

00729 
00730 def lamevercmp(x, y):
00731    """Compare LAME version strings.
00732 
00733    alpha and beta versions are considered older.
00734    versions with sub minor parts or end with 'r' are considered newer.
00735 
00736    Return negative if x<y, zero if x==y, positive if x>y.
00737    """
00738 
00739    x = x.ljust(5)
00740    y = y.ljust(5)
00741    if x[:5] == y[:5]: return 0
00742    ret = cmp(x[:4], y[:4])
00743    if ret: return ret
00744    xmaj, xmin = x.split('.')[:2]
00745    ymaj, ymin = y.split('.')[:2]
00746    minparts = ['.']
00747    # lame 3.96.1 added the use of r in the very short version for post releases
00748    if (xmaj == '3' and xmin >= '96') or (ymaj == '3' and ymin >= '96'):
00749       minparts.append('r')
00750    if x[4] in minparts: return 1
00751    if y[4] in minparts: return -1
00752    if x[4] == ' ': return 1
00753    if y[4] == ' ': return -1
00754    return cmp(x[4], y[4])

Variable Documentation

Initial value:
00001 ((0,    0,    0,    0,    0),
00002                   (32,   32,   32,   32,   8),
00003                   (64,   48,   40,   48,   16),
00004                   (96,   56,   48,   56,   24),
00005                   (128,  64,   56,   64,   32),
00006                   (160,  80,   64,   80,   40),
00007                   (192,  96,   80,   96,   44),
00008                   (224,  112,  96,   112,  56),
00009                   (256,  128,  112,  128,  64),
00010                   (288,  160,  128,  144,  80),
00011                   (320,  192,  160,  160,  96),
00012                   (352,  224,  192,  176,  112),
00013                   (384,  256,  224,  192,  128),
00014                   (416,  320,  256,  224,  144),
00015                   (448,  384,  320,  256,  160),
00016                   (None, None, None, None, None))

Definition at line 35 of file mp3.py.

int mp3.BYTES_FLAG = 0x0002

Definition at line 68 of file mp3.py.

string mp3.EMPHASIS_5015 = "50/15 ms"

Definition at line 57 of file mp3.py.

string mp3.EMPHASIS_CCIT = "CCIT J.17"

Definition at line 58 of file mp3.py.

string mp3.EMPHASIS_NONE = "None"

Definition at line 56 of file mp3.py.

int mp3.FRAMES_FLAG = 0x0001

Definition at line 67 of file mp3.py.

string mp3.MODE_DUAL_CHANNEL_STEREO = "Dual channel stereo"

Definition at line 63 of file mp3.py.

string mp3.MODE_JOINT_STEREO = "Joint stereo"

Definition at line 62 of file mp3.py.

string mp3.MODE_MONO = "Mono"

Definition at line 64 of file mp3.py.

string mp3.MODE_STEREO = "Stereo"

Definition at line 61 of file mp3.py.

Initial value:
00001 ((44100, 22050, 11025),
00002                      (48000, 24000, 12000),
00003                      (32000, 16000, 8000),
00004                      (None,  None,  None))

Definition at line 29 of file mp3.py.

tuple mp3.TIME_PER_FRAME_TABLE = (None, 384, 1152, 1152)

Definition at line 53 of file mp3.py.

int mp3.TOC_FLAG = 0x0004

Definition at line 69 of file mp3.py.

int mp3.VBR_SCALE_FLAG = 0x0008

Definition at line 70 of file mp3.py.