dbf-halloween2015

view libs/vorbis/analysis.c @ 1:c3f5c32cb210

barfed all the libraries in the source tree to make porting easier
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Nov 2015 00:36:56 +0200
parents
children
line source
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 ********************************************************************
13 function: single-block PCM analysis mode dispatch
14 last mod: $Id: analysis.c 16226 2009-07-08 06:43:49Z xiphmont $
16 ********************************************************************/
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"
29 /* decides between modes, dispatches to the appropriate mapping. */
30 int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
31 int ret,i;
32 vorbis_block_internal *vbi=vb->internal;
34 vb->glue_bits=0;
35 vb->time_bits=0;
36 vb->floor_bits=0;
37 vb->res_bits=0;
39 /* first things first. Make sure encode is ready */
40 for(i=0;i<PACKETBLOBS;i++)
41 oggpack_reset(vbi->packetblob[i]);
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 */
47 if((ret=_mapping_P[0]->forward(vb)))
48 return(ret);
50 if(op){
51 if(vorbis_bitrate_managed(vb))
52 /* The app is using a bitmanaged mode... but not using the
53 bitrate management interface. */
54 return(OV_EINVAL);
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 }
66 #ifdef ANALYSIS
67 int analysis_noisy=1;
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];
75 sprintf(buffer,"%s_%d.m",base,i);
76 of=fopen(buffer,"w");
78 if(!of)perror("failed to open data dump file");
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);
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 }
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 }
109 #endif