Browse Source

Rename apt_getsample to apt_getsamples, as it gets more than one sample.

tags/v1.8.0
Jon Beniston 3 years ago
parent
commit
3141493ae6
3 changed files with 17 additions and 17 deletions
  1. +2
    -2
      src/apt.h
  2. +8
    -8
      src/dsp.c
  3. +7
    -7
      src/main.c

+ 2
- 2
src/apt.h View File

@@ -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);


+ 8
- 8
src/dsp.c View File

@@ -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;


+ 7
- 7
src/main.c View File

@@ -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;
}
}

Loading…
Cancel
Save