analysis.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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-2002 *
  9. * by the XIPHOPHORUS Company http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function: single-block PCM analysis mode dispatch
  13. last mod: $Id: analysis.c,v 1.55 2002/07/11 06:40:48 xiphmont Exp $
  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;
  29. vb->glue_bits=0;
  30. vb->time_bits=0;
  31. vb->floor_bits=0;
  32. vb->res_bits=0;
  33. /* first things first. Make sure encode is ready */
  34. oggpack_reset(&vb->opb);
  35. /* we only have one mapping type (0), and we let the mapping code
  36. itself figure out what soft mode to use. This allows easier
  37. bitrate management */
  38. if((ret=_mapping_P[0]->forward(vb)))
  39. return(ret);
  40. if(op){
  41. if(vorbis_bitrate_managed(vb))
  42. /* The app is using a bitmanaged mode... but not using the
  43. bitrate management interface. */
  44. return(OV_EINVAL);
  45. op->packet=oggpack_get_buffer(&vb->opb);
  46. op->bytes=oggpack_bytes(&vb->opb);
  47. op->b_o_s=0;
  48. op->e_o_s=vb->eofflag;
  49. op->granulepos=vb->granulepos;
  50. op->packetno=vb->sequence; /* for sake of completeness */
  51. }
  52. return(0);
  53. }
  54. /* there was no great place to put this.... */
  55. void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  56. int j;
  57. FILE *of;
  58. char buffer[80];
  59. /* if(i==5870){*/
  60. sprintf(buffer,"%s_%d.m",base,i);
  61. of=fopen(buffer,"w");
  62. if(!of)perror("failed to open data dump file");
  63. for(j=0;j<n;j++){
  64. if(bark){
  65. float b=toBARK((4000.f*j/n)+.25);
  66. fprintf(of,"%f ",b);
  67. }else
  68. if(off!=0)
  69. fprintf(of,"%f ",(double)(j+off)/8000.);
  70. else
  71. fprintf(of,"%f ",(double)j);
  72. if(dB){
  73. float val;
  74. if(v[j]==0.)
  75. val=-140.;
  76. else
  77. val=todB(v+j);
  78. fprintf(of,"%f\n",val);
  79. }else{
  80. fprintf(of,"%f\n",v[j]);
  81. }
  82. }
  83. fclose(of);
  84. /* } */
  85. }
  86. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  87. ogg_int64_t off){
  88. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  89. }