source: roaraudio/roard/loop.c @ 36:c5d92dd968cd

Last change on this file since 36:c5d92dd968cd was 36:c5d92dd968cd, checked in by phi, 16 years ago

changed latency messurment code a bit

File size: 2.1 KB
Line 
1//loop.c:
2
3#include "roard.h"
4
5int main_loop (int driver, DRIVER_USERDATA_T driver_inst, struct roar_audio_info * sa) {
6 void ** streams_input = NULL;
7 uint32_t pos = 0;
8#ifdef MONITOR_LATENCY
9 struct timeval         try, ans;
10 long int ans_1last = 0, ans_2last = 0, ans_3last = 0;
11 long int loopc = 0;
12
13 printf("\n\e[s");
14 fflush(stdout);
15#endif
16
17 ROAR_DBG("main_loop(*) = ?");
18 alive = 1;
19
20 while (alive) {
21#ifdef MONITOR_LATENCY
22 gettimeofday(&try, NULL);
23#endif
24
25  ROAR_DBG("main_loop(*): looping...");
26
27  ROAR_DBG("main_loop(*): check for new clients...");
28  net_check_listen();
29
30  ROAR_DBG("main_loop(*): check for new data...");
31  clients_check_all();
32
33  ROAR_DBG("main_loop(*): mixing clients...");
34  if ( g_standby ) {
35   // while in standby we still neet to get the buffers to free input buffer space.
36   streams_get_mixbuffers(&streams_input, sa, pos);
37  } else {
38   if ( streams_get_mixbuffers(&streams_input, sa, pos) == 0 ) {
39    mix_clients(g_output_buffer, sa->bits, streams_input, ROAR_OUTPUT_BUFFER_SAMPLES * sa->channels);
40   }
41  }
42
43/*
44  // while in standby we still need to write out our buffer to not run in an endless loop without
45  // a break
46*/
47
48  if ( g_standby ) {
49   usleep((1000000 * ROAR_OUTPUT_BUFFER_SAMPLES) / sa->rate);
50   printf("usleep(%li) = ?\n", (1000000 * ROAR_OUTPUT_BUFFER_SAMPLES) / sa->rate);
51  } else {
52   clients_send_filter(sa, pos);
53   output_buffer_flush(driver_inst, driver);
54   clients_send_mon(sa, pos);
55  }
56//  output_buffer_reinit();
57
58  pos = ROAR_MATH_OVERFLOW_ADD(pos, ROAR_OUTPUT_BUFFER_SAMPLES);
59  ROAR_DBG("main_loop(*): current pos: %u", pos);
60#ifdef MONITOR_LATENCY
61 gettimeofday(&ans, NULL);
62
63 while (ans.tv_sec > try.tv_sec) {
64  ans.tv_sec--;
65  ans.tv_usec += 1000000;
66 }
67 ans.tv_usec -= try.tv_usec;
68
69 if ( loopc % 128 ) {
70  printf("\e[ucurrent latency: %.3fms  average: %.3fms   ",  ans.tv_usec                               / (double)1000,
71                                                            (ans.tv_usec+ans_3last+ans_2last+ans_1last)/ (double)4000);
72  fflush(stdout);
73 }
74
75 ans_3last = ans_2last;
76 ans_2last = ans_1last;
77 ans_1last = ans.tv_usec;
78 loopc++;
79#endif
80 }
81
82 return -1;
83}
84
85//ll
Note: See TracBrowser for help on using the repository browser.