1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
5 * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
6 * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
8 * THE OggVorbis 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: single-block PCM analysis mode dispatch
15 last mod: $Id: analysis.c,v 1.38 2000/11/14 00:05:30 xiphmont Exp $
17 ********************************************************************/
23 #include "vorbis/codec.h"
28 /* decides between modes, dispatches to the appropriate mapping. */
29 int vorbis_analysis(vorbis_block *vb,ogg_packet *op){
30 vorbis_dsp_state *vd=vb->vd;
31 backend_lookup_state *b=vd->backend_state;
32 vorbis_info *vi=vd->vi;
33 codec_setup_info *ci=vi->codec_setup;
42 /* first things first. Make sure encode is ready */
43 oggpack_reset(&vb->opb);
44 /* Encode the packet type */
45 oggpack_write(&vb->opb,0,1);
47 /* currently lazy. Short block dispatches to 0, long to 1. */
49 if(vb->W &&ci->modes>1)mode=1;
50 type=ci->map_type[ci->mode_param[mode]->mapping];
53 /* Encode frame mode, pre,post windowsize, then dispatch */
54 oggpack_write(&vb->opb,mode,b->modebits);
56 oggpack_write(&vb->opb,vb->lW,1);
57 oggpack_write(&vb->opb,vb->nW,1);
63 if((ret=_mapping_P[type]->forward(vb,b->mode[mode])))
66 /* set up the packet wrapper */
68 op->packet=oggpack_get_buffer(&vb->opb);
69 op->bytes=oggpack_bytes(&vb->opb);
71 op->e_o_s=vb->eofflag;
72 op->granulepos=vb->granulepos;
73 op->packetno=vb->sequence; /* for sake of completeness */
78 /* there was no great place to put this.... */
79 void _analysis_output(char *base,int i,float *v,int n,int bark,int dB){
84 sprintf(buffer,"%s_%d.m",base,i);
87 if(!of)perror("failed to open data dump file");
94 fprintf(of,"%g ",toBARK(22050.*j/n));
96 fprintf(of,"%g ",(double)j);
99 fprintf(of,"%g\n",todB(fabs(v[j])));
101 fprintf(of,"%g\n",v[j]);