Collect training data from the lib when compiled with -DTRAIN
[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.23 2000/02/12 08:33:04 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   vb->mode=mode;
48
49   /* Encode frame mode, pre,post windowsize, then dispatch */
50   _oggpack_write(&vb->opb,mode,vd->modebits);
51   if(vb->W){
52     _oggpack_write(&vb->opb,vb->lW,1);
53     _oggpack_write(&vb->opb,vb->nW,1);
54   }
55
56   if(_mapping_P[type]->forward(vb,vd->mode[mode]))
57     return(-1);
58
59   /* set up the packet wrapper */
60
61   op->packet=_oggpack_buffer(&vb->opb);
62   op->bytes=_oggpack_bytes(&vb->opb);
63   op->b_o_s=0;
64   op->e_o_s=vb->eofflag;
65   op->frameno=vb->frameno;
66   op->packetno=vb->sequence; /* for sake of completeness */
67
68   return(0);
69 }