git @ Cat's Eye Technologies linapple / b590013
changes to fix gcc warnings, clear any unused sound buffer to last value, change timeing to use gettimeofday instead of alarm signal Tim O'Brien 9 years ago
5 changed file(s) with 65 addition(s) and 72 deletion(s). Raw diff Collapse all Expand all
550550 char *
551551 md5str (const char *input)
552552 {
553 char result[16 * 3 +1];
553 static char result[16 * 3 +1];
554554 unsigned char* digest = (unsigned char*)md5 (input);
555555 int i;
556556
967967
968968 return 0;
969969 #endif
970 return 0;
970971 }
971972
972973 //-----------------------------------------------------------------------------
15391540 DWORD MB_GetVolume()
15401541 {
15411542 // return MockingboardVoice.dwUserVolume;
1543 return 0;
15421544 }
15431545
15441546 void MB_SetVolume(DWORD dwVolume, DWORD dwVolumeMax)
251251
252252 void audioCallback(short* stream, unsigned len)
253253 {
254 // clear Audio buffer
255 memset(stream,0,len * sizeof(short));
256
254 int i;
255 static short lastvalue = 0;
256
257257 assert((len & 1) == 0); // stereo
258258 unsigned len1, len2;
259259 unsigned available = getBufferFilled();
260
260261 //std::cerr << "DEBUG callback: " << available << std::endl;
261262 unsigned num = std::min(len, available);
262263 if ((readIdx + num) < bufferSize) {
270271 readIdx = len2;
271272 }
272273
274 if (available != 0) {
275 if (readIdx != 0)
276 lastvalue = mixBuffer[readIdx-1];
277 else
278 lastvalue = mixBuffer[bufferSize - 1];
279 }
280
281 for (i = num; i < len; i++) {
282 stream[i] = lastvalue;
283 }
284
273285 /* Note: cleared at the begininng of the func
274286
275287 int missing = len - available;
288300 available = getBuffer2Filled();
289301 //std::cerr << "DEBUG callback: " << available << std::endl;
290302 num = std::min(len, available);
291 unsigned i;
292303 if ((readIdx2 + num) < bufferSize) {
293304 // memcpy(stream, &mixBuffer[readIdx], num * sizeof(short));
294305 for(i = 0; i < num; i++)
4545 // Timer Functions - POSIX specific //
4646 //=============================================================================//
4747 // Vars
48 static bool g_bRefClockTimerActive = false;
49 static DWORD g_dwLastUsecPeriod = 0;
50
51 static bool g_bTimerToggle = false;
52 struct sigaction sa_SysClk;
53 struct itimerval mytimeset;
54
55 void SysClk_TickTimer(int signum)
56 { // should occur every specified times per second
57 g_bTimerToggle = true; // just set the toggle flag, and leave peacefully? --bb
58 }
48
49 static DWORD g_dwUsecPeriod = 0;
50
5951
6052 bool SysClk_InitTimer()
61 {// first initialization of the timer
62 /* memset(&sa_SysClk, 0, sizeof(sa_SysClk)); // clear sigaction struct
63 sa_SysClk.sa_handler = &SysClk_TickTimer;
64 sigaction(SIGALRM, &sa_SysClk, NULL); // set SIGALRM handler*/
65 if(signal(SIGALRM, SysClk_TickTimer) == SIG_ERR)
66 return false;
67
68 printf("Timer has been initted!\n");
53 {
6954 return true;
7055 }
7156
7257 void SysClk_UninitTimer()
7358 {
74 SysClk_StopTimer();
75 // signal(SIGALRM, NULL);
76 }
59 }
60
61
62 inline Uint32 uSecSinceStart() {
63 struct timeval latest;
64 static struct timeval start;
65 static bool first = true;
66
67 if (first) {
68 gettimeofday(&start, NULL);
69 first = false;
70 return 0;
71 }
72
73 gettimeofday(&latest, NULL);
74 if (latest.tv_sec == start.tv_sec) {
75 return latest.tv_usec - start.tv_usec;
76 } else {
77 return (1000000000 - start.tv_usec) +
78 latest.tv_usec +
79 (latest.tv_sec - (start.tv_sec +1))*1000000000;
80 }
81 }
82
7783
7884 void SysClk_WaitTimer()
7985 {
80 // printf("Waiting timer...\n");
81
82 if(!g_bRefClockTimerActive)
83 return;
84 // pause() - better than that?
85
86 while(!g_bTimerToggle)
87 usleep(1); // do nothing is something doing also? 0_0 --bb
88 g_bTimerToggle = false;
89
90 // printf("Timer has been ticked!\n");
86 static Uint32 old = 0;
87 Uint32 current;
88 Uint32 elapsed;
89
90 // Loop until next period
91 // if more than 500usec sleep to give up CPU
92 while (1) {
93 current = uSecSinceStart();
94 elapsed = current - old;
95 if (elapsed >= g_dwUsecPeriod) {
96 old = current;
97 return;
98 }
99 if ((g_dwUsecPeriod - elapsed) > 500) {
100 usleep(1);
101 }
102 }
91103 }
92104
93105 void SysClk_StartTimerUsec(DWORD dwUsecPeriod)
94106 {
95 // starting timer during dwUsecPeriod in microseconds???
96 // printf("Timer started %d usec\n", dwUsecPeriod);
97 if(g_bRefClockTimerActive && (g_dwLastUsecPeriod == dwUsecPeriod))
98 return;
99
100 SysClk_StopTimer();
101
102 // to comply with Windows DirectShow REFERENCE_TIME, which is in units of 100 nanoseconds
103 mytimeset.it_interval.tv_sec = 0;
104 mytimeset.it_interval.tv_usec = dwUsecPeriod;// * 10 100;
105 mytimeset.it_value.tv_sec = 0;
106 mytimeset.it_value.tv_usec = dwUsecPeriod;// * 10 / 100;
107
108 if(setitimer(ITIMER_REAL, &mytimeset, NULL) != 0) {
109 fprintf(stderr, "Error creating timer (setitimer failed)\n");
110 _ASSERT(0);
111 return;
112 }
113
114 g_dwLastUsecPeriod = dwUsecPeriod;
115 g_bRefClockTimerActive = true;
107 g_dwUsecPeriod = dwUsecPeriod;
116108 }
117109
118110 void SysClk_StopTimer()
119111 {
120 if(!g_bRefClockTimerActive)
121 return;
122
123 // Zero values just disables timers
124 mytimeset.it_interval.tv_sec = 0;
125 mytimeset.it_interval.tv_usec = 0;
126 mytimeset.it_value.tv_sec = 0;
127 mytimeset.it_value.tv_usec = 0;
128
129 setitimer(ITIMER_REAL, &mytimeset, NULL);
130
131 g_bTimerToggle = true;
132 g_bRefClockTimerActive = false;
133112 }
134113
135114 #else
167167 if (now - t < 350 * 86400)
168168 return t;
169169 }
170 return 0;
170171 }
171172
172173 static int check(char *buf,const char *monthname)