]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.2/Lib/sndhdr.py
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / sndhdr.py
diff --git a/AppPkg/Applications/Python/Python-2.7.2/Lib/sndhdr.py b/AppPkg/Applications/Python/Python-2.7.2/Lib/sndhdr.py
deleted file mode 100644 (file)
index 5620f93..0000000
+++ /dev/null
@@ -1,228 +0,0 @@
-"""Routines to help recognizing sound files.\r
-\r
-Function whathdr() recognizes various types of sound file headers.\r
-It understands almost all headers that SOX can decode.\r
-\r
-The return tuple contains the following items, in this order:\r
-- file type (as SOX understands it)\r
-- sampling rate (0 if unknown or hard to decode)\r
-- number of channels (0 if unknown or hard to decode)\r
-- number of frames in the file (-1 if unknown or hard to decode)\r
-- number of bits/sample, or 'U' for U-LAW, or 'A' for A-LAW\r
-\r
-If the file doesn't have a recognizable type, it returns None.\r
-If the file can't be opened, IOError is raised.\r
-\r
-To compute the total time, divide the number of frames by the\r
-sampling rate (a frame contains a sample for each channel).\r
-\r
-Function what() calls whathdr().  (It used to also use some\r
-heuristics for raw data, but this doesn't work very well.)\r
-\r
-Finally, the function test() is a simple main program that calls\r
-what() for all files mentioned on the argument list.  For directory\r
-arguments it calls what() for all files in that directory.  Default\r
-argument is "." (testing all files in the current directory).  The\r
-option -r tells it to recurse down directories found inside\r
-explicitly given directories.\r
-"""\r
-\r
-# The file structure is top-down except that the test program and its\r
-# subroutine come last.\r
-\r
-__all__ = ["what","whathdr"]\r
-\r
-def what(filename):\r
-    """Guess the type of a sound file"""\r
-    res = whathdr(filename)\r
-    return res\r
-\r
-\r
-def whathdr(filename):\r
-    """Recognize sound headers"""\r
-    f = open(filename, 'rb')\r
-    h = f.read(512)\r
-    for tf in tests:\r
-        res = tf(h, f)\r
-        if res:\r
-            return res\r
-    return None\r
-\r
-\r
-#-----------------------------------#\r
-# Subroutines per sound header type #\r
-#-----------------------------------#\r
-\r
-tests = []\r
-\r
-def test_aifc(h, f):\r
-    import aifc\r
-    if h[:4] != 'FORM':\r
-        return None\r
-    if h[8:12] == 'AIFC':\r
-        fmt = 'aifc'\r
-    elif h[8:12] == 'AIFF':\r
-        fmt = 'aiff'\r
-    else:\r
-        return None\r
-    f.seek(0)\r
-    try:\r
-        a = aifc.openfp(f, 'r')\r
-    except (EOFError, aifc.Error):\r
-        return None\r
-    return (fmt, a.getframerate(), a.getnchannels(), \\r
-            a.getnframes(), 8*a.getsampwidth())\r
-\r
-tests.append(test_aifc)\r
-\r
-\r
-def test_au(h, f):\r
-    if h[:4] == '.snd':\r
-        f = get_long_be\r
-    elif h[:4] in ('\0ds.', 'dns.'):\r
-        f = get_long_le\r
-    else:\r
-        return None\r
-    type = 'au'\r
-    hdr_size = f(h[4:8])\r
-    data_size = f(h[8:12])\r
-    encoding = f(h[12:16])\r
-    rate = f(h[16:20])\r
-    nchannels = f(h[20:24])\r
-    sample_size = 1 # default\r
-    if encoding == 1:\r
-        sample_bits = 'U'\r
-    elif encoding == 2:\r
-        sample_bits = 8\r
-    elif encoding == 3:\r
-        sample_bits = 16\r
-        sample_size = 2\r
-    else:\r
-        sample_bits = '?'\r
-    frame_size = sample_size * nchannels\r
-    return type, rate, nchannels, data_size//frame_size, sample_bits\r
-\r
-tests.append(test_au)\r
-\r
-\r
-def test_hcom(h, f):\r
-    if h[65:69] != 'FSSD' or h[128:132] != 'HCOM':\r
-        return None\r
-    divisor = get_long_be(h[128+16:128+20])\r
-    return 'hcom', 22050//divisor, 1, -1, 8\r
-\r
-tests.append(test_hcom)\r
-\r
-\r
-def test_voc(h, f):\r
-    if h[:20] != 'Creative Voice File\032':\r
-        return None\r
-    sbseek = get_short_le(h[20:22])\r
-    rate = 0\r
-    if 0 <= sbseek < 500 and h[sbseek] == '\1':\r
-        ratecode = ord(h[sbseek+4])\r
-        rate = int(1000000.0 / (256 - ratecode))\r
-    return 'voc', rate, 1, -1, 8\r
-\r
-tests.append(test_voc)\r
-\r
-\r
-def test_wav(h, f):\r
-    # 'RIFF' <len> 'WAVE' 'fmt ' <len>\r
-    if h[:4] != 'RIFF' or h[8:12] != 'WAVE' or h[12:16] != 'fmt ':\r
-        return None\r
-    style = get_short_le(h[20:22])\r
-    nchannels = get_short_le(h[22:24])\r
-    rate = get_long_le(h[24:28])\r
-    sample_bits = get_short_le(h[34:36])\r
-    return 'wav', rate, nchannels, -1, sample_bits\r
-\r
-tests.append(test_wav)\r
-\r
-\r
-def test_8svx(h, f):\r
-    if h[:4] != 'FORM' or h[8:12] != '8SVX':\r
-        return None\r
-    # Should decode it to get #channels -- assume always 1\r
-    return '8svx', 0, 1, 0, 8\r
-\r
-tests.append(test_8svx)\r
-\r
-\r
-def test_sndt(h, f):\r
-    if h[:5] == 'SOUND':\r
-        nsamples = get_long_le(h[8:12])\r
-        rate = get_short_le(h[20:22])\r
-        return 'sndt', rate, 1, nsamples, 8\r
-\r
-tests.append(test_sndt)\r
-\r
-\r
-def test_sndr(h, f):\r
-    if h[:2] == '\0\0':\r
-        rate = get_short_le(h[2:4])\r
-        if 4000 <= rate <= 25000:\r
-            return 'sndr', rate, 1, -1, 8\r
-\r
-tests.append(test_sndr)\r
-\r
-\r
-#---------------------------------------------#\r
-# Subroutines to extract numbers from strings #\r
-#---------------------------------------------#\r
-\r
-def get_long_be(s):\r
-    return (ord(s[0])<<24) | (ord(s[1])<<16) | (ord(s[2])<<8) | ord(s[3])\r
-\r
-def get_long_le(s):\r
-    return (ord(s[3])<<24) | (ord(s[2])<<16) | (ord(s[1])<<8) | ord(s[0])\r
-\r
-def get_short_be(s):\r
-    return (ord(s[0])<<8) | ord(s[1])\r
-\r
-def get_short_le(s):\r
-    return (ord(s[1])<<8) | ord(s[0])\r
-\r
-\r
-#--------------------#\r
-# Small test program #\r
-#--------------------#\r
-\r
-def test():\r
-    import sys\r
-    recursive = 0\r
-    if sys.argv[1:] and sys.argv[1] == '-r':\r
-        del sys.argv[1:2]\r
-        recursive = 1\r
-    try:\r
-        if sys.argv[1:]:\r
-            testall(sys.argv[1:], recursive, 1)\r
-        else:\r
-            testall(['.'], recursive, 1)\r
-    except KeyboardInterrupt:\r
-        sys.stderr.write('\n[Interrupted]\n')\r
-        sys.exit(1)\r
-\r
-def testall(list, recursive, toplevel):\r
-    import sys\r
-    import os\r
-    for filename in list:\r
-        if os.path.isdir(filename):\r
-            print filename + '/:',\r
-            if recursive or toplevel:\r
-                print 'recursing down:'\r
-                import glob\r
-                names = glob.glob(os.path.join(filename, '*'))\r
-                testall(names, recursive, 0)\r
-            else:\r
-                print '*** directory (use -r) ***'\r
-        else:\r
-            print filename + ':',\r
-            sys.stdout.flush()\r
-            try:\r
-                print what(filename)\r
-            except IOError:\r
-                print '*** not found ***'\r
-\r
-if __name__ == '__main__':\r
-    test()\r