Subversion Repositories svnkaklik

Rev

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

Rev 537 Rev 538
Line 24... Line 24...
24
static int verbose = 0;					/* verbose flag */
24
static int verbose = 0;					/* verbose flag */
25
static int resample = 1;				/* enable alsa-lib resampling */
25
static int resample = 1;				/* enable alsa-lib resampling */
26
static int period_event = 0;				/* produce poll event after each period */
26
static int period_event = 0;				/* produce poll event after each period */
27
 
27
 
28
#define SOUND_SPEED	340
28
#define SOUND_SPEED	340
-
 
29
#define SIGNAL_SAMPLES 100000
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 185... Line 186...
185
// vygeneruje linearni chirp a vzorky ulozi do pole
186
// vygeneruje linearni chirp a vzorky ulozi do pole
186
unsigned int linear_windowed_chirp(unsigned int *pole, unsigned int delka_pole)
187
unsigned int linear_windowed_chirp(unsigned int *pole, unsigned int delka_pole)
187
{  
188
{  
188
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
189
unsigned int maxval = (1 << (snd_pcm_format_width(format) - 1)) - 1;
189
 
190
 
190
static const float f0 = 8000;
191
static const float f0 = 3000;
191
static const float fmax = 10000;
192
static const float fmax = 5000;
192
static const float Tw = 0.002;
193
static const float Tw = 0.002;
193
static float k;
194
static float k;
194
 
195
 
195
unsigned int n=0;
196
unsigned int n=0;
196
double t;
197
double t;
Line 354... Line 355...
354
	if (err < 0) {
355
	if (err < 0) {
355
		printf("Unable to register async handler\n");
356
		printf("Unable to register async handler\n");
356
		exit(EXIT_FAILURE);
357
		exit(EXIT_FAILURE);
357
	}
358
	}
358
 
359
 
359
//start playback
-
 
360
	if (snd_pcm_state(playback_handle) == SND_PCM_STATE_PREPARED) {
-
 
361
		err = snd_pcm_start(playback_handle);
-
 
362
		if (err < 0) {
-
 
363
			printf("Start error: %s\n", snd_strerror(err));
-
 
364
			exit(EXIT_FAILURE);
-
 
365
		}
-
 
366
	}
-
 
367
 
360
 
368
//start capture
361
//start capture
369
	if ((err = snd_pcm_prepare (capture_handle)) < 0) {
362
	if ((err = snd_pcm_prepare (capture_handle)) < 0) {
370
		fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
363
		fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
371
			 snd_strerror (err));
364
			 snd_strerror (err));
Line 375... Line 368...
375
	err = snd_pcm_start(capture_handle);
368
	err = snd_pcm_start(capture_handle);
376
	if (err < 0) {
369
	if (err < 0) {
377
			printf("Start error: %s\n", snd_strerror(err));
370
			printf("Start error: %s\n", snd_strerror(err));
378
			exit(EXIT_FAILURE);
371
			exit(EXIT_FAILURE);
379
	}
372
	}
-
 
373
 
-
 
374
 
-
 
375
//start playback
-
 
376
	if (snd_pcm_state(playback_handle) == SND_PCM_STATE_PREPARED) {
-
 
377
		err = snd_pcm_start(playback_handle);
-
 
378
		if (err < 0) {
-
 
379
			printf("Start error: %s\n", snd_strerror(err));
-
 
380
			exit(EXIT_FAILURE);
-
 
381
		}
-
 
382
	}
-
 
383
 
380
	
384
	
381
//wait until all samples aren't transmitted
385
//wait until all samples aren't transmitted
382
	printf("Waiting for transmitt all samples\n");
386
	printf("Waiting for transmitt all samples\n");
383
	while(cperiod<10) {
387
	while(cperiod<10) {
384
		sleep(1);
388
		sleep(1);
385
		printf(".");
389
		printf(".");
386
	}	
390
	}	
387
	printf("\nData transmitted... \ncorrelating...\n");
391
	printf("\nData transmitted... \ncorrelating...\n");
388
 
392
 
389
#define SIGNAL_SAMPLES 100000
-
 
390
 
-
 
391
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//spocita korelaci pro mozna spozdeni
393
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//spocita korelaci pro mozna spozdeni
392
	  r=0;
394
	  r=0;
393
	  for(m=0;m < chirp_size;m++) r += chirp[m]*signal[m+n];
395
	  for(m=chirp_size;m > 0;m--) r += chirp[m]*signal[m+n];	// reverse echo patern
394
	  correlation[n]=r;
396
	  correlation[n]=abs(r);
395
	}
397
	}
396
 
398
 
397
	printf("\nFinding echos...\n");
399
	printf("\nFinding echos...\n");
398
	r=0;
400
	r=0;
399
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//najde nejvetsi korelace
401
	for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){			//najde nejvetsi korelace