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/services/audioflinger/
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/libaudioresampler.so /system/lib
50adb push $OUT/system/bin/test-mixer /system/bin
51
52# createwav creates a series of WAV files testing various
53# mixer settings
54# $1 = flags
55# $2 = directory
56function createwav() {
57# create directory if it doesn't exist
58    if [ ! -d $2 ]; then
59        mkdir $2
60    fi
61
62# Test:
63# process__genericResampling with mixed integer and float track input
64# track__Resample / track__genericResample
65    adb shell test-mixer $1 -s 48000 \
66        -o /sdcard/tm48000grif.wav \
67        sine:2,4000,7520 chirp:2,9200 sine:1,3000,18000 \
68        sine:f,6,6000,19000  chirp:i,4,30000
69    adb pull /sdcard/tm48000grif.wav $2
70
71# Test:
72# process__genericResampling
73# track__Resample / track__genericResample
74    adb shell test-mixer $1 -s 48000 \
75        -o /sdcard/tm48000gr.wav \
76        sine:2,4000,7520 chirp:2,9200 sine:1,3000,18000 \
77        sine:6,6000,19000
78    adb pull /sdcard/tm48000gr.wav $2
79
80# Test:
81# process__genericResample
82# track__Resample / track__genericResample
83# track__NoResample / track__16BitsStereo / track__16BitsMono
84# Aux buffer
85    adb shell test-mixer $1 -c 5 -s 9307 \
86        -a /sdcard/aux9307gra.wav -o /sdcard/tm9307gra.wav \
87        sine:4,1000,3000 sine:1,2000,9307 chirp:3,9307
88    adb pull /sdcard/tm9307gra.wav $2
89    adb pull /sdcard/aux9307gra.wav $2
90
91# Test:
92# process__genericNoResampling
93# track__NoResample / track__16BitsStereo / track__16BitsMono
94    adb shell test-mixer $1 -s 32000 \
95        -o /sdcard/tm32000gnr.wav \
96        sine:2,1000,32000 chirp:2,32000  sine:1,3000,32000
97    adb pull /sdcard/tm32000gnr.wav $2
98
99# Test:
100# process__genericNoResampling
101# track__NoResample / track__16BitsStereo / track__16BitsMono
102# Aux buffer
103    adb shell test-mixer $1 -s 32000 \
104        -a /sdcard/aux32000gnra.wav -o /sdcard/tm32000gnra.wav \
105        sine:2,1000,32000 chirp:2,32000  sine:1,3000,32000
106    adb pull /sdcard/tm32000gnra.wav $2
107    adb pull /sdcard/aux32000gnra.wav $2
108
109# Test:
110# process__NoResampleOneTrack / process__OneTrack16BitsStereoNoResampling
111# Downmixer
112    adb shell test-mixer $1 -s 32000 \
113        -o /sdcard/tm32000nrot.wav \
114        sine:6,1000,32000
115    adb pull /sdcard/tm32000nrot.wav $2
116
117# Test:
118# process__NoResampleOneTrack / OneTrack16BitsStereoNoResampling
119# Aux buffer
120    adb shell test-mixer $1 -s 44100 \
121        -a /sdcard/aux44100nrota.wav -o /sdcard/tm44100nrota.wav \
122        sine:2,2000,44100
123    adb pull /sdcard/tm44100nrota.wav $2
124    adb pull /sdcard/aux44100nrota.wav $2
125}
126
127#
128# Call createwav to generate WAV files in various combinations
129#
130# i_i = integer input track, integer mixer output
131# f_f = float input track,   float mixer output
132# i_f = integer input track, float_mixer output
133#
134# If the mixer output is float, then the output WAV file is pcm float.
135#
136# TODO: create a "snr" like "diff" to automatically
137# compare files in these directories together.
138#
139
140createwav "" "tests/mixer_i_i"
141createwav "-f -m" "tests/mixer_f_f"
142createwav "-m" "tests/mixer_i_f"
143
144popd
145