vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

analysis.c (3057B)


      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-2002             *
      9  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
     10  *                                                                  *
     11  ********************************************************************
     12 
     13  function: single-block PCM analysis mode dispatch
     14  last mod: $Id: analysis.c 1919 2005-07-24 14:18:04Z baford $
     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 int analysis_noisy=1;
     30 
     31 /* decides between modes, dispatches to the appropriate mapping. */
     32 int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
     33   int                   ret;
     34 
     35   vb->glue_bits=0;
     36   vb->time_bits=0;
     37   vb->floor_bits=0;
     38   vb->res_bits=0;
     39 
     40   /* first things first.  Make sure encode is ready */
     41   oggpack_reset(&vb->opb);
     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 /* there was no great place to put this.... */
     67 void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
     68   int j;
     69   FILE *of;
     70   char buffer[80];
     71 
     72   /*  if(i==5870){*/
     73     sprintf(buffer,"%s_%d.m",base,i);
     74     of=fopen(buffer,"w");
     75     
     76     if(!of)perror("failed to open data dump file");
     77     
     78     for(j=0;j<n;j++){
     79       if(bark){
     80 	float b=toBARK((4000.f*j/n)+.25);
     81 	fprintf(of,"%f ",b);
     82       }else
     83 	if(off!=0)
     84 	  fprintf(of,"%f ",(double)(j+off)/8000.);
     85 	else
     86 	  fprintf(of,"%f ",(double)j);
     87       
     88       if(dB){
     89 	float val;
     90 	if(v[j]==0.)
     91 	  val=-140.;
     92 	else
     93 	  val=todB(v+j);
     94 	fprintf(of,"%f\n",val);
     95       }else{
     96 	fprintf(of,"%f\n",v[j]);
     97       }
     98     }
     99     fclose(of);
    100     /*  } */
    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 
    109 
    110 
    111 
    112 
    113 
    114 
    115 
    116 
    117 
    118 
    119