8magsvn – Diff between revs 36 and 37

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 36 Rev 37
Line 18... Line 18...
18 static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */ 18 static snd_pcm_format_t format = SND_PCM_FORMAT_S16; /* sample format */
19 static unsigned int rate = 48000; /* stream rate */ 19 static unsigned int rate = 48000; /* stream rate */
20 static int resample = 1; /* enable alsa-lib resampling */ 20 static int resample = 1; /* enable alsa-lib resampling */
21 static int period_event = 0; /* produce poll event after each period */ 21 static int period_event = 0; /* produce poll event after each period */
22   22  
23 static snd_pcm_uframes_t buffer_size = 20000; // size of buffer at sound card 23 static snd_pcm_uframes_t buffer_size = 30000; // size of buffer at sound card
24 static snd_pcm_uframes_t period_size = 4000; //samples per frame 24 static snd_pcm_uframes_t period_size = 8000; //samples per frame
25 static snd_output_t *output = NULL; 25 static snd_output_t *output = NULL;
26   26  
27 #define MAX_BINS 8 27 #define MAX_BINS 8 //define nomber of recorded channels
28 28
29 int sample_count; 29 int sample_count;
30 double q0; 30 double q0;
31 double q1[MAX_BINS]; 31 double q1[MAX_BINS];
32 double q2[MAX_BINS]; 32 double q2[MAX_BINS];
33 double r[MAX_BINS]; 33 double r[MAX_BINS];
34 double coefs[MAX_BINS] ; 34 double coefs[MAX_BINS] ;
35 35
36 FILE *out; 36 FILE *out;
37   37  
38 double freqs[MAX_BINS] = 38 double freqs[MAX_BINS] = // define recorded frequencies
39 { 39 {
40 697, 40 697,
41 770, 41 770,
42 852, 42 852,
43 941, 43 941,
Line 58... Line 58...
58 * Where k = (int) (0.5 + ((float)GOERTZEL_N * target_freq) / SAMPLING_RATE)); 58 * Where k = (int) (0.5 + ((float)GOERTZEL_N * target_freq) / SAMPLING_RATE));
59 * 59 *
60 * More simply: coef = 2.0 * cos( (2.0 * PI * target_freq) / SAMPLING_RATE ); 60 * More simply: coef = 2.0 * cos( (2.0 * PI * target_freq) / SAMPLING_RATE );
61 */ 61 */
62   62  
63 void calc_coeffs() 63 void calc_coeffs() // calculate GOERTZEL coefficients
64 { 64 {
65 int n; 65 int n;
66 66
67 for(n = 0; n < MAX_BINS; n++) 67 for(n = 0; n < MAX_BINS; n++)
68 { 68 {
Line 192... Line 192...
192   192  
193 /////////// CALL BACK STUFF /////////////////// 193 /////////// CALL BACK STUFF ///////////////////
194 static void async_capture_callback(snd_async_handler_t *ahandler) 194 static void async_capture_callback(snd_async_handler_t *ahandler)
195 { 195 {
196 snd_pcm_t *handle = snd_async_handler_get_pcm(ahandler); 196 snd_pcm_t *handle = snd_async_handler_get_pcm(ahandler);
-   197 struct timeval tv;
-   198 struct tm *tm;
-   199 double fsecs;
-   200 time_t ud;
-   201  
197 int err; 202 int err;
198 short signal[100000]; 203 short signal[100000];
-   204 char fname[100];
199 unsigned int n,i; 205 unsigned int n,i;
200   206  
201 while (snd_pcm_avail_update(handle) >= period_size) { // read until data is ready in buffer 207 while (snd_pcm_avail_update(handle) >= period_size) { // read until data is ready in buffer
-   208
-   209 gettimeofday( &tv, NULL); //get microsecond precise epoch time
-   210 fsecs = tv.tv_sec + 1e-6 * tv.tv_usec; // split seconds and microseconds to seconds
-   211 ud = fsecs; //tv.tv_sec - tv.tv_sec % 86400; // convert to time_t format??
-   212 tm = gmtime( &ud); // decode epoch time to UTC time
-   213  
-   214 sprintf(fname, "%s/%02d%02d%02d.txt", "./", tm->tm_year - 100, tm->tm_mon+1, tm->tm_mday);
202   215  
203 err = snd_pcm_readi(handle, signal, period_size); 216 err = snd_pcm_readi(handle, signal, period_size);
-   217  
204 if (err < 0) { 218 if (err < 0) {
205 printf("Read error: %s\n", snd_strerror(err)); 219 printf("Read error: %s\n", snd_strerror(err));
206 exit(EXIT_FAILURE); 220 exit(EXIT_FAILURE);
207 } 221 }
208 if (err != period_size) { 222 if (err != period_size) {
Line 217... Line 231...
217 q2[i] = q1[i]; 231 q2[i] = q1[i];
218 q1[i] = q0; 232 q1[i] = q0;
219 } 233 }
220 } 234 }
221 235
222 for ( i=0; i<MAX_BINS; i++ ) 236 for ( i=0; i<MAX_BINS; i++ )
223 { 237 {
224 r[i] = (q1[i] * q1[i]) + (q2[i] * q2[i]) - (coefs[i] * q1[i] * q2[i]); 238 r[i] = (q1[i] * q1[i]) + (q2[i] * q2[i]) - (coefs[i] * q1[i] * q2[i]);
225 q1[i] = 0.0; 239 q1[i] = 0.0;
226 q2[i] = 0.0; 240 q2[i] = 0.0;
227 } 241 }
-   242  
228 out=fopen("./output.txt","a"); 243 out=fopen(fname,"a+");
-   244 fprintf(out,"%02d:%02d:%2.5f ", tm->tm_hour, tm->tm_min, tm->tm_sec + 1e-6 * tv.tv_usec);
229 for(i=0;i<MAX_BINS;i++) fprintf(out,"%.e5 ",r[i]); 245 for(i=0;i<MAX_BINS;i++) fprintf(out,"%.e5 ",r[i]);
230 fprintf(out,"\n"); 246 fprintf(out,"\n");
231 fclose(out); 247 fclose(out);
232 } 248 }
233 } 249 }
234   250  
235   251  
236 int main(int argc, char *argv[]) 252 int main(int argc, char *argv[])