source: roaraudio/roard/loop.c @ 259:39b0173a540d

Last change on this file since 259:39b0173a540d was 259:39b0173a540d, checked in by phi, 16 years ago

got roar_stream_add_data() working!

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#ifdef MONITOR_LATENCY
8 struct timeval         try, ans;
9 long int ans_1last = 0, ans_2last = 0, ans_3last = 0;
10 long int loopc = 0;
11
12 printf("\n\e[s");
13 fflush(stdout);
14#endif
15
16 ROAR_DBG("main_loop(*) = ?");
17 alive = 1;
18 g_pos = 0;
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, g_pos);
40  } else {
41   if ( streams_get_mixbuffers(&streams_input, sa, g_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, g_pos);
56   output_buffer_flush(driver_inst, driver);
57   clients_send_mon(sa, g_pos);
58  }
59
60  midi_cb_update();
61//  output_buffer_reinit();
62
63  g_pos = ROAR_MATH_OVERFLOW_ADD(g_pos, ROAR_OUTPUT_BUFFER_SAMPLES);
64  ROAR_DBG("main_loop(*): current pos: %u", g_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.