1#!/usr/bin/python
2
3# Copyright (C) 2014 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 *
18
19# Sample test for dut_playback_sample case
20# Input: host recording (mono),
21#        frequency of sine in Hz (i64)
22#        pass level threshold (double)
23# Output: device (double) frequency
24
25def playback_sample(inputData, inputTypes):
26    output = []
27    outputData = []
28    outputTypes = []
29    # basic sanity check
30    inputError = False
31    if (inputTypes[0] != TYPE_MONO):
32        inputError = True
33    if (inputTypes[1] != TYPE_I64):
34        inputError = True
35    if (inputTypes[2] != TYPE_DOUBLE):
36        inputError = True
37    if inputError:
38        output.append(RESULT_ERROR)
39        output.append(outputData)
40        output.append(outputTypes)
41        return output
42
43    hostRecording = inputData[0]
44    signalFrequency = inputData[1]
45    threshold = inputData[2]
46    samplingRate = 44100
47
48    freq = calc_freq(hostRecording, samplingRate)
49    print "Expected Freq ", signalFrequency, "Actual Freq ", freq, "Threshold % ", threshold
50    diff = abs(freq - signalFrequency)
51    if (diff < threshold):
52        output.append(RESULT_PASS)
53    else:
54        output.append(RESULT_OK)
55    outputData.append(freq)
56    outputTypes.append(TYPE_DOUBLE)
57    output.append(outputData)
58    output.append(outputTypes)
59    return output
60
61def calc_freq(recording, samplingRate):
62    #This would calculate the frequency of recording, but is skipped in this sample test for brevity
63    return 32000