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
20
21# Example python script for signal processing in CTS audio
22# There should be a function with the same name as the script
23# Here, function example in example.py
24
25# inputData : list of inputs with different types like int64, double,
26#             mono or stereo audio data
27# inputTypes: list of types for each input. Types are defined as TYPE_XXX
28#             consts from consts.py
29# return value: 3 elements list
30#     element 0 : execution result value as defined as RESULT_XXX in consts.py
31#     element 1 : outputData
32#     element 2 : outputTypes
33#
34# This example takes 2 stereo data, 2 mono data, 2 i64, and 2 doubles
35# and returns average as 1 stereo data, 1 mono data, 1 i64, and 1 double
36# inputTypes for this function is expected to be
37#   [ TYPE_STEREO, TYPE_STEREO, TYPE_MONO, TYPE_MONO, TYPE_I64, TYPE_I64,
38#     TYPE_DOUBLE, TYPE_DOUBLE ]
39# outputTypes will be [ TYPE_STEREO, TYPE_MONO, TYPE_I64, TYPE_DOUBLE ]
40def example(inputData, inputTypes):
41    output = []
42    outputData = []
43    outputTypes = []
44    stereoInt = (inputData[0].astype(int) + inputData[1].astype(int))/2
45    stereo = stereoInt.astype(np.int16)
46    #print len(inputData[0]), len(inputData[1]), len(stereoInt), len(stereo)
47    monoInt = (inputData[2].astype(int) + inputData[3].astype(int))/2
48    mono = monoInt.astype(np.int16)
49    #print len(inputData[2]), len(inputData[3]), len(monoInt), len(mono)
50    i64Val = (inputData[4] + inputData[5])/2
51    doubleVal = (inputData[6] + inputData[7])/2
52    outputData.append(stereo)
53    outputTypes.append(TYPE_STEREO)
54    outputData.append(mono)
55    outputTypes.append(TYPE_MONO)
56    outputData.append(i64Val)
57    outputTypes.append(TYPE_I64)
58    outputData.append(doubleVal)
59    outputTypes.append(TYPE_DOUBLE)
60    output.append(RESULT_OK)
61    output.append(outputData)
62    output.append(outputTypes)
63
64    return output
65