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 |
| 17 | |
| 18 | # Load configuration |
| 19 | cfg_file = imp.load_source("cfg_file", sys.argv[2]) |
| 20 | |
| 21 | # WAV similarity calculator |
| 22 | COMPARE_WAV_EXE = "tools/cmp_wav.exe" |
| 23 | |
Nanang Izzuddin | b40e287 | 2008-06-25 15:05:21 +0000 | [diff] [blame] | 24 | # Threshold to declare degradation is too high when result is lower than this value |
| 25 | COMPARE_THRESHOLD = 2 |
| 26 | |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 27 | # UserData |
| 28 | class mod_media_playrec_user_data: |
| 29 | input_filename = "" |
| 30 | output_filename = "" |
| 31 | |
| 32 | # Test body function |
| 33 | def test_func(t, ud): |
| 34 | endpt = t.process[0] |
| 35 | |
| 36 | # Get input file name |
Nanang Izzuddin | acb3e32 | 2008-06-25 18:18:32 +0000 | [diff] [blame] | 37 | ud.input_filename = re.compile(const.MEDIA_PLAY_FILE).search(endpt.inst_param.arg).group(1) |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 38 | endpt.trace("Input file = " + ud.input_filename) |
| 39 | |
| 40 | # Get output file name |
Nanang Izzuddin | acb3e32 | 2008-06-25 18:18:32 +0000 | [diff] [blame] | 41 | ud.output_filename = re.compile(const.MEDIA_REC_FILE).search(endpt.inst_param.arg).group(1) |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 42 | endpt.trace("Output file = " + ud.output_filename) |
| 43 | |
| 44 | # Find appropriate clock rate for the input file |
| 45 | clock_rate = re.compile(".+(\.\d+\.wav)$").match(ud.output_filename).group(1) |
| 46 | if (clock_rate==None): |
| 47 | endpt.trace("Cannot compare input & output, incorrect output filename format") |
| 48 | return |
| 49 | ud.input_filename = re.sub("\.\d+\.wav$", clock_rate, ud.input_filename) |
| 50 | endpt.trace("WAV file to be compared with output = " + ud.input_filename) |
| 51 | |
| 52 | # Connect input-output file |
| 53 | endpt.sync_stdout() |
| 54 | |
| 55 | endpt.send("cc 1 2") |
| 56 | endpt.expect(const.MEDIA_CONN_PORT_SUCCESS) |
| 57 | |
| 58 | # Wait |
| 59 | time.sleep(3) |
| 60 | |
| 61 | endpt.sync_stdout() |
| 62 | |
| 63 | # Disconnect input-output file |
| 64 | endpt.send("cd 1 2") |
| 65 | endpt.expect(const.MEDIA_DISCONN_PORT_SUCCESS) |
| 66 | |
| 67 | |
| 68 | # Post body function |
| 69 | def post_func(t, ud): |
| 70 | endpt = t.process[0] |
| 71 | |
| 72 | # Check WAV similarity |
| 73 | fullcmd = COMPARE_WAV_EXE + " " + ud.input_filename + " " + ud.output_filename + " " + "3000" |
| 74 | endpt.trace("Popen " + fullcmd) |
| 75 | cmp_proc = subprocess.Popen(fullcmd, stdout=subprocess.PIPE, universal_newlines=True) |
Nanang Izzuddin | e6f85fb | 2008-06-20 17:43:55 +0000 | [diff] [blame] | 76 | |
| 77 | # Parse similarity ouput |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 78 | line = cmp_proc.stdout.readline() |
Nanang Izzuddin | e6f85fb | 2008-06-20 17:43:55 +0000 | [diff] [blame] | 79 | mo_sim_val = re.match(".+=\s+(\d+)", line) |
| 80 | if (mo_sim_val == None): |
| 81 | raise TestError("Error comparing WAV files") |
| 82 | return |
| 83 | |
| 84 | # Evaluate the similarity value |
| 85 | sim_val = mo_sim_val.group(1) |
Nanang Izzuddin | b40e287 | 2008-06-25 15:05:21 +0000 | [diff] [blame] | 86 | if (sim_val >= COMPARE_THRESHOLD): |
Nanang Izzuddin | e6f85fb | 2008-06-20 17:43:55 +0000 | [diff] [blame] | 87 | endpt.trace("WAV similarity = " + sim_val) |
| 88 | else: |
Nanang Izzuddin | b40e287 | 2008-06-25 15:05:21 +0000 | [diff] [blame] | 89 | raise TestError("WAV degraded heavily, similarity = " + sim_val) |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 90 | |
| 91 | |
| 92 | # Here where it all comes together |
| 93 | test = cfg_file.test_param |
| 94 | test.test_func = test_func |
| 95 | test.post_func = post_func |
| 96 | test.user_data = mod_media_playrec_user_data() |