From 612dc0a9776578896aae7af2537ff19c7661efc1 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Tue, 16 Feb 2021 21:48:22 +0000 Subject: [PATCH] Add macro for width of pixel rows --- src/apt.h | 7 +++++++ src/image.c | 2 +- src/main.c | 6 +++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/apt.h b/src/apt.h index 16aded7..e1429df 100644 --- a/src/apt.h +++ b/src/apt.h @@ -41,13 +41,17 @@ extern "C" { // Maximum height of an APT image in number of scanlines #define APT_MAX_HEIGHT 3000 +// Width in pixels of sync #define APT_SYNC_WIDTH 39 +// Width in pixels of space #define APT_SPC_WIDTH 47 +// Width in pixels of telemetry #define APT_TELE_WIDTH 45 // Width in pixels of a single channel image #define APT_CH_WIDTH 909 #define APT_FRAME_LEN 128 #define APT_CH_OFFSET (APT_SYNC_WIDTH+APT_SPC_WIDTH+APT_CH_WIDTH+APT_TELE_WIDTH) +// Width in pixels of full frame, including sync, space, images and telemetry #define APT_IMG_WIDTH 2080 // Offset in pixels to channel A #define APT_CHA_OFFSET (APT_SYNC_WIDTH+APT_SPC_WIDTH) @@ -55,6 +59,9 @@ extern "C" { #define APT_CHB_OFFSET (APT_SYNC_WIDTH+APT_SPC_WIDTH+APT_CH_WIDTH+APT_TELE_WIDTH+APT_SYNC_WIDTH+APT_SPC_WIDTH) #define APT_TOTAL_TELE (APT_SYNC_WIDTH+APT_SPC_WIDTH+APT_TELE_WIDTH+APT_SYNC_WIDTH+APT_SPC_WIDTH+APT_TELE_WIDTH) +// Width in elements of apt_image_t.prow arrays +#define APT_PROW_WIDTH 2150 + // apt_getpixelrow callback function to get audio samples. // context is the same as passed to apt_getpixelrow. typedef int (*apt_getsamples_t)(void *context, float *samples, int count); diff --git a/src/image.c b/src/image.c index 7c1fb5d..712cc17 100644 --- a/src/image.c +++ b/src/image.c @@ -318,7 +318,7 @@ int apt_cropNoise(apt_image_t *img){ // Remove the noisy rows at start for(int y = 0; y < img->nrow-startCrop; y++) { - memmove(img->prow[y], img->prow[y+startCrop], sizeof(float)*2150); + memmove(img->prow[y], img->prow[y+startCrop], sizeof(float)*APT_PROW_WIDTH); } // Ignore the noisy rows at the end diff --git a/src/main.c b/src/main.c index 0932587..677487d 100644 --- a/src/main.c +++ b/src/main.c @@ -161,7 +161,7 @@ static int processAudio(char *filename, options_t *opts){ // TODO: multithreading, would require some sort of input buffer for (img.nrow = 0; img.nrow < APT_MAX_HEIGHT; img.nrow++) { // Allocate memory for this row - img.prow[img.nrow] = (float *) malloc(sizeof(float) * 2150); + 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, &img.zenith, (img.nrow == 0), getsamples, NULL) == 0) @@ -216,8 +216,8 @@ static int processAudio(char *filename, options_t *opts){ // Create another buffer as to not modify the orignal apt_image_t tmpimg = img; for(int i = 0; i < img.nrow; i++){ - tmpimg.prow[i] = (float *) malloc(sizeof(float) * 2150); - memcpy(tmpimg.prow[i], img.prow[i], sizeof(float) * 2150); + tmpimg.prow[i] = (float *) malloc(sizeof(float) * APT_PROW_WIDTH); + memcpy(tmpimg.prow[i], img.prow[i], sizeof(float) * APT_PROW_WIDTH); } // Perform temperature calibration