1 /********************************************************************
3 * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
6 * PLEASE READ THESE TERMS DISTRIBUTING. *
8 * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
9 * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
10 * http://www.xiph.org/ *
12 ********************************************************************
14 function: PCM data envelope analysis and manipulation
15 last mod: $Id: envelope.c,v 1.12 1999/12/30 07:26:36 xiphmont Exp $
19 ********************************************************************/
33 void _ve_envelope_init(envelope_lookup *e,int samples_per){
36 e->winlen=samples_per;
37 e->window=malloc(e->winlen*sizeof(double));
38 mdct_init(&e->mdct,e->winlen);
40 /* We just use a straight sin(x) window for this */
41 for(i=0;i<e->winlen;i++)
42 e->window[i]=sin((i+.5)/e->winlen*M_PI);
46 void _ve_envelope_clear(envelope_lookup *e){
47 if(e->window)free(e->window);
49 memset(e,0,sizeof(envelope_lookup));
52 /* use MDCT for spectral power estimation */
54 static void _ve_deltas(double *deltas,double *pcm,int n,double *window,
55 int winsize,mdct_lookup *m){
57 double *out=alloca(sizeof(double)*winsize/2);
62 mdct_forward(m,pcm+j*winsize,out,window);
63 for(i=winsize/10;i<winsize/2;i++)
65 if(deltas[j]<acc)deltas[j]=acc;
69 void _ve_envelope_deltas(vorbis_dsp_state *v){
70 vorbis_info *vi=v->vi;
71 int step=vi->envelopesa;
73 int dtotal=v->pcm_current/vi->envelopesa;
74 int dcurr=v->envelope_current;
78 double *mult=v->multipliers+dcurr;
79 memset(mult,0,sizeof(double)*(dtotal-dcurr));
81 for(pch=0;pch<vi->channels;pch++){
82 double *pcm=v->pcm[pch]+dcurr*step;
83 _ve_deltas(mult,pcm,dtotal-dcurr,v->ve.window,v->ve.winlen,&v->ve.mdct);
85 v->envelope_current=dtotal;
94 sprintf(buffer,"delt%d.m",frameno);
95 out=fopen(buffer,"w+");
96 for(j=0;j<v->envelope_current;j++)
97 fprintf(out,"%d %g\n",j*vi->envelopesa+vi->envelopesa/2,v->multipliers[j]);
100 sprintf(buffer,"deltpcm%d.m",frameno++);
101 out=fopen(buffer,"w+");
102 for(k=0;k<vi->channels;k++){
103 for(j=0;j<v->pcm_current;j++)
104 fprintf(out,"%d %g\n",j,v->pcm[k][j]);