1
# $Id: mod_media_playrec.py 2884 2009-08-17 08:29:47Z bennylp $
4
# Input file is played and is recorded to output, then compare them.
5
# Useful to tes clock rates compatibility and resample quality
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
9
# wav input must be more than 3 seconds long
16
import inc_const as const
20
cfg_file = imp.load_source("cfg_file", ARGS[1])
22
# WAV similarity calculator
24
if sys.platform.find("win32")!=-1:
25
COMPARE_WAV_EXE = "tools/cmp_wav.exe"
28
COMPARE_WAV_EXE = "tools/cmp_wav"
32
# Threshold to declare degradation is too high when result is lower than this value
36
input_filename = "" # Input filename
37
output_filename = "" # Output filename
42
global output_filename
47
input_filename = re.compile(const.MEDIA_PLAY_FILE).search(endpt.inst_param.arg).group(1)
48
endpt.trace("Input file = " + input_filename)
50
# Get output file name
51
output_filename = re.compile(const.MEDIA_REC_FILE).search(endpt.inst_param.arg).group(1)
52
endpt.trace("Output file = " + output_filename)
54
# Find appropriate clock rate for the input file
55
clock_rate = re.compile(".+(\.\d+\.wav)$").match(output_filename).group(1)
56
if (clock_rate==None):
57
endpt.trace("Cannot compare input & output, incorrect output filename format")
59
input_filename = re.sub("\.\d+\.wav$", clock_rate, input_filename)
60
endpt.trace("WAV file to be compared with output = " + input_filename)
62
# Connect input-output file
66
endpt.expect(const.MEDIA_CONN_PORT_SUCCESS)
73
# Disconnect input-output file
75
endpt.expect(const.MEDIA_DISCONN_PORT_SUCCESS)
81
global output_filename
85
# Check WAV similarity
86
fullcmd = COMPARE_WAV_EXE + " " + input_filename + " " + output_filename + " " + "3000"
87
endpt.trace("Popen " + fullcmd)
88
cmp_proc = subprocess.Popen(fullcmd, shell=G_INUNIX, stdout=subprocess.PIPE, universal_newlines=True)
90
# Parse similarity ouput
91
line = cmp_proc.stdout.readline()
92
mo_sim_val = re.match(".+=\s+(\d+)", line)
93
if (mo_sim_val == None):
94
raise TestError("Error comparing WAV files")
97
# Evaluate the similarity value
98
sim_val = mo_sim_val.group(1)
99
if (sim_val >= COMPARE_THRESHOLD):
100
endpt.trace("WAV similarity = " + sim_val)
102
raise TestError("WAV degraded heavily, similarity = " + sim_val)
105
# Here where it all comes together
106
test = cfg_file.test_param
107
test.test_func = test_func
108
test.post_func = post_func