dbf-halloween2015

diff libs/vorbis/analysis.c @ 1:c3f5c32cb210

barfed all the libraries in the source tree to make porting easier
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 01 Nov 2015 00:36:56 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vorbis/analysis.c	Sun Nov 01 00:36:56 2015 +0200
     1.3 @@ -0,0 +1,120 @@
     1.4 +/********************************************************************
     1.5 + *                                                                  *
     1.6 + * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
     1.7 + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
     1.8 + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
     1.9 + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
    1.10 + *                                                                  *
    1.11 + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007             *
    1.12 + * by the Xiph.Org Foundation http://www.xiph.org/                  *
    1.13 + *                                                                  *
    1.14 + ********************************************************************
    1.15 +
    1.16 + function: single-block PCM analysis mode dispatch
    1.17 + last mod: $Id: analysis.c 16226 2009-07-08 06:43:49Z xiphmont $
    1.18 +
    1.19 + ********************************************************************/
    1.20 +
    1.21 +#include <stdio.h>
    1.22 +#include <string.h>
    1.23 +#include <math.h>
    1.24 +#include <ogg/ogg.h>
    1.25 +#include "vorbis/codec.h"
    1.26 +#include "codec_internal.h"
    1.27 +#include "registry.h"
    1.28 +#include "scales.h"
    1.29 +#include "os.h"
    1.30 +#include "misc.h"
    1.31 +
    1.32 +/* decides between modes, dispatches to the appropriate mapping. */
    1.33 +int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
    1.34 +  int ret,i;
    1.35 +  vorbis_block_internal *vbi=vb->internal;
    1.36 +
    1.37 +  vb->glue_bits=0;
    1.38 +  vb->time_bits=0;
    1.39 +  vb->floor_bits=0;
    1.40 +  vb->res_bits=0;
    1.41 +
    1.42 +  /* first things first.  Make sure encode is ready */
    1.43 +  for(i=0;i<PACKETBLOBS;i++)
    1.44 +    oggpack_reset(vbi->packetblob[i]);
    1.45 +
    1.46 +  /* we only have one mapping type (0), and we let the mapping code
    1.47 +     itself figure out what soft mode to use.  This allows easier
    1.48 +     bitrate management */
    1.49 +
    1.50 +  if((ret=_mapping_P[0]->forward(vb)))
    1.51 +    return(ret);
    1.52 +
    1.53 +  if(op){
    1.54 +    if(vorbis_bitrate_managed(vb))
    1.55 +      /* The app is using a bitmanaged mode... but not using the
    1.56 +         bitrate management interface. */
    1.57 +      return(OV_EINVAL);
    1.58 +
    1.59 +    op->packet=oggpack_get_buffer(&vb->opb);
    1.60 +    op->bytes=oggpack_bytes(&vb->opb);
    1.61 +    op->b_o_s=0;
    1.62 +    op->e_o_s=vb->eofflag;
    1.63 +    op->granulepos=vb->granulepos;
    1.64 +    op->packetno=vb->sequence; /* for sake of completeness */
    1.65 +  }
    1.66 +  return(0);
    1.67 +}
    1.68 +
    1.69 +#ifdef ANALYSIS
    1.70 +int analysis_noisy=1;
    1.71 +
    1.72 +/* there was no great place to put this.... */
    1.73 +void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
    1.74 +  int j;
    1.75 +  FILE *of;
    1.76 +  char buffer[80];
    1.77 +
    1.78 +  sprintf(buffer,"%s_%d.m",base,i);
    1.79 +  of=fopen(buffer,"w");
    1.80 +
    1.81 +  if(!of)perror("failed to open data dump file");
    1.82 +
    1.83 +  for(j=0;j<n;j++){
    1.84 +    if(bark){
    1.85 +      float b=toBARK((4000.f*j/n)+.25);
    1.86 +      fprintf(of,"%f ",b);
    1.87 +    }else
    1.88 +      if(off!=0)
    1.89 +        fprintf(of,"%f ",(double)(j+off)/8000.);
    1.90 +      else
    1.91 +        fprintf(of,"%f ",(double)j);
    1.92 +
    1.93 +    if(dB){
    1.94 +      float val;
    1.95 +      if(v[j]==0.)
    1.96 +        val=-140.;
    1.97 +      else
    1.98 +        val=todB(v+j);
    1.99 +      fprintf(of,"%f\n",val);
   1.100 +    }else{
   1.101 +      fprintf(of,"%f\n",v[j]);
   1.102 +    }
   1.103 +  }
   1.104 +  fclose(of);
   1.105 +}
   1.106 +
   1.107 +void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
   1.108 +                      ogg_int64_t off){
   1.109 +  if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
   1.110 +}
   1.111 +
   1.112 +#endif
   1.113 +
   1.114 +
   1.115 +
   1.116 +
   1.117 +
   1.118 +
   1.119 +
   1.120 +
   1.121 +
   1.122 +
   1.123 +