diff options
Diffstat (limited to 'audio')
-rw-r--r-- | audio/filter/af_center.c | 12 | ||||
-rw-r--r-- | audio/filter/af_channels.c | 34 | ||||
-rw-r--r-- | audio/filter/af_delay.c | 46 | ||||
-rw-r--r-- | audio/filter/af_drc.c | 36 | ||||
-rw-r--r-- | audio/filter/af_dummy.c | 2 | ||||
-rw-r--r-- | audio/filter/af_equalizer.c | 86 | ||||
-rw-r--r-- | audio/filter/af_export.c | 44 | ||||
-rw-r--r-- | audio/filter/af_extrastereo.c | 12 | ||||
-rw-r--r-- | audio/filter/af_hrtf.c | 452 | ||||
-rw-r--r-- | audio/filter/af_hrtf.h | 50 | ||||
-rw-r--r-- | audio/filter/af_karaoke.c | 56 | ||||
-rw-r--r-- | audio/filter/af_pan.c | 20 | ||||
-rw-r--r-- | audio/filter/af_sinesuppress.c | 16 | ||||
-rw-r--r-- | audio/filter/af_sub.c | 30 | ||||
-rw-r--r-- | audio/filter/af_surround.c | 36 | ||||
-rw-r--r-- | audio/filter/dsp.h | 4 | ||||
-rw-r--r-- | audio/filter/equalizer.h | 26 | ||||
-rw-r--r-- | audio/filter/filter.c | 72 | ||||
-rw-r--r-- | audio/filter/filter.h | 2 | ||||
-rw-r--r-- | audio/filter/tools.c | 6 | ||||
-rw-r--r-- | audio/filter/window.c | 6 |
21 files changed, 524 insertions, 524 deletions
diff --git a/audio/filter/af_center.c b/audio/filter/af_center.c index 2e626bffb6..106e08412e 100644 --- a/audio/filter/af_center.c +++ b/audio/filter/af_center.c @@ -35,7 +35,7 @@ // Data for specific instances of this filter typedef struct af_center_s { - int ch; // Channel number which to insert the filtered data + int ch; // Channel number which to insert the filtered data }af_center_t; // Initialization and runtime control @@ -61,12 +61,12 @@ static int control(struct af_instance* af, int cmd, void* arg) // Filter data through filter static int filter(struct af_instance* af, struct mp_audio* data, int flags) { - struct mp_audio* c = data; // Current working data + struct mp_audio* c = data; // Current working data af_center_t* s = af->priv; // Setup for this instance - float* a = c->planes[0]; // Audio data - int nch = c->nch; // Number of channels - int len = c->samples*c->nch; // Number of samples in current audio block - int ch = s->ch; // Channel in which to insert the center audio + float* a = c->planes[0]; // Audio data + int nch = c->nch; // Number of channels + int len = c->samples*c->nch; // Number of samples in current audio block + int ch = s->ch; // Channel in which to insert the center audio register int i; // Run filter diff --git a/audio/filter/af_channels.c b/audio/filter/af_channels.c index 6db44ba024..118607b66f 100644 --- a/audio/filter/af_channels.c +++ b/audio/filter/af_channels.c @@ -114,7 +114,7 @@ static void copy(struct af_instance *af, void* in, void* out, } default: MP_ERR(af, "Unsupported number of bytes/sample: %i" - " please report this error on the MPlayer mailing list. \n",bps); + " please report this error on the MPlayer mailing list. \n",bps); } } @@ -125,7 +125,7 @@ static int check_routes(struct af_instance *af, int nin, int nout) int i; if((s->nr < 1) || (s->nr > AF_NCH)){ MP_ERR(af, "The number of routing pairs must be" - " between 1 and %i. Current value is %i\n",AF_NCH,s->nr); + " between 1 and %i. Current value is %i\n",AF_NCH,s->nr); return AF_ERROR; } @@ -154,22 +154,22 @@ static int control(struct af_instance* af, int cmd, void* arg) int i; // Make sure this filter isn't redundant if(af->data->nch == ((struct mp_audio*)arg)->nch) - return AF_DETACH; + return AF_DETACH; // If mono: fake stereo if(((struct mp_audio*)arg)->nch == 1){ - s->nr = MPMIN(af->data->nch,2); - for(i=0;i<s->nr;i++){ - s->route[i][FR] = 0; - s->route[i][TO] = i; - } + s->nr = MPMIN(af->data->nch,2); + for(i=0;i<s->nr;i++){ + s->route[i][FR] = 0; + s->route[i][TO] = i; + } } else{ - s->nr = MPMIN(af->data->nch, ((struct mp_audio*)arg)->nch); - for(i=0;i<s->nr;i++){ - s->route[i][FR] = i; - s->route[i][TO] = i; - } + s->nr = MPMIN(af->data->nch, ((struct mp_audio*)arg)->nch); + for(i=0;i<s->nr;i++){ + s->route[i][FR] = i; + s->route[i][TO] = i; + } } } @@ -184,10 +184,10 @@ static int control(struct af_instance* af, int cmd, void* arg) // Filter data through filter static int filter(struct af_instance* af, struct mp_audio* data, int flags) { - struct mp_audio* c = data; // Current working data - struct mp_audio* l = af->data; // Local data + struct mp_audio* c = data; // Current working data + struct mp_audio* l = af->data; // Local data af_channels_t* s = af->priv; - int i; + int i; mp_audio_realloc_min(af->data, data->samples); @@ -197,7 +197,7 @@ static int filter(struct af_instance* af, struct mp_audio* data, int flags) if(AF_OK == check_routes(af,c->nch,l->nch)) for(i=0;i<s->nr;i++) copy(af, c->planes[0],l->planes[0],c->nch,s->route[i][FR], - l->nch,s->route[i][TO],mp_audio_psize(c),c->bps); + l->nch,s->route[i][TO],mp_audio_psize(c),c->bps); // Set output data c->planes[0] = l->planes[0]; diff --git a/audio/filter/af_delay.c b/audio/filter/af_delay.c index a8cd79f117..b16cdc1f63 100644 --- a/audio/filter/af_delay.c +++ b/audio/filter/af_delay.c @@ -37,10 +37,10 @@ // Data for specific instances of this filter typedef struct af_delay_s { - void* q[AF_NCH]; // Circular queues used for delaying audio signal - int wi[AF_NCH]; // Write index - int ri; // Read index - float d[AF_NCH]; // Delay [ms] + void* q[AF_NCH]; // Circular queues used for delaying audio signal + int wi[AF_NCH]; // Write index + int ri; // Read index + float d[AF_NCH]; // Delay [ms] char *delaystr; }af_delay_t; @@ -69,7 +69,7 @@ static int control(struct af_instance* af, int cmd, void* arg) for(i=0;i<af->data->nch;i++){ s->q[i] = calloc(L,af->data->bps); if(NULL == s->q[i]) - MP_FATAL(af, "Out of memory\n"); + MP_FATAL(af, "Out of memory\n"); } if(AF_OK != af_from_ms(AF_NCH, s->d, s->wi, af->data->rate, 0.0, 1000.0)) @@ -99,12 +99,12 @@ static void uninit(struct af_instance* af) // Filter data through filter static int filter(struct af_instance* af, struct mp_audio* data, int flags) { - struct mp_audio* c = data; // Current working data - af_delay_t* s = af->priv; // Setup for this instance - int nch = c->nch; // Number of channels - int len = mp_audio_psize(c)/c->bps; // Number of sample in data chunk - int ri = 0; - int ch,i; + struct mp_audio* c = data; // Current working data + af_delay_t* s = af->priv; // Setup for this instance + int nch = c->nch; // Number of channels + int len = mp_audio_psize(c)/c->bps; // Number of sample in data chunk + int ri = 0; + int ch,i; for(ch=0;ch<nch;ch++){ switch(c->bps){ case 1:{ @@ -113,10 +113,10 @@ static int filter(struct af_instance* af, struct mp_audio* data, int flags) int wi = s->wi[ch]; ri = s->ri; for(i=ch;i<len;i+=nch){ - q[wi] = a[i]; - a[i] = q[ri]; - UPDATEQI(wi); - UPDATEQI(ri); + q[wi] = a[i]; + a[i] = q[ri]; + UPDATEQI(wi); + UPDATEQI(ri); } s->wi[ch] = wi; break; @@ -127,10 +127,10 @@ static int filter(struct af_instance* af, struct mp_audio* data, int flags) int wi = s->wi[ch]; ri = s->ri; for(i=ch;i<len;i+=nch){ - q[wi] = a[i]; - a[i] = q[ri]; - UPDATEQI(wi); - UPDATEQI(ri); + q[wi] = a[i]; + a[i] = q[ri]; + UPDATEQI(wi); + UPDATEQI(ri); } s->wi[ch] = wi; break; @@ -141,10 +141,10 @@ static int filter(struct af_instance* af, struct mp_audio* data, int flags) int wi = s->wi[ch]; ri = s->ri; for(i=ch;i<len;i+=nch){ - q[wi] = a[i]; - a[i] = q[ri]; - UPDATEQI(wi); - UPDATEQI(ri); + q[wi] = a[i]; + a[i] = q[ri]; + UPDATEQI(wi); + UPDATEQI(ri); } s->wi[ch] = wi; break; diff --git a/audio/filter/af_drc.c b/audio/filter/af_drc.c index fad34ba500..3bcd368d4d 100644 --- a/audio/filter/af_drc.c +++ b/audio/filter/af_drc.c @@ -70,8 +70,8 @@ typedef struct af_volume_s // method 2 int idx; struct { - float avg; // average level of the sample - int len; // sample size (weight) + float avg; // average level of the sample + int len; // sample size (weight) } mem[NSAMPLES]; // "Ideal" level float mid_s16; @@ -100,8 +100,8 @@ static int control(struct af_instance* af, int cmd, void* arg) static void method1_int16(af_drc_t *s, struct mp_audio *c) { register int i = 0; - int16_t *data = (int16_t*)c->planes[0]; // Audio data - int len = c->samples*c->nch; // Number of samples + int16_t *data = (int16_t*)c->planes[0]; // Audio data + int len = c->samples*c->nch; // Number of samples float curavg = 0.0, newavg, neededmul; int tmp; @@ -142,8 +142,8 @@ static void method1_int16(af_drc_t *s, struct mp_audio *c) static void method1_float(af_drc_t *s, struct mp_audio *c) { register int i = 0; - float *data = (float*)c->planes[0]; // Audio data - int len = c->samples*c->nch; // Number of samples + float *data = (float*)c->planes[0]; // Audio data + int len = c->samples*c->nch; // Number of samples float curavg = 0.0, newavg, neededmul, tmp; for (i = 0; i < len; i++) @@ -179,8 +179,8 @@ static void method1_float(af_drc_t *s, struct mp_audio *c) static void method2_int16(af_drc_t *s, struct mp_audio *c) { register int i = 0; - int16_t *data = (int16_t*)c->planes[0]; // Audio data - int len = c->samples*c->nch; // Number of samples + int16_t *data = (int16_t*)c->planes[0]; // Audio data + int len = c->samples*c->nch; // Number of samples float curavg = 0.0, newavg, avg = 0.0; int tmp, totallen = 0; @@ -204,8 +204,8 @@ static void method2_int16(af_drc_t *s, struct mp_audio *c) avg /= (float)totallen; if (avg >= SIL_S16) { - s->mul = s->mid_s16 / avg; - s->mul = MPCLAMP(s->mul, MUL_MIN, MUL_MAX); + s->mul = s->mid_s16 / avg; + s->mul = MPCLAMP(s->mul, MUL_MIN, MUL_MAX); } } @@ -229,8 +229,8 @@ static void method2_int16(af_drc_t *s, struct mp_audio *c) static void method2_float(af_drc_t *s, struct mp_audio *c) { register int i = 0; - float *data = (float*)c->planes[0]; // Audio data - int len = c->samples*c->nch; // Number of samples + float *data = (float*)c->planes[0]; // Audio data + int len = c->samples*c->nch; // Number of samples float curavg = 0.0, newavg, avg = 0.0, tmp; int totallen = 0; @@ -254,8 +254,8 @@ static void method2_float(af_drc_t *s, struct mp_audio *c) avg /= (float)totallen; if (avg >= SIL_FLOAT) { - s->mul = s->mid_float / avg; - s->mul = MPCLAMP(s->mul, MUL_MIN, MUL_MAX); + s->mul = s->mid_float / avg; + s->mul = MPCLAMP(s->mul, MUL_MIN, MUL_MAX); } } @@ -279,16 +279,16 @@ static int filter(struct af_instance* af, struct mp_audio* data, int flags) if(af->data->format == (AF_FORMAT_S16)) { if (s->method == 2) - method2_int16(s, data); + method2_int16(s, data); else - method1_int16(s, data); + method1_int16(s, data); } else if(af->data->format == (AF_FORMAT_FLOAT)) { if (s->method == 2) - method2_float(s, data); + method2_float(s, data); else - method1_float(s, data); + method1_float(s, data); } return 0; } diff --git a/audio/filter/af_dummy.c b/audio/filter/af_dummy.c index c13c32b968..d920480e01 100644 --- a/audio/filter/af_dummy.c +++ b/audio/filter/af_dummy.c @@ -34,7 +34,7 @@ static int control(struct af_instance* af, int cmd, void* arg) case AF_CONTROL_REINIT: ; *af->data = *(struct mp_audio*)arg; MP_VERBOSE(af, "Was reinitialized: %iHz/%ich/%s\n", - af->data->rate,af->data->nch,af_fmt_to_str(af->data->format)); + af->data->rate,af->data->nch,af_fmt_to_str(af->data->format)); return AF_OK; } return AF_UNKNOWN; diff --git a/audio/filter/af_equalizer.c b/audio/filter/af_equalizer.c index 4f5a29706e..83fa80f2b3 100644 --- a/audio/filter/af_equalizer.c +++ b/audio/filter/af_equalizer.c @@ -32,41 +32,41 @@ #include "common/common.h" #include "af.h" -#define L 2 // Storage for filter taps -#define KM 10 // Max number of bands +#define L 2 // Storage for filter taps +#define KM 10 // Max number of bands #define Q 1.2247449 /* Q value for band-pass filters 1.2247=(3/2)^(1/2) - gives 4dB suppression @ Fc*2 and Fc/2 */ + gives 4dB suppression @ Fc*2 and Fc/2 */ /* Center frequencies for band-pass filters The different frequency bands are: - nr. center frequency - 0 31.25 Hz - 1 62.50 Hz - 2 125.0 Hz - 3 250.0 Hz - 4 500.0 Hz - 5 1.000 kHz - 6 2.000 kHz - 7 4.000 kHz - 8 8.000 kHz - 9 16.00 kHz + nr. center frequency + 0 31.25 Hz + 1 62.50 Hz + 2 125.0 Hz + 3 250.0 Hz + 4 500.0 Hz + 5 1.000 kHz + 6 2.000 kHz + 7 4.000 kHz + 8 8.000 kHz + 9 16.00 kHz */ -#define CF {31.25,62.5,125,250,500,1000,2000,4000,8000,16000} +#define CF {31.25,62.5,125,250,500,1000,2000,4000,8000,16000} // Maximum and minimum gain for the bands -#define G_MAX +12.0 -#define G_MIN -12.0 +#define G_MAX +12.0 +#define G_MIN -12.0 // Data for specific instances of this filter typedef struct af_equalizer_s { - float a[KM][L]; // A weights - float b[KM][L]; // B weights - float wq[AF_NCH][KM][L]; // Circular buffer for W data - float g[AF_NCH][KM]; // Gain factor for each channel and band - int K; // Number of used eq bands - int channels; // Number of channels + float a[KM][L]; // A weights + float b[KM][L]; // B weights + float wq[AF_NCH][KM][L]; // Circular buffer for W data + float g[AF_NCH][KM]; // Gain factor for each channel and band + int K; // Number of used eq bands + int channels; // Number of channels float gain_factor; // applied at output to avoid clipping double p[KM]; } af_equalizer_t; @@ -108,7 +108,7 @@ static int control(struct af_instance* af, int cmd, void* arg) if(s->K != KM) MP_INFO(af, "Limiting the number of filters to" - " %i due to low sample rate.\n",s->K); + " %i due to low sample rate.\n",s->K); // Generate filter taps for(k=0;k<s->K;k++) @@ -144,33 +144,33 @@ static int control(struct af_instance* af, int cmd, void* arg) // Filter data through filter static int filter(struct af_instance* af, struct mp_audio* data, int flags) { - struct mp_audio* c = data; // Current working data - af_equalizer_t* s = (af_equalizer_t*)af->priv; // Setup - uint32_t ci = af->data->nch; // Index for channels - uint32_t nch = af->data->nch; // Number of channels + struct mp_audio* c = data; // Current working data + af_equalizer_t* s = (af_equalizer_t*)af->priv; // Setup + uint32_t ci = af->data->nch; // Index for channels + uint32_t nch = af->data->nch; // Number of channels while(ci--){ - float* g = s->g[ci]; // Gain factor - float* in = ((float*)c->planes[0])+ci; - float* out = ((float*)c->planes[0])+ci; - float* end = in + c->samples*c->nch; // Block loop end + float* g = s->g[ci]; // Gain factor + float* in = ((float*)c->planes[0])+ci; + float* out = ((float*)c->planes[0])+ci; + float* end = in + c->samples*c->nch; // Block loop end while(in < end){ - register int k = 0; // Frequency band index - register float yt = *in; // Current input sample + register int k = 0; // Frequency band index + register float yt = *in; // Current input sample in+=nch; // Run the filters for(;k<s->K;k++){ - // Pointer to circular buffer wq - register float* wq = s->wq[ci][k]; - // Calculate output from AR part of current filter - register float w=yt*s->b[k][0] + wq[0]*s->a[k][0] + wq[1]*s->a[k][1]; - // Calculate output form MA part of current filter - yt+=(w + wq[1]*s->b[k][1])*g[k]; - // Update circular buffer - wq[1] = wq[0]; - wq[0] = w; + // Pointer to circular buffer wq + register float* wq = s->wq[ci][k]; + // Calculate output from AR part of current filter + register float w=yt*s->b[k][0] + wq[0]*s->a[k][0] + wq[1]*s->a[k][1]; + // Calculate output form MA part of current filter + yt+=(w + wq[1]*s->b[k][1])*g[k]; + // Update circular buffer + wq[1] = wq[0]; + wq[0] = w; } // Calculate output *out=yt*s->gain_factor; diff --git a/audio/filter/af_export.c b/audio/filter/af_export.c index 542b2a1f9f..faa09bf927 100644 --- a/audio/filter/af_export.c +++ b/audio/filter/af_export.c @@ -47,7 +47,7 @@ #define DEF_SZ 512 // default buffer size (in samples) #define SHARED_FILE "mpv-af_export" /* default file name - (relative to ~/.mpv/ */ + (relative to ~/.mpv/ */ #define SIZE_HEADER (2 * sizeof(int) + sizeof(unsigned long long)) @@ -55,12 +55,12 @@ typedef struct af_export_s { unsigned long long count; // Used for sync - void* buf[AF_NCH]; // Buffers for storing the data before it is exported - int sz; // Size of buffer in samples - int wi; // Write index - int fd; // File descriptor to shared memory area - char* filename; // File to export data - uint8_t *mmap_area; // MMap shared area + void* buf[AF_NCH]; // Buffers for storing the data before it is exported + int sz; // Size of buffer in samples + int wi; // Write index + int fd; // File descriptor to shared memory area + char* filename; // File to export data + uint8_t *mmap_area; // MMap shared area } af_export_t; @@ -109,7 +109,7 @@ static int control(struct af_instance* af, int cmd, void* arg) MP_INFO(af, "Exporting to file: %s\n", s->filename); if(s->fd < 0) { MP_FATAL(af, "Could not open/create file: %s\n", - s->filename); + s->filename); return AF_ERROR; } @@ -127,7 +127,7 @@ static int control(struct af_instance* af, int cmd, void* arg) if(s->mmap_area == NULL) MP_FATAL(af, "Could not mmap file %s\n", s->filename); MP_INFO(af, "Memory mapped to file: %s (%p)\n", - s->filename, s->mmap_area); + s->filename, s->mmap_area); // Initialize header *((int*)s->mmap_area) = af->data->nch; @@ -164,27 +164,27 @@ static void uninit( struct af_instance* af ) */ static int filter( struct af_instance* af, struct mp_audio* data, int flags) { - struct mp_audio* c = data; // Current working data - af_export_t* s = af->priv; // Setup for this instance - int16_t* a = c->planes[0]; // Incomming sound - int nch = c->nch; // Number of channels - int len = c->samples*c->nch; // Number of sample in data chunk - int sz = s->sz; // buffer size (in samples) - int flag = 0; // Set to 1 if buffer is filled + struct mp_audio* c = data; // Current working data + af_export_t* s = af->priv; // Setup for this instance + int16_t* a = c->planes[0]; // Incomming sound + int nch = c->nch; // Number of channels + int len = c->samples*c->nch; // Number of sample in data chunk + int sz = s->sz; // buffer size (in samples) + int flag = 0; // Set to 1 if buffer is filled - int ch, i; + int ch, i; // Fill all buffers for(ch = 0; ch < nch; ch++){ - int wi = s->wi; // Reset write index - int16_t* b = s->buf[ch]; // Current buffer + int wi = s->wi; // Reset write index + int16_t* b = s->buf[ch]; // Current buffer // Copy data to export buffers for(i = ch; i < len; i += nch){ b[wi++] = a[i]; if(wi >= sz){ // Don't write outside the end of the buffer - flag = 1; - break; + flag = 1; + break; } } s->wi = wi % s->sz; @@ -196,7 +196,7 @@ static int filter( struct af_instance* af, struct mp_audio* data, int flags) memcpy(s->mmap_area + SIZE_HEADER, s->buf[0], sz * c->bps * nch); s->count++; // increment counter (to sync) memcpy(s->mmap_area + SIZE_HEADER - sizeof(s->count), - &(s->count), sizeof(s->count)); + &(s->count), sizeof(s->count)); } return 0; diff --git a/audio/filter/af_extrastereo.c b/audio/filter/af_extrastereo.c index 1e814e8351..05a1ac8e36 100644 --- a/audio/filter/af_extrastereo.c +++ b/audio/filter/af_extrastereo.c @@ -51,11 +51,11 @@ static int control(struct af_instance* af, int cmd, void* arg) mp_audio_set_num_channels(af->data, 2); if (af->data->format == AF_FORMAT_FLOAT) { - af->filter = play_float; + af->filter = play_float; }// else { mp_audio_set_format(af->data, AF_FORMAT_S16); - af->filter = play_s16; + af->filter = play_s16; } return af_test_output(af,(struct mp_audio*)arg); @@ -69,8 +69,8 @@ static int play_s16(struct af_instance* af, struct mp_audio* data, int f) { af_extrastereo_t *s = af->priv; register int i = 0; - int16_t *a = (int16_t*)data->planes[0]; // Audio data - int len = data->samples*data->nch; // Number of samples + int16_t *a = (int16_t*)data->planes[0]; // Audio data + int len = data->samples*data->nch; // Number of samples int avg, l, r; for (i = 0; i < len; i+=2) @@ -91,8 +91,8 @@ static int play_float(struct af_instance* af, struct mp_audio* data, int f) { af_extrastereo_t *s = af->priv; register int i = 0; - float *a = (float*)data->planes[0]; // Audio data - int len = data->samples * data->nch; // Number of samples + float *a = (float*)data->planes[0]; // Audio data + int len = data->samples * data->nch; // Number of samples float avg, l, r; for (i = 0; i < len; i+=2) diff --git a/audio/filter/af_hrtf.c b/audio/filter/af_hrtf.c index e329b4e558..e8ab5fc72d 100644 --- a/audio/filter/af_hrtf.c +++ b/audio/filter/af_hrtf.c @@ -75,23 +75,23 @@ typedef struct af_hrtf_s { } af_hrtf_t; /* Convolution on a ring buffer - * nx: length of the ring buffer - * nk: length of the convolution kernel - * sx: ring buffer - * sk: convolution kernel - * offset: offset on the ring buffer, can be + * nx: length of the ring buffer + * nk: length of the convolution kernel + * sx: ring buffer + * sk: convolution kernel + * offset: offset on the ring buffer, can be */ static float conv(const int nx, const int nk, const float *sx, const float *sk, - const int offset) + const int offset) { /* k = reminder of offset / nx */ int k = offset >= 0 ? offset % nx : nx + (offset % nx); if(nk + k <= nx) - return af_filter_fir(nk, sx + k, sk); + return af_filter_fir(nk, sx + k, sk); else - return af_filter_fir(nk + k - nx, sx, sk + nx - k) + - af_filter_fir(nx - k, sx + k, sk); + return af_filter_fir(nk + k - nx, sx, sk + nx - k) + + af_filter_fir(nx - k, sx + k, sk); } /* Detect when the impulse response starts (significantly) */ @@ -104,8 +104,8 @@ static int pulse_detect(const float *sx) int i; for(i = 0; i < nmax; i++) - if(fabs(sx[i]) > thresh) - return i; + if(fabs(sx[i]) > thresh) + return i; return 0; } @@ -122,14 +122,14 @@ static inline float passive_lock(float x) /* Unified active matrix decoder for 2 channel matrix encoded surround sources */ static inline void matrix_decode(short *in, const int k, const int il, - const int ir, const int decode_rear, - const int dlbuflen, - float l_fwr, float r_fwr, - float lpr_fwr, float lmr_fwr, - float *adapt_l_gain, float *adapt_r_gain, - float *adapt_lpr_gain, float *adapt_lmr_gain, - float *lf, float *rf, float *lr, - float *rr, float *cf) + const int ir, const int decode_rear, + const int dlbuflen, + float l_fwr, float r_fwr, + float lpr_fwr, float lmr_fwr, + float *adapt_l_gain, float *adapt_r_gain, + float *adapt_lpr_gain, float *adapt_lmr_gain, + float *lf, float *rf, float *lr, + float *rr, float *cf) { const int kr = (k + MATREARDELAY) % dlbuflen; float l_gain = (l_fwr + r_fwr) / @@ -161,13 +161,13 @@ static inline void matrix_decode(short *in, const int k, const int il, fp_out = fopen("af_hrtf.log", "w"); if(counter % 240 == 0) fprintf(fp_out, "%g %g %g %g %g ", counter * (1.0 / 48000), - l_gain, r_gain, lpr_gain, lmr_gain); + l_gain, r_gain, lpr_gain, lmr_gain); #endif /*** AXIS NO. 1: (Lt, Rt) -> (C, Ls, Rs) ***/ /* AGC adaption */ d_gain = (fabs(l_gain - *adapt_l_gain) + - fabs(r_gain - *adapt_r_gain)) * 0.5; + fabs(r_gain - *adapt_r_gain)) * 0.5; f = d_gain * (1.0 / MATAGCTRIG); f = MATAGCDECAY - MATAGCDECAY / (1 + f * f); *adapt_l_gain = (1 - f) * *adapt_l_gain + f * l_gain; @@ -179,12 +179,12 @@ static inline void matrix_decode(short *in, const int k, const int il, if(decode_rear) { lr[kr] = rr[kr] = (l_agc - r_agc) * M_SQRT1_2; /* Stereo rear channel is steered with the same AGC steering as - the decoding matrix. Note this requires a fast updating AGC - at the order of 20 ms (which is the case here). */ + the decoding matrix. Note this requires a fast updating AGC + at the order of 20 ms (which is the case here). */ lr[kr] *= (l_fwr + l_fwr) / - (1 + l_fwr + r_fwr); + (1 + l_fwr + r_fwr); rr[kr] *= (r_fwr + r_fwr) / - (1 + l_fwr + r_fwr); + (1 + l_fwr + r_fwr); } /*** AXIS NO. 2: (Lt + Rt, Lt - Rt) -> (L, R) ***/ @@ -221,9 +221,9 @@ static inline void matrix_decode(short *in, const int k, const int il, #if 0 if(counter % 240 == 0) fprintf(fp_out, "%g %g %g %g %g\n", - *adapt_l_gain, *adapt_r_gain, - *adapt_lpr_gain, *adapt_lmr_gain, - c_gain); + *adapt_l_gain, *adapt_r_gain, + *adapt_lpr_gain, *adapt_lmr_gain, + c_gain); counter++; #endif } @@ -237,18 +237,18 @@ static inline void update_ch(af_hrtf_t *s, short *in, const int k) s->l_fwr += abs(in[0]) - fabs(s->fwrbuf_l[fwr_pos]); s->r_fwr += abs(in[1]) - fabs(s->fwrbuf_r[fwr_pos]); s->lpr_fwr += abs(in[0] + in[1]) - - fabs(s->fwrbuf_l[fwr_pos] + s->fwrbuf_r[fwr_pos]); + fabs(s->fwrbuf_l[fwr_pos] + s->fwrbuf_r[fwr_pos]); s->lmr_fwr += abs(in[0] - in[1]) - - fabs(s->fwrbuf_l[fwr_pos] - s->fwrbuf_r[fwr_pos]); + fabs(s->fwrbuf_l[fwr_pos] - s->fwrbuf_r[fwr_pos]); } /* Rear matrix decoder */ if(s->matrix_mode) { s->lr_fwr += abs(in[2]) - fabs(s->fwrbuf_lr[fwr_pos]); s->rr_fwr += abs(in[3]) - fabs(s->fwrbuf_rr[fwr_pos]); s->lrprr_fwr += abs(in[2] + in[3]) - - fabs(s->fwrbuf_lr[fwr_pos] + s->fwrbuf_rr[fwr_pos]); + fabs(s->fwrbuf_lr[fwr_pos] + s->fwrbuf_rr[fwr_pos]); s->lrmrr_fwr += abs(in[2] - in[3]) - - fabs(s->fwrbuf_lr[fwr_pos] - s->fwrbuf_rr[fwr_pos]); + fabs(s->fwrbuf_lr[fwr_pos] - s->fwrbuf_rr[fwr_pos]); } switch (s->decode_mode) { @@ -265,11 +265,11 @@ static inline void update_ch(af_hrtf_t *s, short *in, const int k) s->fwrbuf_l[k] = in[0]; s->fwrbuf_r[k] = in[1]; matrix_decode(in, k, 0, 1, 1, s->dlbuflen, - s->l_fwr, s->r_fwr, - s->lpr_fwr, s->lmr_fwr, - &(s->adapt_l_gain), &(s->adapt_r_gain), - &(s->adapt_lpr_gain), &(s->adapt_lmr_gain), - s->lf, s->rf, s->lr, s->rr, s->cf); + s->l_fwr, s->r_fwr, + s->lpr_fwr, s->lmr_fwr, + &(s->adapt_l_gain), &(s->adapt_r_gain), + &(s->adapt_lpr_gain), &(s->adapt_lmr_gain), + s->lf, s->rf, s->lr, s->rr, s->cf); break; case HRTF_MIX_STEREO: /* Stereo sources */ @@ -292,30 +292,30 @@ static int control(struct af_instance *af, int cmd, void* arg) switch(cmd) { case AF_CONTROL_REINIT: - af->data->rate = ((struct mp_audio*)arg)->rate; - if(af->data->rate != 48000) { - // automatic samplerate adjustment in the filter chain - // is not yet supported. - MP_ERR(af, "ERROR: Sampling rate is not 48000 Hz (%d)!\n", - af->data->rate); - return AF_ERROR; - } - mp_audio_set_channels_old(af->data, ((struct mp_audio*)arg)->nch); - if(af->data->nch == 2) { - /* 2 channel input */ - if(s->decode_mode != HRTF_MIX_MATRIX2CH) { - /* Default behavior is stereo mixing. */ - s->decode_mode = HRTF_MIX_STEREO; - } - } - else if (af->data->nch < 5) - mp_audio_set_channels_old(af->data, 5); + af->data->rate = ((struct mp_audio*)arg)->rate; + if(af->data->rate != 48000) { + // automatic samplerate adjustment in the filter chain + // is not yet supported. + MP_ERR(af, "ERROR: Sampling rate is not 48000 Hz (%d)!\n", + af->data->rate); + return AF_ERROR; + } + mp_audio_set_channels_old(af->data, ((struct mp_audio*)arg)->nch); + if(af->data->nch == 2) { + /* 2 channel input */ + if(s->decode_mode != HRTF_MIX_MATRIX2CH) { + /* Default behavior is stereo mixing. */ + s->decode_mode = HRTF_MIX_STEREO; + } + } + else if (af->data->nch < 5) + mp_audio_set_channels_old(af->data, 5); mp_audio_set_format(af->data, AF_FORMAT_S16); - test_output_res = af_test_output(af, (struct mp_audio*)arg); - // after testing input set the real output format + test_output_res = af_test_output(af, (struct mp_audio*)arg); + // after testing input set the real output format mp_audio_set_num_channels(af->data, 2); - s->print_flag = 1; - return test_output_res; + s->print_flag = 1; + return test_output_res; } return AF_UNKNOWN; @@ -324,21 +324,21 @@ static int control(struct af_instance *af, int cmd, void* arg) /* Deallocate memory */ static void uninit(struct af_instance *af) { - af_hrtf_t *s = af->priv; - - free(s->lf); - free(s->rf); - free(s->lr); - free(s->rr); - free(s->cf); - free(s->cr); - free(s->ba_l); - free(s->ba_r); - free(s->ba_ir); - free(s->fwrbuf_l); - free(s->fwrbuf_r); - free(s->fwrbuf_lr); - free(s->fwrbuf_rr); + af_hrtf_t *s = af->priv; + + free(s->lf); + free(s->rf); + free(s->lr); + free(s->rr); + free(s->cf); + free(s->cr); + free(s->ba_l); + free(s->ba_r); + free(s->ba_ir); + free(s->fwrbuf_l); + free(s->fwrbuf_r); + free(s->fwrbuf_lr); + free(s->fwrbuf_rr); } /* Filter data through filter @@ -364,29 +364,29 @@ static int filter(struct af_instance *af, struct mp_audio *data, int flags) mp_audio_realloc_min(af->data, data->samples); if(s->print_flag) { - s->print_flag = 0; - switch (s->decode_mode) { - case HRTF_MIX_51: - MP_INFO(af, "Using HRTF to mix %s discrete surround into " - "L, R channels\n", s->matrix_mode ? "5+1" : "5"); - break; - case HRTF_MIX_STEREO: - MP_INFO(af, "Using HRTF to mix stereo into " - "L, R channels\n"); - break; - case HRTF_MIX_MATRIX2CH: - MP_INFO(af, "Using active matrix to decode 2 channel " - "input, HRTF to mix %s matrix surround into " - "L, R channels\n", "3/2"); - break; - default: - MP_WARN(af, "bogus decode_mode: %d\n", s->decode_mode); - break; - } + s->print_flag = 0; + switch (s->decode_mode) { + case HRTF_MIX_51: + MP_INFO(af, "Using HRTF to mix %s discrete surround into " + "L, R channels\n", s->matrix_mode ? "5+1" : "5"); + break; + case HRTF_MIX_STEREO: + MP_INFO(af, "Using HRTF to mix stereo into " + "L, R channels\n"); + break; + case HRTF_MIX_MATRIX2CH: + MP_INFO(af, "Using active matrix to decode 2 channel " + "input, HRTF to mix %s matrix surround into " + "L, R channels\n", "3/2"); + break; + default: + MP_WARN(af, "bogus decode_mode: %d\n", s->decode_mode); + break; + } if(s->matrix_mode) - MP_INFO(af, "Using active matrix to decode rear center " - "channel\n"); + MP_INFO(af, "Using active matrix to decode rear center " + "channel\n"); } out = af->data->planes[0]; @@ -410,122 +410,122 @@ static int filter(struct af_instance *af, struct mp_audio *data, int flags) */ while(in < end) { - const int k = s->cyc_pos; - - update_ch(s, in, k); - - /* Simulate a 7.5 ms -20 dB echo of the center channel in the - front channels (like reflection from a room wall) - a kind of - psycho-acoustically "cheating" to focus the center front - channel, which is normally hard to be perceived as front */ - s->lf[k] += CFECHOAMPL * s->cf[(k + CFECHODELAY) % s->dlbuflen]; - s->rf[k] += CFECHOAMPL * s->cf[(k + CFECHODELAY) % s->dlbuflen]; - - switch (s->decode_mode) { - case HRTF_MIX_51: - case HRTF_MIX_MATRIX2CH: - /* Mixer filter matrix */ - common = conv(dblen, hlen, s->cf, s->cf_ir, k + s->cf_o); - if(s->matrix_mode) { - /* In matrix decoding mode, the rear channel gain must be - renormalized, as there is an additional channel. */ - matrix_decode(in, k, 2, 3, 0, s->dlbuflen, - s->lr_fwr, s->rr_fwr, - s->lrprr_fwr, s->lrmrr_fwr, - &(s->adapt_lr_gain), &(s->adapt_rr_gain), - &(s->adapt_lrprr_gain), &(s->adapt_lrmrr_gain), - s->lr, s->rr, NULL, NULL, s->cr); - common += - conv(dblen, hlen, s->cr, s->cr_ir, k + s->cr_o) * - M1_76DB; - left = - ( conv(dblen, hlen, s->lf, s->af_ir, k + s->af_o) + - conv(dblen, hlen, s->rf, s->of_ir, k + s->of_o) + - (conv(dblen, hlen, s->lr, s->ar_ir, k + s->ar_o) + - conv(dblen, hlen, s->rr, s->or_ir, k + s->or_o)) * - M1_76DB + common); - right = - ( conv(dblen, hlen, s->rf, s->af_ir, k + s->af_o) + - conv(dblen, hlen, s->lf, s->of_ir, k + s->of_o) + - (conv(dblen, hlen, s->rr, s->ar_ir, k + s->ar_o) + - conv(dblen, hlen, s->lr, s->or_ir, k + s->or_o)) * - M1_76DB + common); - } else { - left = - ( conv(dblen, hlen, s->lf, s->af_ir, k + s->af_o) + - conv(dblen, hlen, s->rf, s->of_ir, k + s->of_o) + - conv(dblen, hlen, s->lr, s->ar_ir, k + s->ar_o) + - conv(dblen, hlen, s->rr, s->or_ir, k + s->or_o) + - common); - right = - ( conv(dblen, hlen, s->rf, s->af_ir, k + s->af_o) + - conv(dblen, hlen, s->lf, s->of_ir, k + s->of_o) + - conv(dblen, hlen, s->rr, s->ar_ir, k + s->ar_o) + - conv(dblen, hlen, s->lr, s->or_ir, k + s->or_o) + - common); - } - break; - case HRTF_MIX_STEREO: - left = - ( conv(dblen, hlen, s->lf, s->af_ir, k + s->af_o) + - conv(dblen, hlen, s->rf, s->of_ir, k + s->of_o)); - right = - ( conv(dblen, hlen, s->rf, s->af_ir, k + s->af_o) + - conv(dblen, hlen, s->lf, s->of_ir, k + s->of_o)); - break; - default: - /* make gcc happy */ - left = 0.0; - right = 0.0; - break; - } - - /* Bass compensation for the lower frequency cut of the HRTF. A - cross talk of the left and right channel is introduced to - match the directional characteristics of higher frequencies. - The bass will not have any real 3D perception, but that is - OK (note at 180 Hz, the wavelength is about 2 m, and any - spatial perception is impossible). */ - left_b = conv(dblen, blen, s->ba_l, s->ba_ir, k); - right_b = conv(dblen, blen, s->ba_r, s->ba_ir, k); - left += (1 - BASSCROSS) * left_b + BASSCROSS * right_b; - right += (1 - BASSCROSS) * right_b + BASSCROSS * left_b; - /* Also mix the LFE channel (if available) */ - if(data->nch >= 6) { - left += in[5] * M3_01DB; - right += in[5] * M3_01DB; - } - - /* Amplitude renormalization. */ - left *= AMPLNORM; - right *= AMPLNORM; - - switch (s->decode_mode) { - case HRTF_MIX_51: - case HRTF_MIX_STEREO: - /* "Cheating": linear stereo expansion to amplify the 3D - perception. Note: Too much will destroy the acoustic space - and may even result in headaches. */ - diff = STEXPAND2 * (left - right); - out[0] = av_clip_int16(left + diff); - out[1] = av_clip_int16(right - diff); - break; - case HRTF_MIX_MATRIX2CH: - /* Do attempt any stereo expansion with matrix encoded - sources. The L, R channels are already stereo expanded - by the steering, any further stereo expansion will sound - very unnatural. */ - out[0] = av_clip_int16(left); - out[1] = av_clip_int16(right); - break; - } - - /* Next sample... */ - in = &in[data->nch]; - out = &out[af->data->nch]; - (s->cyc_pos)--; - if(s->cyc_pos < 0) - s->cyc_pos += dblen; + const int k = s->cyc_pos; + + update_ch(s, in, k); + + /* Simulate a 7.5 ms -20 dB echo of the center channel in the + front channels (like reflection from a room wall) - a kind of + psycho-acoustically "cheating" to focus the center front + channel, which is normally hard to be perceived as front */ + s->lf[k] += CFECHOAMPL * s->cf[(k + CFECHODELAY) % s->dlbuflen]; + s->rf[k] += CFECHOAMPL * s->cf[(k + CFECHODELAY) % s->dlbuflen]; + + switch (s->decode_mode) { + case HRTF_MIX_51: + case HRTF_MIX_MATRIX2CH: + /* Mixer filter matrix */ + common = conv(dblen, hlen, s->cf, s->cf_ir, k + s->cf_o); + if(s->matrix_mode) { + /* In matrix decoding mode, the rear channel gain must be + renormalized, as there is an additional channel. */ + matrix_decode(in, k, 2, 3, 0, s->dlbuflen, + s->lr_fwr, s->rr_fwr, + s->lrprr_fwr, s->lrmrr_fwr, + &(s->adapt_lr_gain), &(s->adapt_rr_gain), + &(s->adapt_lrprr_gain), &(s->adapt_lrmrr_gain), + s->lr, s->rr, NULL, NULL, s->cr); + common += + conv(dblen, hlen, s->cr, s->cr_ir, k + s->cr_o) * + M1_76DB; + left = + ( conv(dblen, hlen, s->lf, s->af_ir, k + s->af_o) + + conv(dblen, hlen, s->rf, s->of_ir, k + s->of_o) + + (conv(dblen, hlen, s->lr, s->ar_ir, k + s->ar_o) + + conv(dblen, hlen, s->rr, s->or_ir, k + s->or_o)) * + M1_76DB + common); + right = + ( conv(dblen, hlen, s->rf, s->af_ir, k + s->af_o) + + conv(dblen, hlen, s->lf, s->of_ir, k + s->of_o) + + (conv(dblen, hlen, s->rr, s->ar_ir, k + s->ar_o) + + conv(dblen, hlen, s->lr, s->or_ir, k + s->or_o)) * + M1_76DB + common); + } else { + left = + ( conv(dblen, hlen, s->lf, s->af_ir, k + s->af_o) + + conv(dblen, hlen, s->rf, s->of_ir, k + s->of_o) + + conv(dblen, hlen, s->lr, s->ar_ir, k + s->ar_o) + + conv(dblen, hlen, s->rr, s->or_ir, k + s->or_o) + + common); + right = + ( conv(dblen, hlen, s->rf, s->af_ir, k + s->af_o) + + conv(dblen, hlen, s->lf, s->of_ir, k + s->of_o) + + conv(dblen, hlen, s->rr, s->ar_ir, k + s->ar_o) + + conv(dblen, hlen, s->lr, s->or_ir, k + s->or_o) + + common); + } + break; + case HRTF_MIX_STEREO: + left = + ( conv(dblen, hlen, s->lf, s->af_ir, k + s->af_o) + + conv(dblen, hlen, s->rf, s->of_ir, k + s->of_o)); + right = + ( conv(dblen, hlen, s->rf, s->af_ir, k + s->af_o) + + conv(dblen, hlen, s->lf, s->of_ir, k + s->of_o)); + break; + default: + /* make gcc happy */ + left = 0.0; + right = 0.0; + break; + } + + /* Bass compensation for the lower frequency cut of the HRTF. A + cross talk of the left and right channel is introduced to + match the directional characteristics of higher frequencies. + The bass will not have any real 3D perception, but that is + OK (note at 180 Hz, the wavelength is about 2 m, and any + spatial perception is impossible). */ + left_b = conv(dblen, blen, s->ba_l, s->ba_ir, k); + right_b = conv(dblen, blen, s->ba_r, s->ba_ir, k); + left += (1 - BASSCROSS) * left_b + BASSCROSS * right_b; + right += (1 - BASSCROSS) * right_b + BASSCROSS * left_b; + /* Also mix the LFE channel (if available) */ + if(data->nch >= 6) { + left += in[5] * M3_01DB; + right += in[5] * M3_01DB; + } + + /* Amplitude renormalization. */ + left *= AMPLNORM; + right *= AMPLNORM; + + switch (s->decode_mode) { + case HRTF_MIX_51: + case HRTF_MIX_STEREO: + /* "Cheating": linear stereo expansion to amplify the 3D + perception. Note: Too much will destroy the acoustic space + and may even result in headaches. */ + diff = STEXPAND2 * (left - right); + out[0] = av_clip_int16(left + diff); + out[1] = av_clip_int16(right - diff); + break; + case HRTF_MIX_MATRIX2CH: + /* Do attempt any stereo expansion with matrix encoded + sources. The L, R channels are already stereo expanded + by the steering, any further stereo expansion will sound + very unnatural. */ + out[0] = av_clip_int16(left); + out[1] = av_clip_int16(right); + break; + } + + /* Next sample... */ + in = &in[data->nch]; + out = &out[af->data->nch]; + (s->cyc_pos)--; + if(s->cyc_pos < 0) + s->cyc_pos += dblen; } /* Set output data */ @@ -546,13 +546,13 @@ static int allocate(af_hrtf_t *s) if ((s->ba_l = malloc(s->dlbuflen * sizeof(float))) == NULL) return -1; if ((s->ba_r = malloc(s->dlbuflen * sizeof(float))) == NULL) return -1; if ((s->fwrbuf_l = - malloc(s->dlbuflen * sizeof(float))) == NULL) return -1; + malloc(s->dlbuflen * sizeof(float))) == NULL) return -1; if ((s->fwrbuf_r = - malloc(s->dlbuflen * sizeof(float))) == NULL) return -1; + malloc(s->dlbuflen * sizeof(float))) == NULL) return -1; if ((s->fwrbuf_lr = - malloc(s->dlbuflen * sizeof(float))) == NULL) return -1; + malloc(s->dlbuflen * sizeof(float))) == NULL) return -1; if ((s->fwrbuf_rr = - malloc(s->dlbuflen * sizeof(float))) == NULL) return -1; + malloc(s->dlbuflen * sizeof(float))) == NULL) return -1; return 0; } @@ -595,16 +595,16 @@ static int af_open(struct af_instance* af) s->print_flag = 1; if (allocate(s) != 0) { - MP_ERR(af, "Memory allocation error.\n"); - return AF_ERROR; + MP_ERR(af, "Memory allocation error.\n"); + return AF_ERROR; } for(i = 0; i < s->dlbuflen; i++) - s->lf[i] = s->rf[i] = s->lr[i] = s->rr[i] = s->cf[i] = - s->cr[i] = 0; + s->lf[i] = s->rf[i] = s->lr[i] = s->rr[i] = s->cf[i] = + s->cr[i] = 0; s->lr_fwr = - s->rr_fwr = 0; + s->rr_fwr = 0; s->cf_ir = cf_filt + (s->cf_o = pulse_detect(cf_filt)); s->af_ir = af_filt + (s->af_o = pulse_detect(af_filt)); @@ -614,18 +614,18 @@ static int af_open(struct af_instance* af) s->cr_ir = cr_filt + (s->cr_o = pulse_detect(cr_filt)); if((s->ba_ir = malloc(s->basslen * sizeof(float))) == NULL) { - MP_ERR(af, "Memory allocation error.\n"); - return AF_ERROR; + MP_ERR(af, "Memory allocation error.\n"); + return AF_ERROR; } fc = 2.0 * BASSFILTFREQ / (float)af->data->rate; if(af_filter_design_fir(s->basslen, s->ba_ir, &fc, LP | KAISER, 4 * M_PI) == -1) { - MP_ERR(af, "Unable to design low-pass " - "filter.\n"); - return AF_ERROR; + MP_ERR(af, "Unable to design low-pass " + "filter.\n"); + return AF_ERROR; } for(i = 0; i < s->basslen; i++) - s->ba_ir[i] *= BASSGAIN; + s->ba_ir[i] *= BASSGAIN; return AF_OK; } diff --git a/audio/filter/af_hrtf.h b/audio/filter/af_hrtf.h index 887310b57d..a654dc4f98 100644 --- a/audio/filter/af_hrtf.h +++ b/audio/filter/af_hrtf.h @@ -24,38 +24,38 @@ #define HRTF_MIX_MATRIX2CH 2 /* Amplitude scaling factors */ -#define M17_0DB 0.1414213562 -#define M9_03DB 0.3535533906 -#define M6_99DB 0.4472135955 -#define M4_77DB 0.5773502692 -#define M3_01DB 0.7071067812 -#define M1_76DB 0.8164965809 +#define M17_0DB 0.1414213562 +#define M9_03DB 0.3535533906 +#define M6_99DB 0.4472135955 +#define M4_77DB 0.5773502692 +#define M3_01DB 0.7071067812 +#define M1_76DB 0.8164965809 -#define DELAYBUFLEN 1024 /* Length of the delay buffer */ -#define HRTFFILTLEN 64 /* HRTF filter length */ -#define IRTHRESH 0.001 /* Impulse response pruning thresh. */ +#define DELAYBUFLEN 1024 /* Length of the delay buffer */ +#define HRTFFILTLEN 64 /* HRTF filter length */ +#define IRTHRESH 0.001 /* Impulse response pruning thresh. */ -#define AMPLNORM M6_99DB /* Overall amplitude renormalization */ +#define AMPLNORM M6_99DB /* Overall amplitude renormalization */ -#define BASSFILTFREQ 180 /* Bass compensation filter cut (Hz) */ -#define BASSFILTLEN 193 /* Bass compensation filter length */ -#define BASSGAIN M_SQRT2 /* Bass compensation gain */ -#define BASSCROSS 0.35 /* Bass cross talk */ +#define BASSFILTFREQ 180 /* Bass compensation filter cut (Hz) */ +#define BASSFILTLEN 193 /* Bass compensation filter length */ +#define BASSGAIN M_SQRT2 /* Bass compensation gain */ +#define BASSCROSS 0.35 /* Bass cross talk */ -#define FWRDURATION 240 /* FWR average duration (samples) */ -#define MATREARDELAY 720 /* Matrix mode rear delay (samples) */ +#define FWRDURATION 240 /* FWR average duration (samples) */ +#define MATREARDELAY 720 /* Matrix mode rear delay (samples) */ -#define MATAGCTRIG 8.0 /* (Fuzzy) AGC trigger */ -#define MATAGCDECAY 1.0 /* AGC baseline decay rate (1/samp.) */ -#define MATAGCLOCK 0.2 /* AGC range (around 1) where the - matrix behaves passively */ -#define MATCOMPGAIN 0.37 /* Cross talk compensation gain, - 0.50 - 0.55 is full cancellation. */ +#define MATAGCTRIG 8.0 /* (Fuzzy) AGC trigger */ +#define MATAGCDECAY 1.0 /* AGC baseline decay rate (1/samp.) */ +#define MATAGCLOCK 0.2 /* AGC range (around 1) where the + matrix behaves passively */ +#define MATCOMPGAIN 0.37 /* Cross talk compensation gain, + 0.50 - 0.55 is full cancellation. */ -#define CFECHODELAY 360 /* Center front echo delay (samples) */ -#define CFECHOAMPL M17_0DB /* Center front echo amplitude */ +#define CFECHODELAY 360 /* Center front echo delay (samples) */ +#define CFECHOAMPL M17_0DB /* Center front echo amplitude */ -#define STEXPAND2 0.07 /* Stereo expansion / 2 */ +#define STEXPAND2 0.07 /* Stereo expansion / 2 */ /* Head related impulse response (HRIR) derived from KEMAR measurement data by Bill Gardner <billg@media.mit.edu> and Keith Martin diff --git a/audio/filter/af_karaoke.c b/audio/filter/af_karaoke.c index bddb218dde..00c4d16dca 100644 --- a/audio/filter/af_karaoke.c +++ b/audio/filter/af_karaoke.c @@ -32,50 +32,50 @@ // Initialization and runtime control static int control(struct af_instance* af, int cmd, void* arg) { - switch(cmd){ - case AF_CONTROL_REINIT: + switch(cmd){ + case AF_CONTROL_REINIT: mp_audio_copy_config(af->data, (struct mp_audio*)arg); mp_audio_set_format(af->data, AF_FORMAT_FLOAT); - return af_test_output(af,(struct mp_audio*)arg); - } - return AF_UNKNOWN; + return af_test_output(af,(struct mp_audio*)arg); + } + return AF_UNKNOWN; } // Filter data through filter static int play(struct af_instance* af, struct mp_audio* data, int flags) { - struct mp_audio* c = data; // Current working data - float* a = c->planes[0]; // Audio data - int nch = c->nch; // Number of channels - int len = c->samples*nch; // Number of samples in current audio block - register int i; + struct mp_audio* c = data; // Current working data + float* a = c->planes[0]; // Audio data + int nch = c->nch; // Number of channels + int len = c->samples*nch; // Number of samples in current audio block + register int i; - /* - FIXME1 add a low band pass filter to avoid suppressing - centered bass/drums - FIXME2 better calculated* attenuation factor - */ + /* + FIXME1 add a low band pass filter to avoid suppressing + centered bass/drums + FIXME2 better calculated* attenuation factor + */ - for(i=0;i<len;i+=nch) - { - a[i] = (a[i] - a[i+1]) * 0.7; - a[i+1]=a[i]; - } + for(i=0;i<len;i+=nch) + { + a[i] = (a[i] - a[i+1]) * 0.7; + a[i+1]=a[i]; + } - return 0; + return 0; } // Allocate memory and set function pointers static int af_open(struct af_instance* af){ - af->control = control; - af->filter = play; - return AF_OK; + af->control = control; + af->filter = play; + return AF_OK; } // Description of this filter struct af_info af_info_karaoke = { - .info = "Simple karaoke/voice-removal audio filter", - .name = "karaoke", - .flags = AF_FLAGS_NOT_REENTRANT, - .open = af_open, + .info = "Simple karaoke/voice-removal audio filter", + .name = "karaoke", + .flags = AF_FLAGS_NOT_REENTRANT, + .open = af_open, }; diff --git a/audio/filter/af_pan.c b/audio/filter/af_pan.c index 01b0575ae3..b966deb9b3 100644 --- a/audio/filter/af_pan.c +++ b/audio/filter/af_pan.c @@ -32,7 +32,7 @@ typedef struct af_pan_s { int nch; // Number of output channels; zero means same as input - float level[AF_NCH][AF_NCH]; // Gain level for each channel + float level[AF_NCH][AF_NCH]; // Gain level for each channel char *matrixstr; }af_pan_t; @@ -110,14 +110,14 @@ static int control(struct af_instance* af, int cmd, void* arg) // Filter data through filter static int filter(struct af_instance* af, struct mp_audio* data, int flags) { - struct mp_audio* c = data; // Current working data - struct mp_audio* l = af->data; // Local data - af_pan_t* s = af->priv; // Setup for this instance - float* in = c->planes[0]; // Input audio data - float* out = NULL; // Output audio data - float* end = in+c->samples*c->nch; // End of loop - int nchi = c->nch; // Number of input channels - int ncho = l->nch; // Number of output channels + struct mp_audio* c = data; // Current working data + struct mp_audio* l = af->data; // Local data + af_pan_t* s = af->priv; // Setup for this instance + float* in = c->planes[0]; // Input audio data + float* out = NULL; // Output audio data + float* end = in+c->samples*c->nch; // End of loop + int nchi = c->nch; // Number of input channels + int ncho = l->nch; // Number of output channels register int j,k; mp_audio_realloc_min(af->data, data->samples); @@ -130,7 +130,7 @@ static int filter(struct af_instance* af, struct mp_audio* data, int flags) register float x = 0.0; register float* tin = in; for(k=0;k<nchi;k++) - x += tin[k] * s->level[j][k]; + x += tin[k] * s->level[j][k]; out[j] = x; } out+= ncho; diff --git a/audio/filter/af_sinesuppress.c b/audio/filter/af_sinesuppress.c index 9719d46828..6b1d5da50d 100644 --- a/audio/filter/af_sinesuppress.c +++ b/audio/filter/af_sinesuppress.c @@ -57,14 +57,14 @@ static int control(struct af_instance* af, int cmd, void* arg) #if 0 if (((struct mp_audio*)arg)->format == AF_FORMAT_FLOAT) { - af->data->format = AF_FORMAT_FLOAT; - af->data->bps = 4; - af->play = play_float; + af->data->format = AF_FORMAT_FLOAT; + af->data->bps = 4; + af->play = play_float; }// else #endif { mp_audio_set_format(af->data, AF_FORMAT_S16); - af->filter = play_s16; + af->filter = play_s16; } return af_test_output(af,(struct mp_audio*)arg); @@ -78,8 +78,8 @@ static int play_s16(struct af_instance* af, struct mp_audio* data, int f) { af_sinesuppress_t *s = af->priv; register int i = 0; - int16_t *a = (int16_t*)data->planes[0]; // Audio data - int len = data->samples*data->nch; // Number of samples + int16_t *a = (int16_t*)data->planes[0]; // Audio data + int len = data->samples*data->nch; // Number of samples for (i = 0; i < len; i++) { @@ -109,8 +109,8 @@ static struct mp_audio* play_float(struct af_instance* af, struct mp_audio* data { af_sinesuppress_t *s = af->setup; register int i = 0; - float *a = (float*)data->audio; // Audio data - int len = data->len/4; // Number of samples + float *a = (float*)data->audio; // Audio data + int len = data->len/4; // Number of samples float avg, l, r; for (i = 0; i < len; i+=2) diff --git a/audio/filter/af_sub.c b/audio/filter/af_sub.c index 7012e1e129..742d2e7413 100644 --- a/audio/filter/af_sub.c +++ b/audio/filter/af_sub.c @@ -41,22 +41,22 @@ // Analog domain biquad section typedef struct{ - float a[3]; // Numerator coefficients - float b[3]; // Denominator coefficients + float a[3]; // Numerator coefficients + float b[3]; // Denominator coefficients } biquad_t; // S-parameters for designing 4th order Butterworth filter static biquad_t sp[2] = {{{1.0,0.0,0.0},{1.0,0.765367,1.0}}, - {{1.0,0.0,0.0},{1.0,1.847759,1.0}}}; + {{1.0,0.0,0.0},{1.0,1.847759,1.0}}}; // Data for specific instances of this filter typedef struct af_sub_s { - float w[2][4]; // Filter taps for low-pass filter - float q[2][2]; // Circular queues - float fc; // Cutoff frequency [Hz] for low-pass filter - float k; // Filter gain; - int ch; // Channel number which to insert the filtered data + float w[2][4]; // Filter taps for low-pass filter + float q[2][2]; // Circular queues + float fc; // Cutoff frequency [Hz] for low-pass filter + float k; // Filter gain; + int ch; // Channel number which to insert the filtered data }af_sub_t; @@ -92,7 +92,7 @@ static int control(struct af_instance* af, int cmd, void* arg) float h0 = (q)[0]; \ float h1 = (q)[1]; \ float hn = (in) - h0 * (w)[0] - h1 * (w)[1]; \ - out = hn + h0 * (w)[2] + h1 * (w)[3]; \ + out = hn + h0 * (w)[2] + h1 * (w)[3]; \ (q)[1] = h0; \ (q)[0] = hn; \ } @@ -101,12 +101,12 @@ static int control(struct af_instance* af, int cmd, void* arg) // Filter data through filter static int filter(struct af_instance* af, struct mp_audio* data, int flags) { - struct mp_audio* c = data; // Current working data - af_sub_t* s = af->priv; // Setup for this instance - float* a = c->planes[0]; // Audio data - int len = c->samples*c->nch; // Number of samples in current audio block - int nch = c->nch; // Number of channels - int ch = s->ch; // Channel in which to insert the sub audio + struct mp_audio* c = data; // Current working data + af_sub_t* s = af->priv; // Setup for this instance + float* a = c->planes[0]; // Audio data + int len = c->samples*c->nch; // Number of samples in current audio block + int nch = c->nch; // Number of channels + int ch = s->ch; // Channel in which to insert the sub audio register int i; // Run filter diff --git a/audio/filter/af_surround.c b/audio/filter/af_surround.c index 9cabeedf9d..06a8c4a761 100644 --- a/audio/filter/af_surround.c +++ b/audio/filter/af_surround.c @@ -76,13 +76,13 @@ typedef struct af_surround_s { float lq[2*L]; // Circular queue for filtering left rear channel float rq[2*L]; // Circular queue for filtering right rear channel - float w[L]; // FIR filter coefficients for surround sound 7kHz low-pass - float* dr; // Delay queue right rear channel - float* dl; // Delay queue left rear channel - float d; // Delay time - int i; // Position in circular buffer - int wi; // Write index for delay queue - int ri; // Read index for delay queue + float w[L]; // FIR filter coefficients for surround sound 7kHz low-pass + float* dr; // Delay queue right rear channel + float* dl; // Delay queue left rear channel + float d; // Delay time + int i; // Position in circular buffer + int wi; // Write index for delay queue + int ri; // Read index for delay queue }af_surround_t; // Initialization and runtime control @@ -132,10 +132,10 @@ static int control(struct af_instance* af, int cmd, void* arg) // The beginnings of an active matrix... static float steering_matrix[][12] = { -// LL RL LR RR LS RS -// LLs RLs LRs RRs LC RC - {.707, .0, .0, .707, .5, -.5, - .5878, -.3928, .3928, -.5878, .5, .5}, +// LL RL LR RR LS RS +// LLs RLs LRs RRs LC RC + {.707, .0, .0, .707, .5, -.5, + .5878, -.3928, .3928, -.5878, .5, .5}, }; // Experimental moving average dominance @@ -144,13 +144,13 @@ static float steering_matrix[][12] = { // Filter data through filter static int filter(struct af_instance* af, struct mp_audio* data, int flags){ af_surround_t* s = (af_surround_t*)af->priv; - float* m = steering_matrix[0]; - float* in = data->planes[0]; // Input audio data - float* out = NULL; // Output audio data - float* end = in + data->samples * data->nch; - int i = s->i; // Filter queue index - int ri = s->ri; // Read index for delay queue - int wi = s->wi; // Write index for delay queue + float* m = steering_matrix[0]; + float* in = data->planes[0]; // Input audio data + float* out = NULL; // Output audio data + float* end = in + data->samples * data->nch; + int i = s->i; // Filter queue index + int ri = s->ri; // Read index for delay queue + int wi = s->wi; // Write index for delay queue mp_audio_realloc_min(af->data, data->samples); diff --git a/audio/filter/dsp.h b/audio/filter/dsp.h index 561b86cfe0..164eccf140 100644 --- a/audio/filter/dsp.h +++ b/audio/filter/dsp.h @@ -18,8 +18,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef MPLAYER_DSP_H -#define MPLAYER_DSP_H +#ifndef MPLAYER_DSP_H +#define MPLAYER_DSP_H /* Implementation of routines used for DSP */ diff --git a/audio/filter/equalizer.h b/audio/filter/equalizer.h index 4935401413..6505379276 100644 --- a/audio/filter/equalizer.h +++ b/audio/filter/equalizer.h @@ -26,22 +26,22 @@ typedef struct equalizer_s { - float gain; // Gain in dB -15 - 15 - int channel; // Channel number 0 - 5 - int band; // Frequency band 0 - 9 + float gain; // Gain in dB -15 - 15 + int channel; // Channel number 0 - 5 + int band; // Frequency band 0 - 9 }equalizer_t; /* The different frequency bands are: -nr. center frequency -0 31.25 Hz -1 62.50 Hz -2 125.0 Hz -3 250.0 Hz -4 500.0 Hz -5 1.000 kHz -6 2.000 kHz -7 4.000 kHz -8 8.000 kHz +nr. center frequency +0 31.25 Hz +1 62.50 Hz +2 125.0 Hz +3 250.0 Hz +4 500.0 Hz +5 1.000 kHz +6 2.000 kHz +7 4.000 kHz +8 8.000 kHz 9 16.00 kHz */ diff --git a/audio/filter/filter.c b/audio/filter/filter.c index b272125fd8..dbbe743a79 100644 --- a/audio/filter/filter.c +++ b/audio/filter/filter.c @@ -58,7 +58,7 @@ inline FLOAT_TYPE af_filter_fir(register unsigned int n, const FLOAT_TYPE* w, 0 < fc < 1 where 1 <=> Fs/2 flags window and filter type as defined in filter.h variables are ored together: i.e. LP|HAMMING will give a - low pass filter designed using a hamming window + low pass filter designed using a hamming window opt beta constant used only when designing using kaiser windows returns 0 if OK, -1 if fail @@ -66,16 +66,16 @@ inline FLOAT_TYPE af_filter_fir(register unsigned int n, const FLOAT_TYPE* w, int af_filter_design_fir(unsigned int n, FLOAT_TYPE* w, const FLOAT_TYPE* fc, unsigned int flags, FLOAT_TYPE opt) { - unsigned int o = n & 1; // Indicator for odd filter length - unsigned int end = ((n + 1) >> 1) - o; // Loop end - unsigned int i; // Loop index + unsigned int o = n & 1; // Indicator for odd filter length + unsigned int end = ((n + 1) >> 1) - o; // Loop end + unsigned int i; // Loop index - FLOAT_TYPE k1 = 2 * M_PI; // 2*pi*fc1 + FLOAT_TYPE k1 = 2 * M_PI; // 2*pi*fc1 FLOAT_TYPE k2 = 0.5 * (FLOAT_TYPE)(1 - o);// Constant used if the filter has even length - FLOAT_TYPE k3; // 2*pi*fc2 Constant used in BP and BS design - FLOAT_TYPE g = 0.0; // Gain - FLOAT_TYPE t1,t2,t3; // Temporary variables - FLOAT_TYPE fc1,fc2; // Cutoff frequencies + FLOAT_TYPE k3; // 2*pi*fc2 Constant used in BP and BS design + FLOAT_TYPE g = 0.0; // Gain + FLOAT_TYPE t1,t2,t3; // Temporary variables + FLOAT_TYPE fc1,fc2; // Cutoff frequencies // Sanity check if(!w || (n == 0)) return -1; @@ -113,28 +113,28 @@ int af_filter_design_fir(unsigned int n, FLOAT_TYPE* w, const FLOAT_TYPE* fc, // where x is zero. To make sure nothing strange happens, we set this // value separately. if (o){ - w[end] = fc1 * w[end] * 2.0; - g=w[end]; + w[end] = fc1 * w[end] * 2.0; + g=w[end]; } // Create filter for (i=0 ; i<end ; i++){ - t1 = (FLOAT_TYPE)(i+1) - k2; - w[end-i-1] = w[n-end+i] = w[end-i-1] * sin(k1 * t1)/(M_PI * t1); // Sinc - g += 2*w[end-i-1]; // Total gain in filter + t1 = (FLOAT_TYPE)(i+1) - k2; + w[end-i-1] = w[n-end+i] = w[end-i-1] * sin(k1 * t1)/(M_PI * t1); // Sinc + g += 2*w[end-i-1]; // Total gain in filter } } else{ // High pass filter if (!o) // High pass filters must have odd length - return -1; + return -1; w[end] = 1.0 - (fc1 * w[end] * 2.0); g= w[end]; // Create filter for (i=0 ; i<end ; i++){ - t1 = (FLOAT_TYPE)(i+1); - w[end-i-1] = w[n-end+i] = -1 * w[end-i-1] * sin(k1 * t1)/(M_PI * t1); // Sinc - g += ((i&1) ? (2*w[end-i-1]) : (-2*w[end-i-1])); // Total gain in filter + t1 = (FLOAT_TYPE)(i+1); + w[end-i-1] = w[n-end+i] = -1 * w[end-i-1] * sin(k1 * t1)/(M_PI * t1); // Sinc + g += ((i&1) ? (2*w[end-i-1]) : (-2*w[end-i-1])); // Total gain in filter } } } @@ -151,32 +151,32 @@ int af_filter_design_fir(unsigned int n, FLOAT_TYPE* w, const FLOAT_TYPE* fc, if(flags & BP){ // Band pass // Calculate center tap if (o){ - g=w[end]*(fc1+fc2); - w[end] = (fc2 - fc1) * w[end] * 2.0; + g=w[end]*(fc1+fc2); + w[end] = (fc2 - fc1) * w[end] * 2.0; } // Create filter for (i=0 ; i<end ; i++){ - t1 = (FLOAT_TYPE)(i+1) - k2; - t2 = sin(k3 * t1)/(M_PI * t1); // Sinc fc2 - t3 = sin(k1 * t1)/(M_PI * t1); // Sinc fc1 - g += w[end-i-1] * (t3 + t2); // Total gain in filter - w[end-i-1] = w[n-end+i] = w[end-i-1] * (t2 - t3); + t1 = (FLOAT_TYPE)(i+1) - k2; + t2 = sin(k3 * t1)/(M_PI * t1); // Sinc fc2 + t3 = sin(k1 * t1)/(M_PI * t1); // Sinc fc1 + g += w[end-i-1] * (t3 + t2); // Total gain in filter + w[end-i-1] = w[n-end+i] = w[end-i-1] * (t2 - t3); } } else{ // Band stop if (!o) // Band stop filters must have odd length - return -1; + return -1; w[end] = 1.0 - (fc2 - fc1) * w[end] * 2.0; g= w[end]; // Create filter for (i=0 ; i<end ; i++){ - t1 = (FLOAT_TYPE)(i+1); - t2 = sin(k1 * t1)/(M_PI * t1); // Sinc fc1 - t3 = sin(k3 * t1)/(M_PI * t1); // Sinc fc2 - w[end-i-1] = w[n-end+i] = w[end-i-1] * (t2 - t3); - g += 2*w[end-i-1]; // Total gain in filter + t1 = (FLOAT_TYPE)(i+1); + t2 = sin(k1 * t1)/(M_PI * t1); // Sinc fc1 + t3 = sin(k3 * t1)/(M_PI * t1); // Sinc fc2 + w[end-i-1] = w[n-end+i] = w[end-i-1] * (t2 - t3); + g += 2*w[end-i-1]; // Total gain in filter } } } @@ -224,12 +224,12 @@ static void af_filter_prewarp(FLOAT_TYPE* a, FLOAT_TYPE fc, FLOAT_TYPE fs) Arguments: a - s-domain numerator coefficients b - s-domain denominator coefficients - k - filter gain factor. Initially set to 1 and modified by each + k - filter gain factor. Initially set to 1 and modified by each biquad section in such a way, as to make it the coefficient by which to multiply the overall filter gain in order to achieve a desired overall filter gain, specified in initial value of k. - fs - sampling rate (Hz) + fs - sampling rate (Hz) coef - array of z-domain coefficients to be filled in. Return: On return, set coef z-domain coefficients and k to the gain @@ -319,13 +319,13 @@ static void af_filter_bilinear(const FLOAT_TYPE* a, const FLOAT_TYPE* b, FLOAT_T Arguments: a - s-domain numerator coefficients, a[1] is always assumed to be 1.0 b - s-domain denominator coefficients - Q - Q value for the filter - k - filter gain factor. Initially set to 1 and modified by each + Q - Q value for the filter + k - filter gain factor. Initially set to 1 and modified by each biquad section in such a way, as to make it the coefficient by which to multiply the overall filter gain in order to achieve a desired overall filter gain, specified in initial value of k. - fs - sampling rate (Hz) + fs - sampling rate (Hz) coef - array of z-domain coefficients to be filled in. Note: Upon return from each call, the k argument will be set to a diff --git a/audio/filter/filter.h b/audio/filter/filter.h index aed33352c2..f3dea88838 100644 --- a/audio/filter/filter.h +++ b/audio/filter/filter.h @@ -49,7 +49,7 @@ #define WINDOW_MASK 0x0000001F // Parallel filter design -#define FWD 0x00000001 // Forward indexing of polyphase filter +#define FWD 0x00000001 // Forward indexing of polyphase filter #define REW 0x00000002 // Reverse indexing of polyphase filter #define ODD 0x00000010 // Make filter HP diff --git a/audio/filter/tools.c b/audio/filter/tools.c index 217224150e..231477927f 100644 --- a/audio/filter/tools.c +++ b/audio/filter/tools.c @@ -115,9 +115,9 @@ int af_test_output(struct af_instance* af, struct mp_audio* out) float af_softclip(float a) { if (a >= M_PI/2) - return 1.0; + return 1.0; else if (a <= -M_PI/2) - return -1.0; + return -1.0; else - return sin(a); + return sin(a); } diff --git a/audio/filter/window.c b/audio/filter/window.c index a970bdcbea..089c629f8a 100644 --- a/audio/filter/window.c +++ b/audio/filter/window.c @@ -59,7 +59,7 @@ void af_window_triang(int n, FLOAT_TYPE* w) FLOAT_TYPE k1 = (FLOAT_TYPE)(n & 1); FLOAT_TYPE k2 = 1/((FLOAT_TYPE)n + k1); int end = (n + 1) >> 1; - int i; + int i; // Calculate window coefficients for (i=0 ; i<end ; i++) @@ -77,7 +77,7 @@ void af_window_triang(int n, FLOAT_TYPE* w) */ void af_window_hanning(int n, FLOAT_TYPE* w) { - int i; + int i; FLOAT_TYPE k = 2*M_PI/((FLOAT_TYPE)(n+1)); // 2*pi/(N+1) // Calculate window coefficients @@ -201,7 +201,7 @@ void af_window_kaiser(int n, FLOAT_TYPE* w, FLOAT_TYPE b) { FLOAT_TYPE tmp; FLOAT_TYPE k1 = 1.0/besselizero(b); - int k2 = 1 - (n & 1); + int k2 = 1 - (n & 1); int end = (n + 1) >> 1; int i; |