From 8be50e7844ccc8a9fce263127978fb3017f0f60d Mon Sep 17 00:00:00 2001 From: Xerbo Date: Tue, 20 Sep 2022 19:12:46 +0100 Subject: [PATCH] Readd apt_image_t::zenith and MSVC complex #20 --- src/apt.h | 1 + src/dsp.c | 21 ++++++++++++++++++--- src/main.c | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/apt.h b/src/apt.h index a7998e5..2478e9e 100644 --- a/src/apt.h +++ b/src/apt.h @@ -81,6 +81,7 @@ typedef int (*apt_getsamples_t)(void *context, float *samples, int count); typedef struct { float *prow[APT_MAX_HEIGHT]; // Row buffers int nrow; // Number of rows + int zenith; // Row in image where satellite reaches peak elevation apt_channel_t chA, chB; // ID of each channel char name[256]; // Stripped filename char *palette; // Filename of palette diff --git a/src/dsp.c b/src/dsp.c index 5821095..47afe64 100755 --- a/src/dsp.c +++ b/src/dsp.c @@ -26,6 +26,12 @@ #include "taps.h" #include "util.h" +#ifdef _MSC_VER +typedef _Fcomplex complexf_t; +#else +typedef complex float complexf_t; +#endif + // Block sizes #define BLKAMP 32768 #define BLKIN 32768 @@ -59,11 +65,11 @@ int apt_init(double sample_rate) { return 0; } -static float pll(float complex in) { +static float pll(complexf_t in) { static float oscillator_phase = 0.0; // Internal oscillator - float complex osc = cos(oscillator_phase) + -sin(oscillator_phase)*I; + complexf_t osc = cos(oscillator_phase) + -sin(oscillator_phase)*I; in *= osc; // Error detector @@ -104,7 +110,7 @@ static int getamp(float *ampbuff, int count, apt_getsamples_t getsamples, void * } // Process read samples into a brightness value - float complex sample = hilbert_transform(&inbuff[idxin], hilbert_filter, HILBERT_FILTER_SIZE); + complexf_t sample = hilbert_transform(&inbuff[idxin], hilbert_filter, HILBERT_FILTER_SIZE); ampbuff[n] = pll(sample); // Increment current sample @@ -159,6 +165,7 @@ int apt_getpixelrow(float *pixelv, int nrow, int *zenith, int reset, apt_getsamp static size_t npv; static int synced = 0; static float max = 0.0; + static float minDoppler = 1000000000, previous = 0; if(reset) synced = 0; @@ -182,6 +189,14 @@ int apt_getpixelrow(float *pixelv, int nrow, int *zenith, int reset, apt_getsamp corr = convolve(&pixelv[1], sync_pattern, SYNC_PATTERN_SIZE - 1); lcorr = convolve(&pixelv[2], sync_pattern, SYNC_PATTERN_SIZE - 2); FreqLine = 1.0+((ecorr-lcorr) / corr / APT_IMG_WIDTH / 4.0); + + float val = fabs(lcorr - ecorr)*0.25 + previous*0.75; + if(val < minDoppler && nrow > 10){ + minDoppler = val; + *zenith = nrow; + } + previous = fabs(lcorr - ecorr); + // The point in which the pixel offset is recalculated if (corr < 0.75 * max) { synced = 0; diff --git a/src/main.c b/src/main.c index 0701c5a..51d91a4 100644 --- a/src/main.c +++ b/src/main.c @@ -172,7 +172,7 @@ static int processAudio(char *filename, options_t *opts){ img.prow[img.nrow] = (float *) malloc(sizeof(float) * APT_PROW_WIDTH); // Write into memory and break the loop when there are no more samples to read - if (apt_getpixelrow(img.prow[img.nrow], img.nrow, NULL, (img.nrow == 0), getsamples, NULL) == 0) + if (apt_getpixelrow(img.prow[img.nrow], img.nrow, &img.zenith, (img.nrow == 0), getsamples, NULL) == 0) break; if(opts->realtime) pushRow(img.prow[img.nrow], APT_IMG_WIDTH); @@ -197,7 +197,7 @@ static int processAudio(char *filename, options_t *opts){ // Crop noise from start and end of image if(CONTAINS(opts->effects, Crop_Noise)){ - apt_cropNoise(&img); + img.zenith -= apt_cropNoise(&img); } // Denoise