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
64# track__Resample / track__genericResample
65    adb shell test-mixer $1 -s 48000 \
66        -o /sdcard/tm48000gr.wav \
67        sine:2,4000,7520 chirp:2,9200 sine:1,3000,18000
68    adb pull /sdcard/tm48000gr.wav $2
69
70# Test:
71# process__genericResample
72# track__Resample / track__genericResample
73# track__NoResample / track__16BitsStereo / track__16BitsMono
74# Aux buffer
75    adb shell test-mixer $1 -c 5 -s 9307 \
76        -a /sdcard/aux9307gra.wav -o /sdcard/tm9307gra.wav \
77        sine:4,1000,3000 sine:1,2000,9307 chirp:3,9307
78    adb pull /sdcard/tm9307gra.wav $2
79    adb pull /sdcard/aux9307gra.wav $2
80
81# Test:
82# process__genericNoResampling
83# track__NoResample / track__16BitsStereo / track__16BitsMono
84    adb shell test-mixer $1 -s 32000 \
85        -o /sdcard/tm32000gnr.wav \
86        sine:2,1000,32000 chirp:2,32000  sine:1,3000,32000
87    adb pull /sdcard/tm32000gnr.wav $2
88
89# Test:
90# process__genericNoResampling
91# track__NoResample / track__16BitsStereo / track__16BitsMono
92# Aux buffer
93    adb shell test-mixer $1 -s 32000 \
94        -a /sdcard/aux32000gnra.wav -o /sdcard/tm32000gnra.wav \
95        sine:2,1000,32000 chirp:2,32000  sine:1,3000,32000
96    adb pull /sdcard/tm32000gnra.wav $2
97    adb pull /sdcard/aux32000gnra.wav $2
98
99# Test:
100# process__NoResampleOneTrack / process__OneTrack16BitsStereoNoResampling
101# Downmixer
102    adb shell test-mixer $1 -s 32000 \
103        -o /sdcard/tm32000nrot.wav \
104        sine:6,1000,32000
105    adb pull /sdcard/tm32000nrot.wav $2
106
107# Test:
108# process__NoResampleOneTrack / OneTrack16BitsStereoNoResampling
109# Aux buffer
110    adb shell test-mixer $1 -s 44100 \
111        -a /sdcard/aux44100nrota.wav -o /sdcard/tm44100nrota.wav \
112        sine:2,2000,44100
113    adb pull /sdcard/tm44100nrota.wav $2
114    adb pull /sdcard/aux44100nrota.wav $2
115}
116
117#
118# Call createwav to generate WAV files in various combinations
119#
120# i_i = integer input track, integer mixer output
121# f_f = float input track,   float mixer output
122# i_f = integer input track, float_mixer output
123#
124# If the mixer output is float, then the output WAV file is pcm float.
125#
126# TODO: create a "snr" like "diff" to automatically
127# compare files in these directories together.
128#
129
130createwav "" "tests/mixer_i_i"
131createwav "-f -m" "tests/mixer_f_f"
132createwav "-m" "tests/mixer_i_f"
133
134popd
135