Mercurial > hg > sv-dependency-builds
comparison src/libvorbis-1.3.3/lib/analysis.c @ 1:05aa0afa9217
Bring in flac, ogg, vorbis
| author | Chris Cannam |
|---|---|
| date | Tue, 19 Mar 2013 17:37:49 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:c7265573341e | 1:05aa0afa9217 |
|---|---|
| 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. */ | |
| 30 int vorbis_analysis(vorbis_block *vb, ogg_packet *op){ | |
| 31 int ret,i; | |
| 32 vorbis_block_internal *vbi=vb->internal; | |
| 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){ | |
| 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); | |
| 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 |
