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