Subversion Repositories svnkaklik

Compare Revisions

Ignore whitespace Rev 532 → Rev 533

/programy/C/ix86/sound/sonar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/programy/C/ix86/sound/sonar.c
21,11 → 21,12
static unsigned int channels = 1; /* count of channels */
static unsigned int buffer_time = 500000; /* ring buffer length in us */
static unsigned int period_time = 100000; /* period time in us */
static double freq = 440; /* sinusoidal wave frequency in Hz */
static int verbose = 0; /* verbose flag */
static int resample = 1; /* enable alsa-lib resampling */
static int period_event = 0; /* produce poll event after each period */
 
#define SOUND_SPEED 340
 
unsigned int chirp_size;
 
int period=0;
388,24 → 389,24
fclose(out);
 
#define SIGNAL_SAMPLES 100000
#define SAMPLES 1000
 
for(n=0; n < (SIGNAL_SAMPLES - SAMPLES);n++){ //spocita korelaci pro mozna spozdeni
r=0;
for(m=0;m < SAMPLES;m++) r += chirp[m]*signal[m+n];
correlation[n]=r;
}
for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){ //spocita korelaci pro mozna spozdeni
r=0;
for(m=0;m < 1000;m++) r += chirp[m]*signal[m+n];
correlation[n]=r;
}
 
r=0;
for(n=0; n < (SIGNAL_SAMPLES - SAMPLES);n++){ //najde nejvetsi shodu (pro nazornost v samostatnem cyklu)
if (r < correlation[n]){
delay = n;
r = correlation[n];
}
}
r=0;
for(n=0; n < (SIGNAL_SAMPLES - chirp_size);n++){ //najde nejvetsi shodu (pro nazornost v samostatnem cyklu)
if (r < correlation[n]){
delay = n;
r = correlation[n];
}
}
 
printf("\nEcho zacina na: %d vzorku.\n", delay);
printf("\nCasove na: %ds", delay);
printf("Casove na: %f s\n", ((float)delay/rate));
printf("vzdalenost: %f m\n", (SOUND_SPEED*(float)delay/rate));
 
snd_pcm_close(playback_handle);
snd_pcm_close(capture_handle);