faceac34ba434127f22b7c2c35a79ca6ca7964cf
[platform/upstream/libvorbis.git] / lib / analysis.c
1 /********************************************************************
2  *                                                                  *
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.                            *
7  *                                                                  *
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/                                             *
11  *                                                                  *
12  ********************************************************************
13
14  function: single-block PCM analysis mode dispatch
15  last mod: $Id: analysis.c,v 1.22 2000/01/22 13:28:14 xiphmont Exp $
16
17  ********************************************************************/
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <math.h>
22 #include "vorbis/codec.h"
23 #include "bitwise.h"
24 #include "registry.h"
25
26 /* decides between modes, dispatches to the appropriate mapping. */
27 int vorbis_analysis(vorbis_block *vb,ogg_packet *op){
28   vorbis_dsp_state *vd=vb->vd;
29   vorbis_info      *vi=vd->vi;
30   int              type;
31   int              mode=0;
32
33   vb->glue_bits=0;
34   vb->time_bits=0;
35   vb->floor_bits=0;
36   vb->res_bits=0;
37
38   /* first things first.  Make sure encode is ready */
39   _oggpack_reset(&vb->opb);
40   /* Encode the packet type */
41   _oggpack_write(&vb->opb,0,1);
42
43   /* currently lazy.  Short block dispatches to 0, long to 1. */
44
45   if(vb->W &&vi->modes>1)mode=1;
46   type=vi->map_type[vi->mode_param[mode]->mapping];
47
48   /* Encode frame mode, pre,post windowsize, then dispatch */
49   _oggpack_write(&vb->opb,mode,vd->modebits);
50   if(vb->W){
51     _oggpack_write(&vb->opb,vb->lW,1);
52     _oggpack_write(&vb->opb,vb->nW,1);
53   }
54
55   if(_mapping_P[type]->forward(vb,vd->mode[mode]))
56     return(-1);
57
58   /* set up the packet wrapper */
59
60   op->packet=_oggpack_buffer(&vb->opb);
61   op->bytes=_oggpack_bytes(&vb->opb);
62   op->b_o_s=0;
63   op->e_o_s=vb->eofflag;
64   op->frameno=vb->frameno;
65   op->packetno=vb->sequence; /* for sake of completeness */
66
67   return(0);
68 }