Commit 593d5176 authored by Monty Montgomery's avatar Monty Montgomery

Eliminate block change CPU latency in declipping filter by pre-caching...

Eliminate block change CPU latency in declipping filter by pre-caching blocksize changes w.r.t. FFTW



git-svn-id: https://svn.xiph.org/trunk/postfish@6532 0101bb08-14d6-0310-b084-bc0e0c8e3800
parent 563f94fa
......@@ -34,7 +34,9 @@ extern int input_size;
extern int inbytes;
/* accessed only in playback thread/setup */
static fftwf_plan fftwf_weight;
static float *work;
static float *freq;
......@@ -63,29 +65,6 @@ static sig_atomic_t pending_blocksize=0;
static float convergence=0.;
static float iterations=0.;
#include <stdio.h>
static void _analysis(char *base,int i,float *v,int n,int dB,int offset){
int j;
FILE *of;
char buffer[80];
sprintf(buffer,"%s_%d.m",base,i);
of=fopen(buffer,"a");
if(!of)perror("failed to open data dump file");
for(j=0;j<n;j++){
fprintf(of,"%f ",(float)j+offset);
if(dB)
fprintf(of,"%f\n",todB(v[j]));
else
fprintf(of,"%f\n",(v[j]));
}
fprintf(of,"\n");
fclose(of);
}
/* feedback! */
typedef struct declip_feedback{
feedback_generic parent_class;
......@@ -149,14 +128,13 @@ static void setup_window(int left,int right){
static void setup_blocksize(int newblocksize){
int i;
if(blocksize)fftwf_destroy_plan(fftwf_weight);
blocksize=newblocksize;
fftwf_weight=fftwf_plan_dft_r2c_1d(blocksize*2,
work,
(fftwf_complex *)freq,
FFTW_MEASURE);
fftwf_weight=fftwf_plan_dft_r2c_1d(blocksize*2,work,
(fftwf_complex *)freq,
FFTW_MEASURE);
lopad=1-rint(fromBark(toBark(0.)-width)*blocksize*2/input_rate);
hipad=rint(fromBark(toBark(input_rate*.5)+width)*blocksize*2/input_rate)+lopad;
for(i=0;i<blocksize;i++){
......@@ -171,7 +149,7 @@ static void setup_blocksize(int newblocksize){
/* called only by initial setup */
int declip_load(void){
int i;
int i,j;
declip_active=calloc(input_ch,sizeof(*declip_active));
declip_prev_active=calloc(input_ch,sizeof(*declip_prev_active));
chtrigger=malloc(input_ch*sizeof(*chtrigger));
......@@ -204,8 +182,16 @@ int declip_load(void){
widthlookup=malloc((hiestpad+1)*sizeof(*widthlookup));
freq=fftwf_malloc((blocksize*2+2)*sizeof(freq));
work=fftwf_malloc((blocksize*2)*sizeof(freq));
}
for(i=0,j=32;j<=blocksize*2;i++,j*=2){
fftwf_weight=fftwf_plan_dft_r2c_1d(j,work,
(fftwf_complex *)freq,
FFTW_MEASURE);
fftwf_destroy_plan(fftwf_weight);
}
}
reconstruct_init(32,input_size*4);
pending_blocksize=input_size*2;
return(0);
}
......@@ -321,7 +307,6 @@ static void declip(int blocksize,float trigger,
}
/* called only by playback thread */
static int offset=0;
time_linkage *declip_read(time_linkage *in){
int i,j,k;
float local_trigger[input_ch];
......@@ -359,7 +344,7 @@ time_linkage *declip_read(time_linkage *in){
declip_prev_active[i]=channel_active;
/* peak feedback */
if(declip_visible){
if(declip_visible && !mute_channel_muted(in->active,i)){
float *l=in->data[i];
for(j=0;j<in->samples;j++)
if(fabs(l[j])>peak[i])peak[i]=fabs(l[j]);
......@@ -435,7 +420,7 @@ time_linkage *declip_read(time_linkage *in){
int channel_active=declip_active[i];
/* peak feedback */
if(declip_visible){
if(declip_visible && !mute_channel_muted(in->active,i)){
float *l=in->data[i];
for(j=0;j<in->samples;j++)
if(fabs(l[j])>peak[i])peak[i]=fabs(l[j]);
......@@ -645,11 +630,5 @@ time_linkage *declip_read(time_linkage *in){
out.active=active;
/* XXXX Temporary! Until later plugins can handle mute, we zero out
muted channels here */
for(i=0;i<input_ch;i++)
if((active & (1<<i))==0)
memset(out.data[i],0,sizeof(*out.data[i])*input_size);
return &out;
}
......@@ -240,6 +240,13 @@ void *playback_thread(void *dummy){
link=declip_read(link);
result|=link->samples;
/* XXXX Temporary! Until later plugins can handle mute, we zero out
muted channels here */
for(i=0;i<input_ch;i++)
if((link->active & (1<<i))==0)
memset(link->data[i],0,sizeof(*link->data[i])*input_size);
link=multicompand_read(link);
result|=link->samples;
link=singlecomp_read(link);
......
......@@ -42,6 +42,26 @@ static float *q;
static float *s;
static int blocksize=0;
void reconstruct_init(int minblock,int maxblock){
int i;
q=fftwf_malloc((maxblock+2)*sizeof(*q));
s=fftwf_malloc((maxblock+2)*sizeof(*s));
/* fftw priming trick; run it thorugh the paces and prime a plan for
every size we may need. fftw will cache the information and not
need to re-measure later */
for(i=minblock;i<=maxblock;i<<=1){
fftwf_qf=fftwf_plan_dft_r2c_1d(i,q,(fftwf_complex *)q,FFTW_MEASURE);
fftwf_qb=fftwf_plan_dft_c2r_1d(i,(fftwf_complex *)q,q,FFTW_MEASURE);
fftwf_destroy_plan(fftwf_qf);
fftwf_destroy_plan(fftwf_qb);
}
}
void reconstruct_reinit(int n){
if(blocksize!=n){
if(blocksize){
......
......@@ -21,6 +21,7 @@
*
*/
extern void reconstruct_init(int min,int max);
extern void reconstruct_reinit(int n);
extern void reconstruct(float *x, float *w, float *flag,
float e,int max);
#define VERSION "$Id$ "
/* DO NOT EDIT: Automated versioning hack [Sun Apr 18 18:58:52 EDT 2004] */
/* DO NOT EDIT: Automated versioning hack [Sun Apr 18 22:28:48 EDT 2004] */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment