vorbis_analysis.c (3088B)
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 https://xiph.org/ * 10 * * 11 ******************************************************************** 12 13 function: single-block PCM analysis mode dispatch 14 15 ********************************************************************/ 16 17 #include <stdio.h> 18 #include <string.h> 19 #include <math.h> 20 #include <ogg/ogg.h> 21 #include "vorbis/codec.h" 22 #include "codec_internal.h" 23 #include "registry.h" 24 #include "scales.h" 25 #include "os.h" 26 #include "misc.h" 27 28 /* decides between modes, dispatches to the appropriate mapping. */ 29 int vorbis_analysis(vorbis_block *vb, ogg_packet *op){ 30 int ret,i; 31 vorbis_block_internal *vbi=vb->internal; 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 for(i=0;i<PACKETBLOBS;i++) 40 oggpack_reset(vbi->packetblob[i]); 41 42 /* we only have one mapping type (0), and we let the mapping code 43 itself figure out what soft mode to use. This allows easier 44 bitrate management */ 45 46 if((ret=_mapping_P[0]->forward(vb))) 47 return(ret); 48 49 if(op){ 50 if(vorbis_bitrate_managed(vb)) 51 /* The app is using a bitmanaged mode... but not using the 52 bitrate management interface. */ 53 return(OV_EINVAL); 54 55 op->packet=oggpack_get_buffer(&vb->opb); 56 op->bytes=oggpack_bytes(&vb->opb); 57 op->b_o_s=0; 58 op->e_o_s=vb->eofflag; 59 op->granulepos=vb->granulepos; 60 op->packetno=vb->sequence; /* for sake of completeness */ 61 } 62 return(0); 63 } 64 65 #ifdef ANALYSIS 66 int analysis_noisy=1; 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 sprintf(buffer,"%s_%d.m",base,i); 75 of=fopen(buffer,"w"); 76 77 if(!of)perror("failed to open data dump file"); 78 79 for(j=0;j<n;j++){ 80 if(bark){ 81 float b=toBARK((4000.f*j/n)+.25); 82 fprintf(of,"%f ",b); 83 }else 84 if(off!=0) 85 fprintf(of,"%f ",(double)(j+off)/8000.); 86 else 87 fprintf(of,"%f ",(double)j); 88 89 if(dB){ 90 float val; 91 if(v[j]==0.) 92 val=-140.; 93 else 94 val=todB(v+j); 95 fprintf(of,"%f\n",val); 96 }else{ 97 fprintf(of,"%f\n",v[j]); 98 } 99 } 100 fclose(of); 101 } 102 103 void _analysis_output(char *base,int i,float *v,int n,int bark,int dB, 104 ogg_int64_t off){ 105 if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off); 106 } 107 108 #endif