dbf-halloween2015

annotate libs/vorbis/analysis.c @ 3:c37fe5d8a4ed

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