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 13293 2007-07-24 00:09:47Z 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 | int analysis_noisy=1; |
---|
30 | |
---|
31 | /* decides between modes, dispatches to the appropriate mapping. */ |
---|
32 | int vorbis_analysis(vorbis_block *vb, ogg_packet *op){ |
---|
33 | int ret,i; |
---|
34 | vorbis_block_internal *vbi=vb->internal; |
---|
35 | |
---|
36 | vb->glue_bits=0; |
---|
37 | vb->time_bits=0; |
---|
38 | vb->floor_bits=0; |
---|
39 | vb->res_bits=0; |
---|
40 | |
---|
41 | /* first things first. Make sure encode is ready */ |
---|
42 | for(i=0;i<PACKETBLOBS;i++) |
---|
43 | oggpack_reset(vbi->packetblob[i]); |
---|
44 | |
---|
45 | /* we only have one mapping type (0), and we let the mapping code |
---|
46 | itself figure out what soft mode to use. This allows easier |
---|
47 | bitrate management */ |
---|
48 | |
---|
49 | if((ret=_mapping_P[0]->forward(vb))) |
---|
50 | return(ret); |
---|
51 | |
---|
52 | if(op){ |
---|
53 | if(vorbis_bitrate_managed(vb)) |
---|
54 | /* The app is using a bitmanaged mode... but not using the |
---|
55 | bitrate management interface. */ |
---|
56 | return(OV_EINVAL); |
---|
57 | |
---|
58 | op->packet=oggpack_get_buffer(&vb->opb); |
---|
59 | op->bytes=oggpack_bytes(&vb->opb); |
---|
60 | op->b_o_s=0; |
---|
61 | op->e_o_s=vb->eofflag; |
---|
62 | op->granulepos=vb->granulepos; |
---|
63 | op->packetno=vb->sequence; /* for sake of completeness */ |
---|
64 | } |
---|
65 | return(0); |
---|
66 | } |
---|
67 | |
---|
68 | /* there was no great place to put this.... */ |
---|
69 | void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){ |
---|
70 | int j; |
---|
71 | FILE *of; |
---|
72 | char buffer[80]; |
---|
73 | |
---|
74 | /* if(i==5870){*/ |
---|
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 | |
---|
105 | void _analysis_output(char *base,int i,float *v,int n,int bark,int dB, |
---|
106 | ogg_int64_t off){ |
---|
107 | if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off); |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | |
---|
121 | |
---|