From 3141493ae68f4f377e1bafaa4848d3cfb9a4fb09 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Tue, 16 Feb 2021 21:03:47 +0000 Subject: [PATCH] Rename apt_getsample to apt_getsamples, as it gets more than one sample. --- src/apt.h | 4 ++-- src/dsp.c | 16 ++++++++-------- src/main.c | 14 +++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/apt.h b/src/apt.h index b97d745..022f00a 100644 --- a/src/apt.h +++ b/src/apt.h @@ -44,7 +44,7 @@ extern "C" { // apt_getpixelrow callback function to get audio samples. // context is the same as passed to apt_getpixelrow. -typedef int (*apt_getsample_t)(void *context, float *samples, int count); +typedef int (*apt_getsamples_t)(void *context, float *samples, int count); typedef struct { float *prow[APT_MAX_HEIGHT]; // Row buffers @@ -60,7 +60,7 @@ typedef struct { } apt_rgb_t; int APT_API apt_init(double sample_rate); -int APT_API apt_getpixelrow(float *pixelv, int nrow, int *zenith, int reset, apt_getsample_t getsample, void *context); +int APT_API apt_getpixelrow(float *pixelv, int nrow, int *zenith, int reset, apt_getsamples_t getsamples, void *context); void APT_API apt_histogramEqualise(float **prow, int nrow, int offset, int width); void APT_API apt_linearEnhance(float **prow, int nrow, int offset, int width); diff --git a/src/dsp.c b/src/dsp.c index e9becd7..63bf1da 100755 --- a/src/dsp.c +++ b/src/dsp.c @@ -131,7 +131,7 @@ static double pll(double I, double Q) { } // Convert samples into pixels -static int getamp(double *ampbuff, int count, apt_getsample_t getsample, void *context) { +static int getamp(double *ampbuff, int count, apt_getsamples_t getsamples, void *context) { static float inbuff[BLKIN]; static int idxin = 0; static int nin = 0; @@ -147,7 +147,7 @@ static int getamp(double *ampbuff, int count, apt_getsample_t getsample, void *c idxin = 0; // Read some samples - res = getsample(context, &(inbuff[nin]), BLKIN - nin); + res = getsamples(context, &(inbuff[nin]), BLKIN - nin); nin += res; // Make sure there is enough samples to continue @@ -168,7 +168,7 @@ static int getamp(double *ampbuff, int count, apt_getsample_t getsample, void *c } // Sub-pixel offsetting + FIR compensation -int getpixelv(float *pvbuff, int count, apt_getsample_t getsample, void *context) { +int getpixelv(float *pvbuff, int count, apt_getsamples_t getsamples, void *context) { // Amplitude buffer static double ampbuff[BLKAMP]; static int nam = 0; @@ -187,7 +187,7 @@ int getpixelv(float *pvbuff, int count, apt_getsample_t getsample, void *context int res; memmove(ampbuff, &(ampbuff[idxam]), nam * sizeof(double)); idxam = 0; - res = getamp(&(ampbuff[nam]), BLKAMP - nam, getsample, context); + res = getamp(&(ampbuff[nam]), BLKAMP - nam, getsamples, context); nam += res; if (nam < m) return n; @@ -207,7 +207,7 @@ int getpixelv(float *pvbuff, int count, apt_getsample_t getsample, void *context } // Get an entire row of pixels, aligned with sync markers -int apt_getpixelrow(float *pixelv, int nrow, int *zenith, int reset, apt_getsample_t getsample, void *context) { +int apt_getpixelrow(float *pixelv, int nrow, int *zenith, int reset, apt_getsamples_t getsamples, void *context) { static float pixels[PixelLine + SyncFilterLen]; static int npv; static int synced = 0; @@ -225,7 +225,7 @@ int apt_getpixelrow(float *pixelv, int nrow, int *zenith, int reset, apt_getsamp // Get the sync line if (npv < SyncFilterLen + 2) { - res = getpixelv(&(pixelv[npv]), SyncFilterLen + 2 - npv, getsample, context); + res = getpixelv(&(pixelv[npv]), SyncFilterLen + 2 - npv, getsamples, context); npv += res; if (npv < SyncFilterLen + 2) return 0; @@ -256,7 +256,7 @@ int apt_getpixelrow(float *pixelv, int nrow, int *zenith, int reset, apt_getsamp static int lastmshift; if (npv < PixelLine + SyncFilterLen) { - res = getpixelv(&(pixelv[npv]), PixelLine + SyncFilterLen - npv, getsample, context); + res = getpixelv(&(pixelv[npv]), PixelLine + SyncFilterLen - npv, getsamples, context); npv += res; if (npv < PixelLine + SyncFilterLen) return 0; @@ -294,7 +294,7 @@ int apt_getpixelrow(float *pixelv, int nrow, int *zenith, int reset, apt_getsamp // Get the rest of this row if (npv < PixelLine) { - res = getpixelv(&(pixelv[npv]), PixelLine - npv, getsample, context); + res = getpixelv(&(pixelv[npv]), PixelLine - npv, getsamples, context); npv += res; if (npv < PixelLine) return 0; diff --git a/src/main.c b/src/main.c index 46e5bdc..3b9ea07 100644 --- a/src/main.c +++ b/src/main.c @@ -46,7 +46,7 @@ int channels = 1; // Function declarations static int initsnd(char *filename); -int getsample(void *context, float *sample, int nb); +int getsamples(void *context, float *samples, int nb); static int processAudio(char *filename, options_t *opts); #ifdef _MSC_VER @@ -165,7 +165,7 @@ static int processAudio(char *filename, options_t *opts){ img.prow[img.nrow] = (float *) malloc(sizeof(float) * 2150); // 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), getsample, 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], IMG_WIDTH); @@ -299,17 +299,17 @@ static int initsnd(char *filename) { } // Read samples from the audio file -int getsample(void *context, float *sample, int nb) { +int getsamples(void *context, float *samples, int nb) { if(channels == 1){ - return (int)sf_read_float(audioFile, sample, nb); + return (int)sf_read_float(audioFile, samples, nb); }else{ /* Multi channel audio is encoded such as: * Ch1,Ch2,Ch1,Ch2,Ch1,Ch2 */ float *buf = malloc(sizeof(float) * nb * channels); // Something like BLKIN*2 could also be used - int samples = (int)sf_read_float(audioFile, buf, nb * channels); - for(int i = 0; i < nb; i++) sample[i] = buf[i * channels]; + int samplesRead = (int)sf_read_float(audioFile, buf, nb * channels); + for(int i = 0; i < nb; i++) samples[i] = buf[i * channels]; free(buf); - return samples / channels; + return samplesRead / channels; } }