1#!/usr/bin/python 2 3# Copyright (C) 2012 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from consts import * 18import numpy as np 19import scipy as sp 20from calc_thd import * 21import calc_delay 22 23# calculate THD for dut_playback_thd case 24# Input: host recording (mono), 25# frequency of sine in Hz (i64) 26# THD pass level in percentile (double) 27# Output: THD device (double) in percentile 28 29def playback_thd(inputData, inputTypes): 30 output = [] 31 outputData = [] 32 outputTypes = [] 33 # basic validate 34 inputError = False 35 if (inputTypes[0] != TYPE_MONO): 36 inputError = True 37 if (inputTypes[1] != TYPE_I64): 38 inputError = True 39 if (inputTypes[2] != TYPE_DOUBLE): 40 inputError = True 41 if inputError: 42 output.append(RESULT_ERROR) 43 output.append(outputData) 44 output.append(outputTypes) 45 return output 46 47 hostRecording = inputData[0] 48 signalFrequency = inputData[1] 49 thdPassPercentile = inputData[2] 50 samplingRate = 44100 51 52 thd = calc_thd(hostRecording, signalFrequency, samplingRate, 0.02) * 100 53 print "THD %", thd, "Margain % ", thdPassPercentile 54 if (thd < thdPassPercentile): 55 output.append(RESULT_PASS) 56 else: 57 output.append(RESULT_OK) 58 outputData.append(thd) 59 outputTypes.append(TYPE_DOUBLE) 60 output.append(outputData) 61 output.append(outputTypes) 62 return output 63