source: roaraudio/roard/loop.c @ 257:087ca7261dea

Last change on this file since 257:087ca7261dea was 257:087ca7261dea, checked in by phi, 16 years ago

added midi_cb_update() to main_loop()

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