Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame^] | 1 | # $Id$ |
| 2 | |
| 3 | # PLAYFILE -> RECFILE: |
| 4 | # input file is played and is recorded to output, then compare them. |
| 5 | # null-audio |
| 6 | # port 1: wav file input xxxxxx.clock_rate.wav, e.g: test1.8.wav |
| 7 | # port 2: wav file ouput xxxxxx.clock_rate.wav, e.g: res1.8.wav |
| 8 | # wav input more than 3 seconds |
| 9 | |
| 10 | import time |
| 11 | import imp |
| 12 | import sys |
| 13 | import re |
| 14 | import subprocess |
| 15 | import inc_const as const |
| 16 | |
| 17 | # Load configuration |
| 18 | cfg_file = imp.load_source("cfg_file", sys.argv[2]) |
| 19 | |
| 20 | # WAV similarity calculator |
| 21 | COMPARE_WAV_EXE = "tools/cmp_wav.exe" |
| 22 | |
| 23 | # UserData |
| 24 | class mod_media_playrec_user_data: |
| 25 | input_filename = "" |
| 26 | output_filename = "" |
| 27 | |
| 28 | # Test body function |
| 29 | def test_func(t, ud): |
| 30 | endpt = t.process[0] |
| 31 | |
| 32 | # Get input file name |
| 33 | endpt.sync_stdout() |
| 34 | endpt.send("dc") |
| 35 | line = endpt.expect(const.MEDIA_PLAY_FILE) |
| 36 | ud.input_filename = re.compile(const.MEDIA_PLAY_FILE).match(line).group(1) |
| 37 | endpt.trace("Input file = " + ud.input_filename) |
| 38 | |
| 39 | # Get output file name |
| 40 | endpt.sync_stdout() |
| 41 | endpt.send("dc") |
| 42 | line = endpt.expect(const.MEDIA_REC_FILE) |
| 43 | ud.output_filename = re.compile(const.MEDIA_REC_FILE).match(line).group(1) |
| 44 | endpt.trace("Output file = " + ud.output_filename) |
| 45 | |
| 46 | # Find appropriate clock rate for the input file |
| 47 | clock_rate = re.compile(".+(\.\d+\.wav)$").match(ud.output_filename).group(1) |
| 48 | if (clock_rate==None): |
| 49 | endpt.trace("Cannot compare input & output, incorrect output filename format") |
| 50 | return |
| 51 | ud.input_filename = re.sub("\.\d+\.wav$", clock_rate, ud.input_filename) |
| 52 | endpt.trace("WAV file to be compared with output = " + ud.input_filename) |
| 53 | |
| 54 | # Connect input-output file |
| 55 | endpt.sync_stdout() |
| 56 | |
| 57 | endpt.send("cc 1 2") |
| 58 | endpt.expect(const.MEDIA_CONN_PORT_SUCCESS) |
| 59 | |
| 60 | # Wait |
| 61 | time.sleep(3) |
| 62 | |
| 63 | endpt.sync_stdout() |
| 64 | |
| 65 | # Disconnect input-output file |
| 66 | endpt.send("cd 1 2") |
| 67 | endpt.expect(const.MEDIA_DISCONN_PORT_SUCCESS) |
| 68 | |
| 69 | |
| 70 | # Post body function |
| 71 | def post_func(t, ud): |
| 72 | endpt = t.process[0] |
| 73 | |
| 74 | # Check WAV similarity |
| 75 | fullcmd = COMPARE_WAV_EXE + " " + ud.input_filename + " " + ud.output_filename + " " + "3000" |
| 76 | endpt.trace("Popen " + fullcmd) |
| 77 | cmp_proc = subprocess.Popen(fullcmd, stdout=subprocess.PIPE, universal_newlines=True) |
| 78 | line = cmp_proc.stdout.readline() |
| 79 | endpt.trace("WAV similarity = " + line) |
| 80 | |
| 81 | |
| 82 | # Here where it all comes together |
| 83 | test = cfg_file.test_param |
| 84 | test.test_func = test_func |
| 85 | test.post_func = post_func |
| 86 | test.user_data = mod_media_playrec_user_data() |