blob: ef6ed7922f22e0346b5e1e9020386f4b1424553c [file] [log] [blame]
Nanang Izzuddinf810f952008-06-18 21:04:14 +00001# $Id$
2
3# PLAYFILE -> RECFILE:
Nanang Izzuddine6f85fb2008-06-20 17:43:55 +00004# Input file is played and is recorded to output, then compare them.
5# Useful to tes clock rates compatibility and resample quality
Nanang Izzuddinf810f952008-06-18 21:04:14 +00006# 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 Izzuddine6f85fb2008-06-20 17:43:55 +00009# wav input must be more than 3 seconds long
Nanang Izzuddinf810f952008-06-18 21:04:14 +000010
11import time
12import imp
13import sys
14import re
15import subprocess
16import inc_const as const
Nanang Izzuddina680bd62008-06-27 21:12:12 +000017from inc_cfg import *
Nanang Izzuddinf810f952008-06-18 21:04:14 +000018
19# Load configuration
Nanang Izzuddina680bd62008-06-27 21:12:12 +000020cfg_file = imp.load_source("cfg_file", ARGS[1])
Nanang Izzuddinf810f952008-06-18 21:04:14 +000021
22# WAV similarity calculator
23COMPARE_WAV_EXE = "tools/cmp_wav.exe"
24
Nanang Izzuddinb40e2872008-06-25 15:05:21 +000025# Threshold to declare degradation is too high when result is lower than this value
26COMPARE_THRESHOLD = 2
27
Nanang Izzuddina680bd62008-06-27 21:12:12 +000028# COMPARE params
29input_filename = "" # Input filename
30output_filename = "" # Output filename
Nanang Izzuddinf810f952008-06-18 21:04:14 +000031
32# Test body function
Nanang Izzuddine19e0e02008-06-27 22:47:33 +000033def test_func(t):
Nanang Izzuddina680bd62008-06-27 21:12:12 +000034 global input_filename
35 global output_filename
36
Nanang Izzuddinf810f952008-06-18 21:04:14 +000037 endpt = t.process[0]
38
39 # Get input file name
Nanang Izzuddine19e0e02008-06-27 22:47:33 +000040 input_filename = re.compile(const.MEDIA_PLAY_FILE).search(endpt.inst_param.arg).group(1)
41 endpt.trace("Input file = " + input_filename)
Nanang Izzuddinf810f952008-06-18 21:04:14 +000042
43 # Get output file name
Nanang Izzuddine19e0e02008-06-27 22:47:33 +000044 output_filename = re.compile(const.MEDIA_REC_FILE).search(endpt.inst_param.arg).group(1)
45 endpt.trace("Output file = " + output_filename)
Nanang Izzuddinf810f952008-06-18 21:04:14 +000046
47 # Find appropriate clock rate for the input file
Nanang Izzuddine19e0e02008-06-27 22:47:33 +000048 clock_rate = re.compile(".+(\.\d+\.wav)$").match(output_filename).group(1)
Nanang Izzuddinf810f952008-06-18 21:04:14 +000049 if (clock_rate==None):
50 endpt.trace("Cannot compare input & output, incorrect output filename format")
51 return
Nanang Izzuddine19e0e02008-06-27 22:47:33 +000052 input_filename = re.sub("\.\d+\.wav$", clock_rate, input_filename)
53 endpt.trace("WAV file to be compared with output = " + input_filename)
Nanang Izzuddinf810f952008-06-18 21:04:14 +000054
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 Izzuddine19e0e02008-06-27 22:47:33 +000072def post_func(t):
Nanang Izzuddina680bd62008-06-27 21:12:12 +000073 global input_filename
74 global output_filename
75
Nanang Izzuddinf810f952008-06-18 21:04:14 +000076 endpt = t.process[0]
77
78 # Check WAV similarity
Nanang Izzuddine19e0e02008-06-27 22:47:33 +000079 fullcmd = COMPARE_WAV_EXE + " " + input_filename + " " + output_filename + " " + "3000"
Nanang Izzuddinf810f952008-06-18 21:04:14 +000080 endpt.trace("Popen " + fullcmd)
81 cmp_proc = subprocess.Popen(fullcmd, stdout=subprocess.PIPE, universal_newlines=True)
Nanang Izzuddine6f85fb2008-06-20 17:43:55 +000082
83 # Parse similarity ouput
Nanang Izzuddinf810f952008-06-18 21:04:14 +000084 line = cmp_proc.stdout.readline()
Nanang Izzuddine6f85fb2008-06-20 17:43:55 +000085 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 Izzuddinb40e2872008-06-25 15:05:21 +000092 if (sim_val >= COMPARE_THRESHOLD):
Nanang Izzuddine6f85fb2008-06-20 17:43:55 +000093 endpt.trace("WAV similarity = " + sim_val)
94 else:
Nanang Izzuddinb40e2872008-06-25 15:05:21 +000095 raise TestError("WAV degraded heavily, similarity = " + sim_val)
Nanang Izzuddinf810f952008-06-18 21:04:14 +000096
97
98# Here where it all comes together
99test = cfg_file.test_param
100test.test_func = test_func
101test.post_func = post_func