source: roaraudio/roard/loop.c @ 9:73840ee4793d

Last change on this file since 9:73840ee4793d was 9:73840ee4793d, checked in by phi, 16 years ago

added some simple hacked code to messure latency in the main loop

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