Subversion Repositories svnkaklik

Rev

Rev 540 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 540 Rev 541
Line 24... Line 24...
24
static int resample = 1;				/* enable alsa-lib resampling */
24
static int resample = 1;				/* enable alsa-lib resampling */
25
static int period_event = 0;				/* produce poll event after each period */
25
static int period_event = 0;				/* produce poll event after each period */
26
 
26
 
27
#define SOUND_SPEED	340
27
#define SOUND_SPEED	340
28
#define SIGNAL_SAMPLES 100000
28
#define SIGNAL_SAMPLES 100000
-
 
29
#define CHIRP_OFFSET	300 
29
 
30
 
30
unsigned int chirp_size;
31
unsigned int chirp_size;
31
 
32
 
32
int period=0;
33
int period=0;
33
int cperiod=0;
34
int cperiod=0;
Line 298... Line 299...
298
	struct async_private_data data;
299
	struct async_private_data data;
299
	snd_async_handler_t *chandler, *phandler;
300
	snd_async_handler_t *chandler, *phandler;
300
	int count;
301
	int count;
301
	unsigned int i,j,m,n;
302
	unsigned int i,j,m,n;
302
	unsigned int delay[10];	//store delay of signifed correlation
303
	unsigned int delay[10];	//store delay of signifed correlation
303
  	double l,r;  // store correlation at strict time
304
  	long int l,r;  // store correlation at strict time
304
	long int correlationl[100000]; //array to store correlation curve
305
	long int correlationl[100000]; //array to store correlation curve
305
	long int correlationr[100000]; //array to store correlation curve
306
	long int correlationr[100000]; //array to store correlation curve
306
 
307
 
307
	FILE *out;
308
	FILE *out;
308
 
309
 
Line 341... Line 342...
341
		exit(EXIT_FAILURE);
342
		exit(EXIT_FAILURE);
342
	}
343
	}
343
 
344
 
344
/// generate ping pattern
345
/// generate ping pattern
345
 
346
 
346
        chirp_size=linear_windowed_chirp(chirp,1000000, 200);
347
        chirp_size=linear_windowed_chirp(chirp,1000000, CHIRP_OFFSET);
347
 
348
 
348
/// register playback callback 
349
/// register playback callback 
349
	err = snd_async_add_pcm_handler(&phandler, playback_handle, async_playback_callback, &data); // fill by dummy &data
350
	err = snd_async_add_pcm_handler(&phandler, playback_handle, async_playback_callback, &data); // fill by dummy &data
350
	if (err < 0) {
351
	if (err < 0) {
351
		printf("Unable to register async handler\n");
352
		printf("Unable to register async handler\n");
Line 406... Line 407...
406
	i=0;
407
	i=0;
407
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//we have interleaved data we must have 2 saples step
408
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//we have interleaved data we must have 2 saples step
408
	  l=0;
409
	  l=0;
409
          r=0;
410
          r=0;
410
	  j=0;
411
	  j=0;
411
	  for(m=0;m < chirp_size;m++)
412
	  for(m=CHIRP_OFFSET;m < chirp_size;m++)
412
          {
413
          {
413
            l += chirp[m]*signal[i+j];	// correlate with left channel
414
            l += chirp[m]*signal[i+j];	// correlate with left channel
414
            r += chirp[m]*signal[i+j+1];	// correlate with right channel
415
            r += chirp[m]*signal[i+j+1];	// correlate with right channel
415
	    j+=2;
416
	    j+=2;
416
          }
417
          }
417
	  correlationl[n]=l;
418
	  correlationl[n]=l;
418
	  correlationr[n]=r;
419
	  correlationr[n]=r;
419
	  i+=2;
420
	  i+=2;
420
	}
421
	}
421
 
422
 
422
/*	printf("\nFinding echos...\n");
423
	printf("\nSearching echos...\n");
423
	r=0;
424
	r=0;
424
	l=0;
425
	l=0;
425
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//najde nejvetsi korelace
426
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//najde nejvetsi korelace
426
	  if (l < correlationl[n]){
427
	  if (l < correlationl[n]){
427
	  delay[1] = n;
428
	  delay[1] = n;
428
	  l = correlationl[n];
429
	  l = correlationl[n];
429
	  }
430
	  }
430
	  if (r < correlationr[n]){
431
	  if (r < correlationr[n]){
431
	  delay[1] = n;
432
	  delay[2] = n;
432
	  r = correlationr[n];
433
	  r = correlationr[n];
433
	  }
434
	  }
434
	}*/
435
	}
435
 
436
 
436
	out=fopen("./output.txt","w");
437
	out=fopen("./output.txt","w");
437
  j=0;
438
  j=0;
438
  for(i=0;i<=100000;i++){
439
  for(i=0;i<=60000;i++){
439
    fprintf(out,"%6d %6d %6d %6d %9ld %9ld\n",i,chirp[i],signal[j],signal[j+1],correlationl[i], correlationr[i]);
440
    fprintf(out,"%6d %6d %6d %6d %9ld %9ld\n",i,chirp[i],signal[j],signal[j+1],correlationl[i], correlationr[i]);
440
    j+=2;
441
    j+=2;
441
  }
442
  }
442
	fclose(out);
443
	fclose(out);
443
 
444