diff options
| author | Monty <xiphmont@xiph.org> | 2000-02-12 08:33:10 +0000 |
|---|---|---|
| committer | Monty <xiphmont@xiph.org> | 2000-02-12 08:33:10 +0000 |
| commit | 69c07b4904ace8a29154e6da0fcf4fea3f409f8a (patch) | |
| tree | 2d27d587680a1db071869d700d02ddf553856760 /lib | |
| parent | 1487aec2e3af5f9d8e502f1ad5e3418fe4d47e59 (diff) | |
| download | libvorbis-git-69c07b4904ace8a29154e6da0fcf4fea3f409f8a.tar.gz | |
Collect training data from the lib when compiled with -DTRAIN
Added staging to floor0.c
Added first work toward residue partitioning and huff builder
Monty
x
svn path=/trunk/vorbis/; revision=257
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/analysis.c | 3 | ||||
| -rw-r--r-- | lib/floor0.c | 16 | ||||
| -rw-r--r-- | lib/mapping0.c | 40 | ||||
| -rw-r--r-- | lib/psy.c | 39 | ||||
| -rw-r--r-- | lib/psy.h | 16 | ||||
| -rw-r--r-- | lib/res0.c | 74 | ||||
| -rw-r--r-- | lib/synthesis.c | 3 |
7 files changed, 124 insertions, 67 deletions
diff --git a/lib/analysis.c b/lib/analysis.c index faceac34..c6fd420e 100644 --- a/lib/analysis.c +++ b/lib/analysis.c @@ -12,7 +12,7 @@ ******************************************************************** function: single-block PCM analysis mode dispatch - last mod: $Id: analysis.c,v 1.22 2000/01/22 13:28:14 xiphmont Exp $ + last mod: $Id: analysis.c,v 1.23 2000/02/12 08:33:04 xiphmont Exp $ ********************************************************************/ @@ -44,6 +44,7 @@ int vorbis_analysis(vorbis_block *vb,ogg_packet *op){ if(vb->W &&vi->modes>1)mode=1; type=vi->map_type[vi->mode_param[mode]->mapping]; + vb->mode=mode; /* Encode frame mode, pre,post windowsize, then dispatch */ _oggpack_write(&vb->opb,mode,vd->modebits); diff --git a/lib/floor0.c b/lib/floor0.c index 56ef8057..eff41a4c 100644 --- a/lib/floor0.c +++ b/lib/floor0.c @@ -12,7 +12,7 @@ ******************************************************************** function: floor backend 0 implementation - last mod: $Id: floor0.c,v 1.8 2000/02/09 22:04:12 xiphmont Exp $ + last mod: $Id: floor0.c,v 1.9 2000/02/12 08:33:05 xiphmont Exp $ ********************************************************************/ @@ -143,6 +143,20 @@ static int forward(vorbis_block *vb,vorbis_look_floor *i, vorbis_lpc_to_lsp(out,out,look->m); memcpy(work,out,sizeof(double)*look->m); +#ifdef TRAIN + { + int j; + FILE *of; + char buffer[80]; + sprintf(buffer,"lsp0coeff_%d.vqd",vb->mode); + of=fopen(buffer,"a"); + for(j=0;j<look->m;j++) + fprintf(of,"%g, ",out[j]); + fprintf(of,"\n"); + fclose(of); + } +#endif + /* code the spectral envelope, and keep track of the actual quantized values; we don't want creeping error as each block is nailed to the last quantized value of the previous block. */ diff --git a/lib/mapping0.c b/lib/mapping0.c index 58f6f13b..df36ce50 100644 --- a/lib/mapping0.c +++ b/lib/mapping0.c @@ -12,7 +12,7 @@ ******************************************************************** function: channel mapping 0 implementation - last mod: $Id: mapping0.c,v 1.8 2000/02/09 22:04:14 xiphmont Exp $ + last mod: $Id: mapping0.c,v 1.9 2000/02/12 08:33:06 xiphmont Exp $ ********************************************************************/ @@ -190,7 +190,6 @@ static int forward(vorbis_block *vb,vorbis_look_mapping *l){ double *window=vd->window[vb->W][vb->lW][vb->nW][mode->windowtype]; double **pcmbundle=alloca(sizeof(double *)*vi->channels); - int **auxbundle=alloca(sizeof(int *)*vi->channels); int *nonzero=alloca(sizeof(int)*vi->channels); /* time domain pre-window: NONE IMPLEMENTED */ @@ -216,19 +215,17 @@ static int forward(vorbis_block *vb,vorbis_look_mapping *l){ double *decfloor=_vorbis_block_alloc(vb,n*sizeof(double)/2); double *floor=_vorbis_block_alloc(vb,n*sizeof(double)/2); double *mask=_vorbis_block_alloc(vb,n*sizeof(double)/2); - int **pcmaux=_vorbis_block_alloc(vb,vi->channels*sizeof(int *)); for(i=0;i<vi->channels;i++){ double *pcm=vb->pcm[i]; int submap=map->chmuxlist[i]; - pcmaux[i]=_vorbis_block_alloc(vb,n/2*sizeof(int)); - /* perform psychoacoustics; takes PCM vector; returns two curves: the desired transform floor and the masking curve */ memset(floor,0,sizeof(double)*n/2); memset(mask,0,sizeof(double)*n/2); - _vp_mask_floor(look->psy_look+submap,pcm,mask,floor); + _vp_mask_floor(look->psy_look+submap,pcm,floor,0); + _vp_mask_floor(look->psy_look+submap,pcm,mask,1); /* perform floor encoding; takes transform floor, returns decoded floor */ nonzero[i]=look->floor_func[submap]-> @@ -236,12 +233,28 @@ static int forward(vorbis_block *vb,vorbis_look_mapping *l){ /* no iterative residue/floor tuning at the moment */ - /* perform residue prequantization. Do it now so we have all - the values if we need them */ - _vp_quantize(look->psy_look+submap,pcm,mask,decfloor,pcmaux[i],0,n/2,n/2); - +#ifdef TRAIN + if(nonzero[i]){ + FILE *of; + char buffer[80]; + + sprintf(buffer,"masked_%d.vqd",vb->mode); + of=fopen(buffer,"a"); + for(i=0;i<n/2;i++) + fprintf(of,"%g, ",pcm[i]/mask[i]); + fprintf(of,"\n"); + fclose(of); + sprintf(buffer,"floored_%d.vqd",vb->mode); + of=fopen(buffer,"a"); + for(i=0;i<n/2;i++) + fprintf(of,"%g, ",pcm[i]/floor[i]); + fprintf(of,"\n"); + fclose(of); + } +#endif + } - + /* perform residue encoding with residue mapping; this is multiplexed. All the channels belonging to one submap are encoded (values interleaved), then the next submap, etc */ @@ -251,12 +264,11 @@ static int forward(vorbis_block *vb,vorbis_look_mapping *l){ for(j=0;j<vi->channels;j++){ if(map->chmuxlist[j]==i && nonzero[j]==1){ pcmbundle[ch_in_bundle]=vb->pcm[j]; - auxbundle[ch_in_bundle++]=pcmaux[j]; } } - look->residue_func[i]->forward(vb,look->residue_look[i],pcmbundle,auxbundle, - ch_in_bundle); + look->residue_func[i]->forward(vb,look->residue_look[i], + pcmbundle,ch_in_bundle); } } @@ -12,7 +12,7 @@ ******************************************************************** function: psychoacoustics not including preecho - last mod: $Id: psy.c,v 1.15 2000/02/06 13:39:44 xiphmont Exp $ + last mod: $Id: psy.c,v 1.16 2000/02/12 08:33:07 xiphmont Exp $ ********************************************************************/ @@ -84,18 +84,18 @@ void _vp_psy_clear(vorbis_look_psy *p){ /* Masking curve: linear rolloff on a Bark/dB scale, attenuated by maskthresh */ -/* right now, floor==mask */ -void _vp_mask_floor(vorbis_look_psy *p,double *f, double *mask,double *floor){ + +void _vp_mask_floor(vorbis_look_psy *p,double *f, double *floor,int attp){ int n=p->n; double hroll=p->vi->hrolldB; double lroll=p->vi->lrolldB; - double curmask=todB(f[0])+p->maskthresh[0]; + double curmask=todB(f[0])+(attp?p->maskthresh[0]:0); double curoc=0.; long i; /* run mask forward then backward */ for(i=0;i<n;i++){ - double newmask=todB(f[i])+p->maskthresh[i]; + double newmask=todB(f[i])+(attp?p->maskthresh[i]:0); double newoc=p->barknum[i]; double roll=curmask-(newoc-curoc)*hroll; double troll; @@ -104,14 +104,13 @@ void _vp_mask_floor(vorbis_look_psy *p,double *f, double *mask,double *floor){ curoc=newoc; } troll=fromdB(roll); - if(mask[i]<troll)mask[i]=troll; if(floor[i]<troll)floor[i]=troll; } - curmask=todB(f[n-1])+p->maskthresh[n-1]; + curmask=todB(f[n-1])+(attp?p->maskthresh[n-1]:0); curoc=p->barknum[n-1]; for(i=n-1;i>=0;i--){ - double newmask=todB(f[i])+p->maskthresh[i]; + double newmask=todB(f[i])+(attp?p->maskthresh[i]:0); double newoc=p->barknum[i]; double roll=curmask-(curoc-newoc)*lroll; double troll; @@ -120,34 +119,10 @@ void _vp_mask_floor(vorbis_look_psy *p,double *f, double *mask,double *floor){ curoc=newoc; } troll=fromdB(roll); - if(mask[i]<troll)mask[i]=troll; if(floor[i]<troll)floor[i]=troll; } } -/* take a masking curve and raw residue; eliminate the inaduble and - quantize to the final form handed to the VQ. All and any tricks to - squeeze out bits given knowledge of the encoding mode should go - here too */ - -/* modifies the pcm vector, returns book membership in aux */ - -void _vp_quantize(vorbis_look_psy *p, double *pcm, double *mask, - double *floor,int *aux,long begin, long n,long subn){ - long i,j; - /* for now, we're not worrying about subvector, but the idea is - that we normal blocks not have zeroes; zeroes only exist as an - all-zero block */ - - for(i=begin;i<n;i++){ - double value=rint(pcm[i]/floor[i]); - if(value>15)value=15; - if(value<-15)value=-15; - pcm[i]=value; - } - -} - /* s must be padded at the end with m-1 zeroes */ static void time_convolve(double *s,double *r,int n,int m){ int i; @@ -12,7 +12,7 @@ ******************************************************************** function: random psychoacoustics (not including preecho) - last mod: $Id: psy.h,v 1.10 2000/02/06 13:39:45 xiphmont Exp $ + last mod: $Id: psy.h,v 1.11 2000/02/12 08:33:08 xiphmont Exp $ ********************************************************************/ @@ -26,13 +26,6 @@ typedef struct { double *maskthresh; double *barknum; - int framebegin; - int frameend; - int subframelen; - int elements[4]; - double cutoffs[4]; - int quantval[4]; - } vorbis_look_psy; extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,int n,long rate); @@ -40,11 +33,8 @@ extern void _vp_psy_clear(vorbis_look_psy *p); extern void *_vi_psy_dup(void *source); extern void _vi_psy_free(vorbis_info_psy *i); -extern void _vp_mask_floor(vorbis_look_psy *p,double *pcm, - double *mask,double *floor); -extern void _vp_quantize(vorbis_look_psy *p, double *pcm, double *mask, - double *floor,int *aux, - long begin,long n, long subn); +extern void _vp_mask_floor(vorbis_look_psy *p,double *pcm,double *floor, + int attp); #endif @@ -12,42 +12,106 @@ ******************************************************************** function: residue backend 0 implementation - last mod: $Id: res0.c,v 1.4 2000/02/06 13:39:46 xiphmont Exp $ + last mod: $Id: res0.c,v 1.5 2000/02/12 08:33:09 xiphmont Exp $ ********************************************************************/ #include <stdlib.h> #include <string.h> #include <math.h> +#include <stdio.h> #include "vorbis/codec.h" #include "bitwise.h" #include "registry.h" +#include "scales.h" -/* unfinished as of 20000118 */ +typedef struct { + vorbis_info_residue0 *info; + int bookpointers[64]; +} vorbis_look_residue0; void free_info(vorbis_info_residue *i){ + if(i){ + memset(i,0,sizeof(vorbis_info_residue0)); + free(i); + } } void free_look(vorbis_look_residue *i){ + if(i){ + memset(i,0,sizeof(vorbis_look_residue0)); + free(i); + } } /* not yet */ void pack(vorbis_info_residue *vr,oggpack_buffer *opb){ + vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr; + int j,acc=0; + _oggpack_write(opb,info->begin,24); + _oggpack_write(opb,info->end,24); + + _oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and + code with a partitioned book */ + _oggpack_write(opb,info->partitions-1,6); /* possible partition choices */ + _oggpack_write(opb,info->groupspercode-1,6); /* partitioned group + codes to encode at + once */ + _oggpack_write(opb,info->groupbook,8); /* group huffman book */ + for(j=0;j<info->partitions;j++){ + _oggpack_write(opb,info->secondstages[j],4); /* zero *is* a valid choice */ + acc+=info->secondstages[j]; + } + for(j=0;j<acc;j++) + _oggpack_write(opb,info->booklist[j],8); + } /* vorbis_info is for range checking */ vorbis_info_residue *unpack(vorbis_info *vi,oggpack_buffer *opb){ - return ""; + int j,acc=0; + vorbis_info_residue0 *ret=calloc(1,sizeof(vorbis_info_residue0)); + + ret->begin=_oggpack_read(opb,24); + ret->end=_oggpack_read(opb,24); + ret->grouping=_oggpack_read(opb,24)+1; + ret->partitions=_oggpack_read(opb,6)+1; + ret->groupspercode=_oggpack_read(opb,6)+1; + ret->groupbook=_oggpack_read(opb,8); + for(j=0;j<ret->partitions;j++) + acc+=ret->secondstages[j]=_oggpack_read(opb,4); + for(j=0;j<acc;j++) + ret->booklist[j]=_oggpack_read(opb,8); + + if(ret->groupbook>=vi->books)goto errout; + for(j=0;j<acc;j++) + if(ret->booklist[j]>=vi->books)goto errout; + + return(ret); + errout: + free_info(ret); + return(NULL); } vorbis_look_residue *look (vorbis_info *vi,vorbis_info_mode *vm, vorbis_info_residue *vr){ - return ""; + vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr; + vorbis_look_residue0 *look=calloc(1,sizeof(vorbis_look_residue0)); + int j,acc=0; + look->info=info; + for(j=0;j<info->partitions;j++){ + look->bookpointers[j]=acc; + acc+=info->secondstages[j]; + } + + return(look); } int forward(vorbis_block *vb,vorbis_look_residue *l, - double **in,int **aux,int ch){ + double **in,int ch){ long i,j; + vorbis_look_residue0 *look=(vorbis_look_residue0 *)l; + vorbis_info_residue0 *info=look->info; for(i=0;i<ch;i++) for(j=0;j<vb->pcmend/2;j++) _oggpack_write(&vb->opb,rint(in[i][j])+16,5); diff --git a/lib/synthesis.c b/lib/synthesis.c index 3947f23c..031d6cd4 100644 --- a/lib/synthesis.c +++ b/lib/synthesis.c @@ -12,7 +12,7 @@ ******************************************************************** function: single-block PCM synthesis - last mod: $Id: synthesis.c,v 1.14 2000/01/22 13:28:33 xiphmont Exp $ + last mod: $Id: synthesis.c,v 1.15 2000/02/12 08:33:10 xiphmont Exp $ ********************************************************************/ @@ -40,6 +40,7 @@ int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){ /* read our mode and pre/post windowsize */ mode=_oggpack_read(opb,vd->modebits); + vb->mode=mode; vb->W=vi->mode_param[mode]->blockflag; if(vb->W){ vb->lW=_oggpack_read(opb,1); |
