浏览代码

Add context pointer to getsample callback

tags/v1.8.0
Jon Beniston 3 年前
父节点
当前提交
23d7870102
共有 3 个文件被更改,包括 15 次插入14 次删除
  1. +4
    -3
      src/apt.h
  2. +8
    -8
      src/dsp.c
  3. +3
    -3
      src/main.c

+ 4
- 3
src/apt.h 查看文件

@@ -42,8 +42,9 @@ extern "C" {
// Maximum height of an APT image in number of scanlines
#define APT_MAX_HEIGHT 3000

// apt_getpixelrow callback function to get audio samples
typedef int (*apt_getsample_t)(float *samples, int count);
// 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 struct {
float *prow[APT_MAX_HEIGHT]; // Row buffers
@@ -59,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);
int APT_API apt_getpixelrow(float *pixelv, int nrow, int *zenith, int reset, apt_getsample_t getsample, 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 查看文件

@@ -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) {
static int getamp(double *ampbuff, int count, apt_getsample_t getsample, 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) {
idxin = 0;

// Read some samples
res = getsample(&(inbuff[nin]), BLKIN - nin);
res = getsample(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) {
}

// Sub-pixel offsetting + FIR compensation
int getpixelv(float *pvbuff, int count, apt_getsample_t getsample) {
int getpixelv(float *pvbuff, int count, apt_getsample_t getsample, 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) {
int res;
memmove(ampbuff, &(ampbuff[idxam]), nam * sizeof(double));
idxam = 0;
res = getamp(&(ampbuff[nam]), BLKAMP - nam, getsample);
res = getamp(&(ampbuff[nam]), BLKAMP - nam, getsample, context);
nam += res;
if (nam < m)
return n;
@@ -207,7 +207,7 @@ int getpixelv(float *pvbuff, int count, apt_getsample_t getsample) {
}

// 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) {
int apt_getpixelrow(float *pixelv, int nrow, int *zenith, int reset, apt_getsample_t getsample, 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);
res = getpixelv(&(pixelv[npv]), SyncFilterLen + 2 - npv, getsample, 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);
res = getpixelv(&(pixelv[npv]), PixelLine + SyncFilterLen - npv, getsample, 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);
res = getpixelv(&(pixelv[npv]), PixelLine - npv, getsample, context);
npv += res;
if (npv < PixelLine)
return 0;


+ 3
- 3
src/main.c 查看文件

@@ -46,7 +46,7 @@ int channels = 1;

// Function declarations
static int initsnd(char *filename);
int getsample(float *sample, int nb);
int getsample(void *context, float *sample, 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) == 0)
if (apt_getpixelrow(img.prow[img.nrow], img.nrow, &img.zenith, (img.nrow == 0), getsample, NULL) == 0)
break;

if(opts->realtime) pushRow(img.prow[img.nrow], IMG_WIDTH);
@@ -299,7 +299,7 @@ static int initsnd(char *filename) {
}

// Read samples from the audio file
int getsample(float *sample, int nb) {
int getsample(void *context, float *sample, int nb) {
if(channels == 1){
return (int)sf_read_float(audioFile, sample, nb);
}else{


正在加载...
取消
保存