[xiph-cvs] cvs commit: postfish clippanel.c declip.c input.c mainpanel.c output.c reconstruct.c version.h
Monty
xiphmont at xiph.org
Fri Feb 13 10:11:36 PST 2004
xiphmont 04/02/13 13:11:35
Modified: . clippanel.c declip.c input.c mainpanel.c output.c
reconstruct.c version.h
Log:
We really do need padded fourier blocks to avoid time-aliasing.
Implement that in the declipper and make sure to use it in later
filters.
Monty
Revision Changes Path
1.7 +2 -2 postfish/clippanel.c
Index: clippanel.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/clippanel.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- clippanel.c 14 Jan 2004 16:03:34 -0000 1.6
+++ clippanel.c 13 Feb 2004 18:11:35 -0000 1.7
@@ -73,10 +73,10 @@
int choice=rint(gtk_range_get_value(GTK_RANGE(w)));
int blocksize=64<<choice;
- sprintf(buffer,"%5d ",blocksize*3/4);
+ sprintf(buffer,"%5d ",blocksize);
readout_set(READOUT(samplereadout),buffer);
- sprintf(buffer,"%3.1f ms",blocksize*3000./4/input_rate);
+ sprintf(buffer,"%3.1f ms",blocksize*1000./input_rate);
readout_set(READOUT(msreadout),buffer);
sprintf(buffer,"%5d Hz",(int)rint(input_rate*2./blocksize));
<p><p>1.5 +34 -34 postfish/declip.c
Index: declip.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/declip.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- declip.c 14 Jan 2004 16:03:34 -0000 1.4
+++ declip.c 13 Feb 2004 18:11:35 -0000 1.5
@@ -129,7 +129,7 @@
int declip_settrigger(double trigger,int ch){
if(ch<0 || ch>=input_ch)return -1;
pthread_mutex_lock(&master_mutex);
- chtrigger[ch]=trigger;
+ chtrigger[ch]=trigger-(1./32768);
pthread_mutex_unlock(&master_mutex);
return 0;
}
@@ -216,12 +216,11 @@
int blocksize,double trigger,
double epsilon, double iteration,
int *runningtotal, int *runningcount){
- double freq[blocksize];
- double flag[blocksize];
+ double freq[blocksize*2];
+ double flag[blocksize*2];
int iterbound,i,j,count=0;
- for(i=0;i<blocksize/8;i++)flag[i]=0.;
- for(;i<blocksize*7/8;i++){
+ for(i=blocksize/2;i<blocksize*3/2;i++){
flag[i]=0.;
if(data[i]>=trigger || data[i]<=-trigger){
flag[i]=1.;
@@ -229,36 +228,41 @@
}
}
- *runningtotal+=blocksize*3/4;
+ *runningtotal+=blocksize;
*runningcount+=count;
if(declip_active){
- for(;i<blocksize;i++)flag[i]=0.;
- for(i=0;i<blocksize;i++)data[i]*=window[i];
+ for(i=0;i<blocksize/2;i++)flag[i]=0.;
+ for(i=blocksize*3/2;i<blocksize*2;i++)flag[i]=0.;
+
+ for(i=0;i<blocksize/2;i++)data[i]=0.;
+ for(i=0;i<blocksize;i++)data[i+blocksize/2]*=window[i];
+ for(i=blocksize*3/2;i<blocksize*2;i++)data[i]=0.;
+
memcpy(freq,data,sizeof(freq));
drft_forward(&fft,freq);
- sliding_bark_average(freq,freq,blocksize,width);
-
+ sliding_bark_average(freq,freq,blocksize*2,width);
iterbound=count*iteration;
if(iterbound<10)iterbound=10;
- if(count)reconstruct(&fft,data,freq,flag,epsilon,iterbound,blocksize);
-
+
+ if(count)reconstruct(&fft,data,freq,flag,epsilon,iterbound,blocksize*2);
+
if(out)
for(i=0;i<blocksize/2;i++)
- out[i]=lap[i]+data[i]*window[i];
+ out[i]=lap[i]+data[i+blocksize/2]*window[i];
for(i=blocksize/2,j=0;i<blocksize;i++)
- lap[j++]=data[i]*window[i];
+ lap[j++]=data[i+blocksize/2]*window[i];
}else{
if(out)
for(i=0;i<blocksize/2;i++)
- out[i]=data[i];
+ out[i]=data[i+blocksize/2];
for(i=blocksize/2,j=0;i<blocksize;i++)
- lap[j++]=data[i]*window[i]*window[i];
+ lap[j++]=data[i+blocksize/2]*window[i]*window[i];
}
for(i=blocksize/2;i<input_size;i++)
lap[i]=0.;
@@ -291,31 +295,27 @@
}
blocksize=pending_blocksize;
- lopad=1-rint(fromBark(toBark(0.)-width)*blocksize/input_rate);
- hipad=rint(fromBark(toBark(input_rate*.5)+width)*blocksize/input_rate)+lopad;
+ lopad=1-rint(fromBark(toBark(0.)-width)*blocksize*2/input_rate);
+ hipad=rint(fromBark(toBark(input_rate*.5)+width)*blocksize*2/input_rate)+lopad;
widthlookup=malloc((hipad+1)*sizeof(*widthlookup));
- for(i=0;i<blocksize/2;i++){
- double bark=toBark(input_rate*i/blocksize);
- int hi=rint(fromBark(bark-width)*blocksize/input_rate)-1+lopad;
- int lo=rint(fromBark(bark+width)*blocksize/input_rate)+1+lopad;
+ for(i=0;i<blocksize;i++){
+ double bark=toBark(input_rate*i/(blocksize*2));
+ int hi=rint(fromBark(bark-width)*(blocksize*2)/input_rate)-1+lopad;
+ int lo=rint(fromBark(bark+width)*(blocksize*2)/input_rate)+1+lopad;
widthlookup[i]=(hi<<16)+lo;
}
- drft_init(&fft,blocksize);
+ drft_init(&fft,blocksize*2);
window=malloc(blocksize*sizeof(*window));
- for(i=0;i<blocksize/8;i++) window[i]=0.;
- for(;i<blocksize*3/8;i++) window[i]=sin( (double)(i-blocksize/8)/blocksize*M_PIl*2. );
- for(;i<blocksize*5/8;i++) window[i]=1.;
- for(;i<blocksize*7/8;i++) window[i]=sin( (double)(blocksize*7/8-i)/blocksize*M_PIl*2. );
- for(;i<blocksize;i++) window[i]=0.;
+ for(i=0;i<blocksize;i++) window[i]=sin( M_PIl*i/blocksize );
for(i=0;i<blocksize;i++) window[i]*=window[i];
for(i=0;i<blocksize;i++) window[i]=sin(window[i]*M_PIl*.5);
}
{
- double work[blocksize];
+ double work[blocksize*2];
switch(fillstate){
case 0: /* prime the lapping and cache */
@@ -323,8 +323,8 @@
int j;
double *temp=in->data[i];
total=0;
- memset(work,0,sizeof(*work)*blocksize/2);
- memcpy(work+blocksize/2,temp,sizeof(*work)*blocksize/2);
+ memset(work+blocksize/2,0,sizeof(*work)*blocksize/2);
+ memcpy(work+blocksize,temp,sizeof(*work)*blocksize/2);
declip(work,lap[i],0,blocksize,
local_trigger[i],local_convergence,local_iterations,
&total,count+i);
@@ -348,13 +348,13 @@
int j;
total=0;
for(j=0;j+blocksize<=out.size;j+=blocksize/2){
- memcpy(work,temp+j,sizeof(*work)*blocksize);
+ memcpy(work+blocksize/2,temp+j,sizeof(*work)*blocksize);
declip(work,lap[i],out.data[i]+j,blocksize,
local_trigger[i],local_convergence,local_iterations,
&total,count+i);
}
- memcpy(work,temp+j,sizeof(*work)*blocksize/2);
- memcpy(work+blocksize/2,in->data[i],sizeof(*work)*blocksize/2);
+ memcpy(work+blocksize/2,temp+j,sizeof(*work)*blocksize/2);
+ memcpy(work+blocksize,in->data[i],sizeof(*work)*blocksize/2);
declip(work,lap[i],out.data[i]+j,blocksize,
local_trigger[i],local_convergence,local_iterations,
<p><p>1.14 +2 -2 postfish/input.c
Index: input.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/input.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- input.c 26 Dec 2003 09:55:57 -0000 1.13
+++ input.c 13 Feb 2004 18:11:35 -0000 1.14
@@ -517,9 +517,9 @@
break;
}
if(signp)
- dval=out.data[j][i]=val/2147483647.;
+ dval=out.data[j][i]=val/2147483648.;
else
- dval=out.data[j][i]=(val^0x80000000UL)/2147483647.;
+ dval=out.data[j][i]=(val^0x80000000UL)/2147483648.;
if(fabs(dval)>peak[j])peak[j]=fabs(dval);
rms[j]+= dval*dval;
<p><p>1.26 +1 -1 postfish/mainpanel.c
Index: mainpanel.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/mainpanel.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- mainpanel.c 26 Dec 2003 09:55:57 -0000 1.25
+++ mainpanel.c 13 Feb 2004 18:11:35 -0000 1.26
@@ -862,7 +862,7 @@
available and not dirtied by a seek */
if(!playback_seeking){
off_t time_cursor;
- int n=input_ch+2;
+ int n=(input_ch>1?input_ch+2:input_ch);
double *rms=alloca(sizeof(*rms)*(input_ch+2));
double *peak=alloca(sizeof(*peak)*(input_ch+2));
<p><p>1.12 +51 -21 postfish/output.c
Index: output.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/output.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- output.c 26 Dec 2003 09:55:57 -0000 1.11
+++ output.c 13 Feb 2004 18:11:35 -0000 1.12
@@ -124,9 +124,9 @@
return 0;
}
+static int outbytes;
static FILE *playback_startup(int outfileno, int ch, int r, int *bep){
FILE *playback_fd=NULL;
- int format=AFMT_S16_NE;
int rate=r,channels=ch,ret;
if(outfileno==-1){
@@ -144,6 +144,8 @@
if(isachr(playback_fd)){
int fragment=0x0004000d;
int fd=fileno(playback_fd);
+ int format=AFMT_S16_NE;
+ outbytes=2;
/* try to lower the DSP delay; this ioctl may fail gracefully */
ret=ioctl(fd,SNDCTL_DSP_SETFRAGMENT,&fragment);
@@ -167,7 +169,8 @@
exit(1);
}
}else{
- WriteWav(playback_fd,ch,r,16,-1);
+ outbytes=3;
+ WriteWav(playback_fd,ch,r,24,-1);
*bep=0;
}
@@ -176,8 +179,8 @@
/* playback must be halted to change blocksize. */
void *playback_thread(void *dummy){
- int audiobufsize=8192,i,j,k;
- unsigned char *audiobuf=malloc(audiobufsize);
+ int audiobufsize=0,i,j,k;
+ unsigned char *audiobuf=NULL;
int bigendianp=(AFMT_S16_NE==AFMT_S16_BE?1:0);
FILE *playback_fd=NULL;
int setupp=0;
@@ -241,13 +244,16 @@
setupp=1;
}
- if(audiobufsize<link->channels*link->samples*2){
- audiobufsize=link->channels*link->samples*2;
- audiobuf=realloc(audiobuf,sizeof(*audiobuf)*audiobufsize);
+ if(audiobufsize<link->channels*link->samples*outbytes){
+ audiobufsize=link->channels*link->samples*outbytes;
+ if(audiobuf)
+ audiobuf=realloc(audiobuf,sizeof(*audiobuf)*audiobufsize);
+ else
+ audiobuf=malloc(sizeof(*audiobuf)*audiobufsize);
}
/* final limiting and conversion */
-
+
for(k=0,i=0;i<link->samples;i++){
double mean=0.;
double div=0.;
@@ -255,17 +261,41 @@
for(j=0;j<link->channels;j++){
double dval=link->data[j][i];
- int val=rint(dval*32767.);
- if(val>32767)val=32767;
- if(val<-32768)val=-32768;
- if(bigendianp){
- audiobuf[k++]=val>>8;
- audiobuf[k++]=val;
- }else{
- audiobuf[k++]=val;
- audiobuf[k++]=val>>8;
- }
-
+
+ switch(outbytes){
+ case 3:
+ {
+ int32_t val=rint(dval*8388608.);
+ if(val>8388607)val=8388607;
+ if(val<-8388608)val=-8388608;
+
+ if(bigendianp){
+ audiobuf[k++]=val>>16;
+ audiobuf[k++]=val>>8;
+ audiobuf[k++]=val;
+ }else{
+ audiobuf[k++]=val;
+ audiobuf[k++]=val>>8;
+ audiobuf[k++]=val>>16;
+ }
+ }
+ break;
+ case 2:
+ {
+ int32_t val=rint(dval*32768.);
+ if(val>32767)val=32767;
+ if(val<-32768)val=-32768;
+ if(bigendianp){
+ audiobuf[k++]=val>>8;
+ audiobuf[k++]=val;
+ }else{
+ audiobuf[k++]=val;
+ audiobuf[k++]=val>>8;
+ }
+ }
+ break;
+ }
+
if(fabs(dval)>peak[j])peak[j]=fabs(dval);
rms[j]+= dval*dval;
mean+=dval;
@@ -292,7 +322,7 @@
rms[j]=sqrt(rms[j]);
}
- count+=fwrite(audiobuf,1,link->channels*link->samples*2,playback_fd);
+ count+=fwrite(audiobuf,1,link->channels*link->samples*outbytes,playback_fd);
/* inform Lord Vader his shuttle is ready */
push_output_feedback(peak,rms);
@@ -307,7 +337,7 @@
ioctl(fd,SNDCTL_DSP_RESET);
}else{
if(ch>-1)
- WriteWav(playback_fd,ch,rate,16,count);
+ WriteWav(playback_fd,ch,rate,24,count);
}
fclose(playback_fd);
}
<p><p>1.5 +0 -2 postfish/reconstruct.c
Index: reconstruct.c
===================================================================
RCS file: /usr/local/cvsroot/postfish/reconstruct.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- reconstruct.c 14 Jan 2004 16:03:34 -0000 1.4
+++ reconstruct.c 13 Feb 2004 18:11:35 -0000 1.5
@@ -122,7 +122,5 @@
}
- fprintf(stderr,"converged in %d with res=%f\n",i,sqrt(res_new)/sqrt(res_0));
-
}
<p><p>1.25 +2 -2 postfish/version.h
Index: version.h
===================================================================
RCS file: /usr/local/cvsroot/postfish/version.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- version.h 14 Jan 2004 16:03:34 -0000 1.24
+++ version.h 13 Feb 2004 18:11:35 -0000 1.25
@@ -1,2 +1,2 @@
-#define VERSION "$Id: version.h,v 1.24 2004/01/14 16:03:34 xiphmont Exp $ "
-/* DO NOT EDIT: Automated versioning hack [Mon Jan 12 14:46:49 EST 2004] */
+#define VERSION "$Id: version.h,v 1.25 2004/02/13 18:11:35 xiphmont Exp $ "
+/* DO NOT EDIT: Automated versioning hack [Fri Feb 13 13:08:35 EST 2004] */
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list