annotate src/libvorbis-1.3.3/lib/analysis.c @ 83:ae30d91d2ffe

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