Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 1 | # $Id$ |
| 2 | |
| 3 | # PLAYFILE -> RECFILE: |
Nanang Izzuddin | e6f85fb | 2008-06-20 17:43:55 +0000 | [diff] [blame] | 4 | # Input file is played and is recorded to output, then compare them. |
| 5 | # Useful to tes clock rates compatibility and resample quality |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 6 | # null-audio |
| 7 | # port 1: wav file input xxxxxx.clock_rate.wav, e.g: test1.8.wav |
| 8 | # port 2: wav file ouput xxxxxx.clock_rate.wav, e.g: res1.8.wav |
Nanang Izzuddin | e6f85fb | 2008-06-20 17:43:55 +0000 | [diff] [blame] | 9 | # wav input must be more than 3 seconds long |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 10 | |
| 11 | import time |
| 12 | import imp |
| 13 | import sys |
| 14 | import re |
| 15 | import subprocess |
| 16 | import inc_const as const |
Nanang Izzuddin | a680bd6 | 2008-06-27 21:12:12 +0000 | [diff] [blame] | 17 | from inc_cfg import * |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 18 | |
| 19 | # Load configuration |
Nanang Izzuddin | a680bd6 | 2008-06-27 21:12:12 +0000 | [diff] [blame] | 20 | cfg_file = imp.load_source("cfg_file", ARGS[1]) |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 21 | |
| 22 | # WAV similarity calculator |
| 23 | COMPARE_WAV_EXE = "tools/cmp_wav.exe" |
| 24 | |
Nanang Izzuddin | b40e287 | 2008-06-25 15:05:21 +0000 | [diff] [blame] | 25 | # Threshold to declare degradation is too high when result is lower than this value |
| 26 | COMPARE_THRESHOLD = 2 |
| 27 | |
Nanang Izzuddin | a680bd6 | 2008-06-27 21:12:12 +0000 | [diff] [blame] | 28 | # COMPARE params |
| 29 | input_filename = "" # Input filename |
| 30 | output_filename = "" # Output filename |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 31 | |
| 32 | # Test body function |
Nanang Izzuddin | e19e0e0 | 2008-06-27 22:47:33 +0000 | [diff] [blame] | 33 | def test_func(t): |
Nanang Izzuddin | a680bd6 | 2008-06-27 21:12:12 +0000 | [diff] [blame] | 34 | global input_filename |
| 35 | global output_filename |
| 36 | |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 37 | endpt = t.process[0] |
| 38 | |
| 39 | # Get input file name |
Nanang Izzuddin | e19e0e0 | 2008-06-27 22:47:33 +0000 | [diff] [blame] | 40 | input_filename = re.compile(const.MEDIA_PLAY_FILE).search(endpt.inst_param.arg).group(1) |
| 41 | endpt.trace("Input file = " + input_filename) |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 42 | |
| 43 | # Get output file name |
Nanang Izzuddin | e19e0e0 | 2008-06-27 22:47:33 +0000 | [diff] [blame] | 44 | output_filename = re.compile(const.MEDIA_REC_FILE).search(endpt.inst_param.arg).group(1) |
| 45 | endpt.trace("Output file = " + output_filename) |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 46 | |
| 47 | # Find appropriate clock rate for the input file |
Nanang Izzuddin | e19e0e0 | 2008-06-27 22:47:33 +0000 | [diff] [blame] | 48 | clock_rate = re.compile(".+(\.\d+\.wav)$").match(output_filename).group(1) |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 49 | if (clock_rate==None): |
| 50 | endpt.trace("Cannot compare input & output, incorrect output filename format") |
| 51 | return |
Nanang Izzuddin | e19e0e0 | 2008-06-27 22:47:33 +0000 | [diff] [blame] | 52 | input_filename = re.sub("\.\d+\.wav$", clock_rate, input_filename) |
| 53 | endpt.trace("WAV file to be compared with output = " + input_filename) |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 54 | |
| 55 | # Connect input-output file |
| 56 | endpt.sync_stdout() |
| 57 | |
| 58 | endpt.send("cc 1 2") |
| 59 | endpt.expect(const.MEDIA_CONN_PORT_SUCCESS) |
| 60 | |
| 61 | # Wait |
| 62 | time.sleep(3) |
| 63 | |
| 64 | endpt.sync_stdout() |
| 65 | |
| 66 | # Disconnect input-output file |
| 67 | endpt.send("cd 1 2") |
| 68 | endpt.expect(const.MEDIA_DISCONN_PORT_SUCCESS) |
| 69 | |
| 70 | |
| 71 | # Post body function |
Nanang Izzuddin | e19e0e0 | 2008-06-27 22:47:33 +0000 | [diff] [blame] | 72 | def post_func(t): |
Nanang Izzuddin | a680bd6 | 2008-06-27 21:12:12 +0000 | [diff] [blame] | 73 | global input_filename |
| 74 | global output_filename |
| 75 | |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 76 | endpt = t.process[0] |
| 77 | |
| 78 | # Check WAV similarity |
Nanang Izzuddin | e19e0e0 | 2008-06-27 22:47:33 +0000 | [diff] [blame] | 79 | fullcmd = COMPARE_WAV_EXE + " " + input_filename + " " + output_filename + " " + "3000" |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 80 | endpt.trace("Popen " + fullcmd) |
| 81 | cmp_proc = subprocess.Popen(fullcmd, stdout=subprocess.PIPE, universal_newlines=True) |
Nanang Izzuddin | e6f85fb | 2008-06-20 17:43:55 +0000 | [diff] [blame] | 82 | |
| 83 | # Parse similarity ouput |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 84 | line = cmp_proc.stdout.readline() |
Nanang Izzuddin | e6f85fb | 2008-06-20 17:43:55 +0000 | [diff] [blame] | 85 | mo_sim_val = re.match(".+=\s+(\d+)", line) |
| 86 | if (mo_sim_val == None): |
| 87 | raise TestError("Error comparing WAV files") |
| 88 | return |
| 89 | |
| 90 | # Evaluate the similarity value |
| 91 | sim_val = mo_sim_val.group(1) |
Nanang Izzuddin | b40e287 | 2008-06-25 15:05:21 +0000 | [diff] [blame] | 92 | if (sim_val >= COMPARE_THRESHOLD): |
Nanang Izzuddin | e6f85fb | 2008-06-20 17:43:55 +0000 | [diff] [blame] | 93 | endpt.trace("WAV similarity = " + sim_val) |
| 94 | else: |
Nanang Izzuddin | b40e287 | 2008-06-25 15:05:21 +0000 | [diff] [blame] | 95 | raise TestError("WAV degraded heavily, similarity = " + sim_val) |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 96 | |
| 97 | |
| 98 | # Here where it all comes together |
| 99 | test = cfg_file.test_param |
| 100 | test.test_func = test_func |
| 101 | test.post_func = post_func |