1#!/bin/bash
2#
3# This script uses test-mixer to generate WAV files
4# for evaluation of the AudioMixer component.
5#
6# Sine and chirp signals are used for input because they
7# show up as clear lines, either horizontal or diagonal,
8# on a spectrogram. This means easy verification of multiple
9# track mixing.
10#
11# After execution, look for created subdirectories like
12# mixer_i_i
13# mixer_i_f
14# mixer_f_f
15#
16# Recommend using a program such as audacity to evaluate
17# the output WAV files, e.g.
18#
19# cd testdir
20# audacity *.wav
21#
22# Using Audacity:
23#
24# Under "Waveform" view mode you can zoom into the
25# start of the WAV file to verify proper ramping.
26#
27# Select "Spectrogram" to see verify the lines
28# (sine = horizontal, chirp = diagonal) which should
29# be clear (except for around the start as the volume
30# ramping causes spectral distortion).
31
32if [ -z "$ANDROID_BUILD_TOP" ]; then
33    echo "Android build environment not set"
34    exit -1
35fi
36
37# ensure we have mm
38. $ANDROID_BUILD_TOP/build/envsetup.sh
39
40pushd $ANDROID_BUILD_TOP/frameworks/av/media/libaudioprocessing
41
42# build
43pwd
44mm
45
46# send to device
47echo "waiting for device"
48adb root && adb wait-for-device remount
49adb push $OUT/system/lib/libaudioprocessing.so /system/lib
50adb push $OUT/system/lib64/libaudioprocessing.so /system/lib64
51adb push $OUT/system/bin/test-mixer /system/bin
52
53# createwav creates a series of WAV files testing various
54# mixer settings
55# $1 = flags
56# $2 = directory
57function createwav() {
58# create directory if it doesn't exist
59    if [ ! -d $2 ]; then
60        mkdir $2
61    fi
62
63# Test:
64# process__genericResampling with mixed integer and float track input
65# track__Resample / track__genericResample
66    adb shell test-mixer $1 -s 48000 \
67        -o /sdcard/tm48000grif.wav \
68        sine:2,4000,7520 chirp:2,9200 sine:1,3000,18000 \
69        sine:f,6,6000,19000  chirp:i,4,30000
70    adb pull /sdcard/tm48000grif.wav $2
71
72# Test:
73# process__genericResampling
74# track__Resample / track__genericResample
75    adb shell test-mixer $1 -s 48000 \
76        -o /sdcard/tm48000gr.wav \
77        sine:2,4000,7520 chirp:2,9200 sine:1,3000,18000 \
78        sine:6,6000,19000
79    adb pull /sdcard/tm48000gr.wav $2
80
81# Test:
82# process__genericResample
83# track__Resample / track__genericResample
84# track__NoResample / track__16BitsStereo / track__16BitsMono
85# Aux buffer
86    adb shell test-mixer $1 -c 5 -s 9307 \
87        -a /sdcard/aux9307gra.wav -o /sdcard/tm9307gra.wav \
88        sine:4,1000,3000 sine:1,2000,9307 chirp:3,9307
89    adb pull /sdcard/tm9307gra.wav $2
90    adb pull /sdcard/aux9307gra.wav $2
91
92# Test:
93# process__genericNoResampling
94# track__NoResample / track__16BitsStereo / track__16BitsMono
95    adb shell test-mixer $1 -s 32000 \
96        -o /sdcard/tm32000gnr.wav \
97        sine:2,1000,32000 chirp:2,32000  sine:1,3000,32000
98    adb pull /sdcard/tm32000gnr.wav $2
99
100# Test:
101# process__genericNoResampling
102# track__NoResample / track__16BitsStereo / track__16BitsMono
103# Aux buffer
104    adb shell test-mixer $1 -s 32000 \
105        -a /sdcard/aux32000gnra.wav -o /sdcard/tm32000gnra.wav \
106        sine:2,1000,32000 chirp:2,32000  sine:1,3000,32000
107    adb pull /sdcard/tm32000gnra.wav $2
108    adb pull /sdcard/aux32000gnra.wav $2
109
110# Test:
111# process__NoResampleOneTrack / process__OneTrack16BitsStereoNoResampling
112# Downmixer
113    adb shell test-mixer $1 -s 32000 \
114        -o /sdcard/tm32000nrot.wav \
115        sine:6,1000,32000
116    adb pull /sdcard/tm32000nrot.wav $2
117
118# Test:
119# process__NoResampleOneTrack / OneTrack16BitsStereoNoResampling
120# Aux buffer
121    adb shell test-mixer $1 -s 44100 \
122        -a /sdcard/aux44100nrota.wav -o /sdcard/tm44100nrota.wav \
123        sine:2,2000,44100
124    adb pull /sdcard/tm44100nrota.wav $2
125    adb pull /sdcard/aux44100nrota.wav $2
126}
127
128#
129# Call createwav to generate WAV files in various combinations
130#
131# i_i = integer input track, integer mixer output
132# f_f = float input track,   float mixer output
133# i_f = integer input track, float_mixer output
134#
135# If the mixer output is float, then the output WAV file is pcm float.
136#
137# TODO: create a "snr" like "diff" to automatically
138# compare files in these directories together.
139#
140
141createwav "" "tests/mixer_i_i"
142createwav "-f -m" "tests/mixer_f_f"
143createwav "-m" "tests/mixer_i_f"
144
145popd
146