• Home
  • Raw
  • Download

Lines Matching refs:bat

34 static float sumaudio(struct bat *bat, short int *buffer, int frames)  in sumaudio()  argument
42 for (n = 0; n < bat->channels; n++) { in sumaudio()
48 sum = sum / bat->channels; in sumaudio()
53 static void play_and_listen(struct bat *bat, void *buffer, int frames) in play_and_listen() argument
61 int num = bat->latency.number; in play_and_listen()
63 averageinput = (int) (sumaudio(bat, buffer, frames) / frames); in play_and_listen()
67 if (averageinput > bat->latency.threshold) { in play_and_listen()
72 if (*input++ > bat->latency.threshold) in play_and_listen()
74 *input += bat->channels; in play_and_listen()
79 bat->latency.samples += n; in play_and_listen()
82 if (bat->latency.samples > frames) { in play_and_listen()
83 bat->latency.result[num - 1] = in play_and_listen()
84 (float) bat->latency.samples * 1000 / bat->rate; in play_and_listen()
85 fprintf(bat->log, in play_and_listen()
88 (int) bat->latency.result[num - 1]); in play_and_listen()
91 if (bat->latency.result[n] > max) in play_and_listen()
92 max = bat->latency.result[n]; in play_and_listen()
93 if (bat->latency.result[n] < min) in play_and_listen()
94 min = bat->latency.result[n]; in play_and_listen()
95 sum += bat->latency.result[n]; in play_and_listen()
100 bat->latency.state = in play_and_listen()
102 bat->latency.is_capturing = false; in play_and_listen()
107 bat->latency.final_result = in play_and_listen()
109 fprintf(bat->log, in play_and_listen()
111 bat->latency.final_result); in play_and_listen()
113 bat->latency.state = in play_and_listen()
115 bat->latency.is_capturing = false; in play_and_listen()
120 bat->latency.state = LATENCY_STATE_WAITING; in play_and_listen()
122 bat->latency.number++; in play_and_listen()
126 bat->latency.state = LATENCY_STATE_WAITING; in play_and_listen()
130 bat->latency.samples += frames; in play_and_listen()
134 if (bat->latency.samples > bat->rate) { in play_and_listen()
135 bat->latency.error++; in play_and_listen()
137 if (bat->latency.error > LATENCY_TEST_NUMBER) { in play_and_listen()
138 fprintf(bat->err, in play_and_listen()
140 fprintf(bat->err, in play_and_listen()
142 bat->latency.state = in play_and_listen()
144 bat->latency.is_capturing = false; in play_and_listen()
149 bat->latency.state = LATENCY_STATE_WAITING; in play_and_listen()
156 static void calculate_threshold(struct bat *bat) in calculate_threshold() argument
163 average = bat->latency.sum / bat->latency.samples / 32767.0f; in calculate_threshold()
165 bat->latency.threshold = (int) (powf(10.0f, reference / 20.0f) in calculate_threshold()
169 void roundtrip_latency_init(struct bat *bat) in roundtrip_latency_init() argument
171 bat->latency.number = 1; in roundtrip_latency_init()
172 bat->latency.state = LATENCY_STATE_MEASURE_FOR_1_SECOND; in roundtrip_latency_init()
173 bat->latency.final_result = 0; in roundtrip_latency_init()
174 bat->latency.samples = 0; in roundtrip_latency_init()
175 bat->latency.sum = 0; in roundtrip_latency_init()
176 bat->latency.threshold = 0; in roundtrip_latency_init()
177 bat->latency.is_capturing = false; in roundtrip_latency_init()
178 bat->latency.is_playing = false; in roundtrip_latency_init()
179 bat->latency.error = 0; in roundtrip_latency_init()
180 bat->latency.xrun_error = false; in roundtrip_latency_init()
181 bat->frames = LATENCY_TEST_TIME_LIMIT * bat->rate; in roundtrip_latency_init()
182 bat->periods_played = 0; in roundtrip_latency_init()
185 int handleinput(struct bat *bat, void *buffer, int frames) in handleinput() argument
187 switch (bat->latency.state) { in handleinput()
190 bat->latency.sum += sumaudio(bat, buffer, frames); in handleinput()
191 bat->latency.samples += frames; in handleinput()
194 if (bat->latency.samples >= bat->rate) { in handleinput()
195 calculate_threshold(bat); in handleinput()
196 bat->latency.state = LATENCY_STATE_PLAY_AND_LISTEN; in handleinput()
197 bat->latency.samples = 0; in handleinput()
198 bat->latency.sum = 0; in handleinput()
204 play_and_listen(bat, buffer, frames); in handleinput()
209 bat->latency.samples += frames; in handleinput()
211 if (bat->latency.samples > bat->rate) { in handleinput()
213 bat->latency.samples = 0; in handleinput()
214 bat->latency.state = LATENCY_STATE_MEASURE_FOR_1_SECOND; in handleinput()
225 int handleoutput(struct bat *bat, void *buffer, int bytes, int frames) in handleoutput() argument
230 if (bat->periods_played * frames > 2 * bat->rate in handleoutput()
231 && bat->latency.is_capturing == false) in handleoutput()
232 return bat->latency.state; in handleoutput()
234 if (bat->latency.state == LATENCY_STATE_PLAY_AND_LISTEN) in handleoutput()
235 err = generate_sine_wave(bat, frames, buffer); in handleoutput()