2
* Miscellaneous Functions
7
* Copyright (C) 1997-2008 Jim Jackson jj@franjam.org.uk
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with this program - see the file COPYING; if not, write to
21
* the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
27
#include <sys/types.h>
32
* delay(us) wait us microsecs using select. Effectively
33
* causes current process to stop and a reschedule take place
34
* as well as doing the delay.
44
(void)select( 1, (fd_set *)0, (fd_set *)0, (fd_set *)0, &tv );
58
if (err) fprintf(stderr,"[%s] %s : %s\n",sys,strerror(err),msg);
63
/* hcf(x,y) find highest common factor of x and y
70
register unsigned a,b,r;
77
for ( ; r=a%b ; a=b, b=r) { }
82
/* parse(s,aa,sep) splits s up into parameters and stores ptrs
83
* to each prm in ptr array aa (upto MAX_ARGS)
84
* params are space or tab or 'sep' seperated, and may be
85
* enclosed in single or double quotes e.g. 'this is 1 prm'
87
* returns number of parameters parsed
97
#define EOL ((*s=='\0') || (*s=='\n'))
98
#define EOP ((*s==' ') || (*s=='\t') || (*s==sep))
99
#define QUOTE ((*s=='\'') || (*s=='"'))
103
for ( ; EOP; s++) {} /* skip leading separators */
105
if (EOL) return((--i)?i:1);
109
while (!(EOL || EOP)) {
111
for (s++; !(EOL || QUOTE); ) *p++=*s++;
115
if (EOL) {*p='\0'; return(i);}
126
* mstosamples(ms,sr) convert ms millisecs into number of samples
127
* given that the sample rate is sr samples/sec
138
m=INT_MAX/(4*sr); /* we need to make sure we don't overflow INT size
139
including when no. of samples may get upped for stereo
140
16 bit into a byte count for getting buffers etc
142
for ( d=1000; d>0 && ms>m; d/=10 ) { ms/=10; }
144
return((sr*ms+d/2)/d);