Subversion Repositories svnkaklik

Rev

Rev 536 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 536 Rev 537
Line 85... Line 85...
85
	}
85
	}
86
	if (rrate != rate) {
86
	if (rrate != rate) {
87
		printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err);
87
		printf("Rate doesn't match (requested %iHz, get %iHz)\n", rate, err);
88
		return -EINVAL;
88
		return -EINVAL;
89
	}
89
	}
-
 
90
	else printf("Rate set to %i Hz\n", rate, err); 
90
	/* set the buffer time */
91
	/* set the buffer time */
91
	err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, &dir);
92
	err = snd_pcm_hw_params_set_buffer_time_near(handle, params, &buffer_time, &dir);
92
	if (err < 0) {
93
	if (err < 0) {
93
		printf("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err));
94
		printf("Unable to set buffer time %i for playback: %s\n", buffer_time, snd_strerror(err));
94
		return err;
95
		return err;
Line 184... Line 185...
184
// vygeneruje linearni chirp a vzorky ulozi do pole
185
// vygeneruje linearni chirp a vzorky ulozi do pole
185
unsigned int linear_windowed_chirp(unsigned int *pole, unsigned int delka_pole)
186
unsigned int linear_windowed_chirp(unsigned int *pole, unsigned int delka_pole)
186
{  
187
{  
187
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
188
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
188
 
189
 
189
static const float f0 = 1000;
190
static const float f0 = 8000;
190
static const float fmax = 5000;
191
static const float fmax = 10000;
191
static const float Tw = 0.002;
192
static const float Tw = 0.002;
192
static float k;
193
static float k;
193
 
194
 
194
unsigned int n=0;
195
unsigned int n=0;
195
double t;
196
double t;
Line 294... Line 295...
294
	FILE *out;
295
	FILE *out;
295
 
296
 
296
	snd_pcm_hw_params_alloca(&hwparams);
297
	snd_pcm_hw_params_alloca(&hwparams);
297
	snd_pcm_sw_params_alloca(&swparams);
298
	snd_pcm_sw_params_alloca(&swparams);
298
 
299
 
-
 
300
 
299
//open and set playback device
301
//open and set playback device
300
	if ((err = snd_pcm_open(&playback_handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
302
	if ((err = snd_pcm_open(&playback_handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
301
		printf("Playback open error: %s\n", snd_strerror(err));
303
		printf("Playback open error: %s\n", snd_strerror(err));
302
		return 0;
304
		return 0;
303
	}
305
	}
Line 380... Line 382...
380
	printf("Waiting for transmitt all samples\n");
382
	printf("Waiting for transmitt all samples\n");
381
	while(cperiod<10) {
383
	while(cperiod<10) {
382
		sleep(1);
384
		sleep(1);
383
		printf(".");
385
		printf(".");
384
	}	
386
	}	
385
	printf("\nData transmitted... \nprocessing...\n");
387
	printf("\nData transmitted... \ncorrelating...\n");
386
 
388
 
387
#define SIGNAL_SAMPLES 100000
389
#define SIGNAL_SAMPLES 100000
388
 
390
 
389
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//spocita korelaci pro mozna spozdeni
391
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//spocita korelaci pro mozna spozdeni
390
	  r=0;
392
	  r=0;
391
	  for(m=0;m < 1000;m++) r += chirp[m]*signal[m+n];
393
	  for(m=0;m < chirp_size;m++) r += chirp[m]*signal[m+n];
392
	  correlation[n]=r;
394
	  correlation[n]=r;
393
	}
395
	}
394
 
396
 
-
 
397
	printf("\nFinding echos...\n");
395
	r=0;
398
	r=0;
396
 
-
 
397
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//najde nejvetsi korelace
399
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//najde nejvetsi korelace
398
	  if (r < correlation[n]){
400
	  if (r < correlation[n]){
399
	  delay[1] = n;
401
	  delay[1] = n;
400
	  r = correlation[n];
402
	  r = correlation[n];
401
	  }
403
	  }