analysis.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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-2007 *
  9. * by the Xiph.Org Foundation http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: single-block PCM analysis mode dispatch
  13. last mod: $Id$
  14. ********************************************************************/
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <math.h>
  18. #include <ogg/ogg.h>
  19. #include "vorbis/codec.h"
  20. #include "codec_internal.h"
  21. #include "registry.h"
  22. #include "scales.h"
  23. #include "os.h"
  24. #include "misc.h"
  25. int analysis_noisy=1;
  26. /* decides between modes, dispatches to the appropriate mapping. */
  27. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  28. int ret,i;
  29. vorbis_block_internal *vbi=vb->internal;
  30. vb->glue_bits=0;
  31. vb->time_bits=0;
  32. vb->floor_bits=0;
  33. vb->res_bits=0;
  34. /* first things first. Make sure encode is ready */
  35. for(i=0;i<PACKETBLOBS;i++)
  36. oggpack_reset(vbi->packetblob[i]);
  37. /* we only have one mapping type (0), and we let the mapping code
  38. itself figure out what soft mode to use. This allows easier
  39. bitrate management */
  40. if((ret=_mapping_P[0]->forward(vb)))
  41. return(ret);
  42. if(op){
  43. if(vorbis_bitrate_managed(vb))
  44. /* The app is using a bitmanaged mode... but not using the
  45. bitrate management interface. */
  46. return(OV_EINVAL);
  47. op->packet=oggpack_get_buffer(&vb->opb);
  48. op->bytes=oggpack_bytes(&vb->opb);
  49. op->b_o_s=0;
  50. op->e_o_s=vb->eofflag;
  51. op->granulepos=vb->granulepos;
  52. op->packetno=vb->sequence; /* for sake of completeness */
  53. }
  54. return(0);
  55. }
  56. /* there was no great place to put this.... */
  57. void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  58. #if 0
  59. int j;
  60. FILE *of;
  61. char buffer[80];
  62. /* if(i==5870){*/
  63. sprintf(buffer,"%s_%d.m",base,i);
  64. of=fopen(buffer,"w");
  65. if(!of)perror("failed to open data dump file");
  66. for(j=0;j<n;j++){
  67. if(bark){
  68. float b=toBARK((4000.f*j/n)+.25);
  69. fprintf(of,"%f ",b);
  70. }else
  71. if(off!=0)
  72. fprintf(of,"%f ",(double)(j+off)/8000.);
  73. else
  74. fprintf(of,"%f ",(double)j);
  75. if(dB){
  76. float val;
  77. if(v[j]==0.)
  78. val=-140.;
  79. else
  80. val=todB(v+j);
  81. fprintf(of,"%f\n",val);
  82. }else{
  83. fprintf(of,"%f\n",v[j]);
  84. }
  85. }
  86. fclose(of);
  87. /* } */
  88. #endif
  89. }
  90. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  91. ogg_int64_t off){
  92. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  93. }