vrshoot

annotate libs/vorbis/analysis.c @ 2:334d17aed7de

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