Subversion Repositories svnkaklik

Rev

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

Rev 532 Rev 533
Line 19... Line 19...
19
static snd_pcm_format_t format = SND_PCM_FORMAT_S16;	/* sample format */
19
static snd_pcm_format_t format = SND_PCM_FORMAT_S16;	/* sample format */
20
static unsigned int rate = 44100;			/* stream rate */
20
static unsigned int rate = 44100;			/* stream rate */
21
static unsigned int channels = 1;			/* count of channels */
21
static unsigned int channels = 1;			/* count of channels */
22
static unsigned int buffer_time = 500000;		/* ring buffer length in us */
22
static unsigned int buffer_time = 500000;		/* ring buffer length in us */
23
static unsigned int period_time = 100000;		/* period time in us */
23
static unsigned int period_time = 100000;		/* period time in us */
24
static double freq = 440;				/* sinusoidal wave frequency in Hz */
-
 
25
static int verbose = 0;					/* verbose flag */
24
static int verbose = 0;					/* verbose flag */
26
static int resample = 1;				/* enable alsa-lib resampling */
25
static int resample = 1;				/* enable alsa-lib resampling */
27
static int period_event = 0;				/* produce poll event after each period */
26
static int period_event = 0;				/* produce poll event after each period */
28
 
27
 
-
 
28
#define SOUND_SPEED	340
-
 
29
 
29
unsigned int chirp_size;
30
unsigned int chirp_size;
30
 
31
 
31
int period=0;
32
int period=0;
32
int cperiod=0;
33
int cperiod=0;
33
int chirp[100000];
34
int chirp[100000];
Line 386... Line 387...
386
	out=fopen("./output.txt","w");
387
	out=fopen("./output.txt","w");
387
	for(i=0;i<=100000;i++) fprintf(out,"%6d	%6d %6d \n",i,chirp[i],signal[i]); 
388
	for(i=0;i<=100000;i++) fprintf(out,"%6d	%6d %6d \n",i,chirp[i],signal[i]); 
388
	fclose(out);
389
	fclose(out);
389
 
390
 
390
#define SIGNAL_SAMPLES 100000
391
#define SIGNAL_SAMPLES 100000
391
#define SAMPLES  1000
-
 
392
 
392
 
393
   for(n=0; n < (SIGNAL_SAMPLES - SAMPLES);n++){			//spocita korelaci pro mozna spozdeni
393
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//spocita korelaci pro mozna spozdeni
394
     r=0;
394
	  r=0;
395
     for(m=0;m < SAMPLES;m++) r += chirp[m]*signal[m+n];
395
	  for(m=0;m < 1000;m++) r += chirp[m]*signal[m+n];
396
     correlation[n]=r;
396
	  correlation[n]=r;
397
   }
397
	}
398
 
398
 
399
   r=0;
399
	r=0;
400
   for(n=0; n < (SIGNAL_SAMPLES - SAMPLES);n++){			//najde nejvetsi shodu (pro nazornost v samostatnem cyklu)
400
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//najde nejvetsi shodu (pro nazornost v samostatnem cyklu)
401
     if (r < correlation[n]){
401
	  if (r < correlation[n]){
402
       delay = n;
402
	  delay = n;
403
       r = correlation[n];
403
	  r = correlation[n];
404
     }
404
	  }
405
   }
405
	}
406
 
406
 
407
	printf("\nEcho zacina na: %d vzorku.\n", delay);
407
	printf("\nEcho zacina na: %d vzorku.\n", delay);
408
	printf("\nCasove na: %ds", delay);
408
	printf("Casove na: %f s\n", ((float)delay/rate));
-
 
409
	printf("vzdalenost: %f m\n", (SOUND_SPEED*(float)delay/rate));
409
 
410
 
410
	snd_pcm_close(playback_handle);
411
	snd_pcm_close(playback_handle);
411
	snd_pcm_close(capture_handle);
412
	snd_pcm_close(capture_handle);
412
	return 0;
413
	return 0;
413
}
414
}