zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
analysis.c
Go to the documentation of this file.
1 /********************************************************************
2  * *
3  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
4  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
5  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
6  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
7  * *
8  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
9  * by the Xiph.Org Foundation http://www.xiph.org/ *
10  * *
11  ********************************************************************
12 
13  function: single-block PCM analysis mode dispatch
14  last mod: $Id: analysis.c 16226 2009-07-08 06:43:49Z xiphmont $
15 
16  ********************************************************************/
17 
18 #include <stdio.h>
19 #include <string.h>
20 #include <math.h>
21 #include <ogg/ogg.h>
22 #include "vorbis/codec.h"
23 #include "codec_internal.h"
24 #include "registry.h"
25 #include "scales.h"
26 #include "os.h"
27 #include "misc.h"
28 
29 /* decides between modes, dispatches to the appropriate mapping. */
31  int ret,i;
33 
34  vb->glue_bits=0;
35  vb->time_bits=0;
36  vb->floor_bits=0;
37  vb->res_bits=0;
38 
39  /* first things first. Make sure encode is ready */
40  for(i=0;i<PACKETBLOBS;i++)
41  oggpack_reset(vbi->packetblob[i]);
42 
43  /* we only have one mapping type (0), and we let the mapping code
44  itself figure out what soft mode to use. This allows easier
45  bitrate management */
46 
47  if((ret=_mapping_P[0]->forward(vb)))
48  return(ret);
49 
50  if(op){
52  /* The app is using a bitmanaged mode... but not using the
53  bitrate management interface. */
54  return(OV_EINVAL);
55 
56  op->packet=oggpack_get_buffer(&vb->opb);
57  op->bytes=oggpack_bytes(&vb->opb);
58  op->b_o_s=0;
59  op->e_o_s=vb->eofflag;
60  op->granulepos=vb->granulepos;
61  op->packetno=vb->sequence; /* for sake of completeness */
62  }
63  return(0);
64 }
65 
66 #ifdef ANALYSIS
67 int analysis_noisy=1;
68 
69 /* there was no great place to put this.... */
70 void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
71  int j;
72  FILE *of;
73  char buffer[80];
74 
75  sprintf(buffer,"%s_%d.m",base,i);
76  of=fopen(buffer,"w");
77 
78  if(!of)perror("failed to open data dump file");
79 
80  for(j=0;j<n;j++){
81  if(bark){
82  float b=toBARK((4000.f*j/n)+.25);
83  fprintf(of,"%f ",b);
84  }else
85  if(off!=0)
86  fprintf(of,"%f ",(double)(j+off)/8000.);
87  else
88  fprintf(of,"%f ",(double)j);
89 
90  if(dB){
91  float val;
92  if(v[j]==0.)
93  val=-140.;
94  else
95  val=todB(v+j);
96  fprintf(of,"%f\n",val);
97  }else{
98  fprintf(of,"%f\n",v[j]);
99  }
100  }
101  fclose(of);
102 }
103 
104 void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
105  ogg_int64_t off){
106  if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
107 }
108 
109 #endif
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
long glue_bits
Definition: codec.h:113
#define PACKETBLOBS
GLuint const GLfloat * val
Definition: glew.h:2715
oggpack_buffer opb
Definition: codec.h:91
GLclampf f
Definition: glew.h:3390
GLclampd n
Definition: glew.h:7287
Definition: ogg.h:90
int32_t j
Definition: e_log.c:102
#define OV_EINVAL
Definition: codec.h:229
int vorbis_analysis(vorbis_block *vb, ogg_packet *op)
Definition: analysis.c:30
ret
Definition: glew_str_glx.c:2
EGLContext EGLenum EGLClientBuffer buffer
Definition: eglext.h:87
const GLdouble * v
Definition: glew.h:1377
static float todB(const float *x)
Definition: scales.h:44
long bytes
Definition: ogg.h:92
oggpack_buffer * packetblob[PACKETBLOBS]
int vorbis_bitrate_managed(vorbis_block *vb)
Definition: bitrate.c:64
#define toBARK(n)
Definition: scales.h:79
unsigned char * packet
Definition: ogg.h:91
long floor_bits
Definition: codec.h:115
long b_o_s
Definition: ogg.h:93
long time_bits
Definition: codec.h:114
int eofflag
Definition: codec.h:99
ogg_int64_t granulepos
Definition: codec.h:100
long oggpack_bytes(oggpack_buffer *b)
Definition: bitwise.c:499
ogg_int64_t granulepos
Definition: ogg.h:96
void oggpack_reset(oggpack_buffer *b)
Definition: bitwise.c:235
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
unsigned char * oggpack_get_buffer(oggpack_buffer *b)
Definition: bitwise.c:515
long res_bits
Definition: codec.h:116
int i
Definition: pngrutil.c:1377
const vorbis_func_mapping *const _mapping_P[]
Definition: registry.c:43
void * internal
Definition: codec.h:118
ogg_int64_t sequence
Definition: codec.h:101
long e_o_s
Definition: ogg.h:94
long ogg_int64_t
Definition: config_types.h:23
ogg_int64_t packetno
Definition: ogg.h:98