examples/SFExamples/oggvorbiscodec94/src/libvorbis/lib/analysis.c

00001 /********************************************************************
00002  *                                                                  *
00003  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
00004  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
00005  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
00006  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
00007  *                                                                  *
00008  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
00009  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
00010  *                                                                  *
00011  ********************************************************************
00012 
00013  function: single-block PCM analysis mode dispatch
00014  last mod: $Id: analysis.c 7187 2004-07-20 07:24:27Z xiphmont $
00015 
00016  ********************************************************************/
00017 
00018 #include <stdio.h>
00019 #include <string.h>
00020 #include <math.h>
00021 #include "ogg/ogg.h"
00022 #include "vorbis/codec.h"
00023 #include "codec_internal.h"
00024 #include "registry.h"
00025 #include "scales.h"
00026 #include "os.h"
00027 #include "misc.h"
00028 
00029 int analysis_noisy=1;
00030 
00031 /* decides between modes, dispatches to the appropriate mapping. */
00032 int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
00033   int ret,i;
00034   vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
00035 
00036   vb->glue_bits=0;
00037   vb->time_bits=0;
00038   vb->floor_bits=0;
00039   vb->res_bits=0;
00040 
00041   /* first things first.  Make sure encode is ready */
00042   for(i=0;i<PACKETBLOBS;i++)
00043     oggpack_reset(vbi->packetblob[i]);
00044   
00045   /* we only have one mapping type (0), and we let the mapping code
00046      itself figure out what soft mode to use.  This allows easier
00047      bitrate management */
00048   ret=_mapping_P[0]->forward(vb);       
00049   if(ret)
00050     return(ret);
00051 
00052   if(op){
00053     if(vorbis_bitrate_managed(vb))
00054       /* The app is using a bitmanaged mode... but not using the
00055          bitrate management interface. */
00056       return(OV_EINVAL);
00057     
00058     op->packet=oggpack_get_buffer(&vb->opb);
00059     op->bytes=oggpack_bytes(&vb->opb);
00060     op->b_o_s=0;
00061     op->e_o_s=vb->eofflag;
00062     op->granulepos=vb->granulepos;
00063     op->packetno=vb->sequence; /* for sake of completeness */
00064   }
00065   return(0);
00066 }
00067 
00068 /* there was no great place to put this.... */
00069 void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
00070   int j;
00071   FILE *of;
00072   char buffer[80];
00073 
00074   /*  if(i==5870){*/
00075     sprintf(buffer,"%s_%d.m",base,i);
00076     of=fopen(buffer,"w");
00077     
00078     if(!of)perror("failed to open data dump file");
00079     
00080     for(j=0;j<n;j++){
00081       if(bark){
00082         float b=toBARK((4000.f*j/n)+.25);
00083         fprintf(of,"%f ",b);
00084       }else
00085         if(off!=0)
00086           fprintf(of,"%f ",(double)(j+off)/8000.);
00087         else
00088           fprintf(of,"%f ",(double)j);
00089       
00090       if(dB){
00091         float val;
00092         if(v[j]==0.)
00093           val=-140.;
00094         else
00095           val=todB(v+j);
00096         fprintf(of,"%f\n",val);
00097       }else{
00098         fprintf(of,"%f\n",v[j]);
00099       }
00100     }
00101     fclose(of);
00102     /*  } */
00103 }
00104 
00105 void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
00106                       ogg_int64_t off){
00107   if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
00108 }
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 

Generated by  doxygen 1.6.2