analysis.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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-2001 *
  9. * by the XIPHOPHORUS Company http://www.xiph.org/ *
  10. ********************************************************************
  11. function: single-block PCM analysis mode dispatch
  12. last mod: $Id: analysis.c,v 1.44.2.2 2001/08/13 00:20:10 xiphmont Exp $
  13. ********************************************************************/
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <math.h>
  17. #include <ogg/ogg.h>
  18. #include "vorbis/codec.h"
  19. #include "codec_internal.h"
  20. #include "registry.h"
  21. #include "scales.h"
  22. #include "os.h"
  23. int analysis_noisy=1;
  24. /* decides between modes, dispatches to the appropriate mapping. */
  25. int vorbis_analysis(vorbis_block *vb,ogg_packet *op){
  26. vorbis_dsp_state *vd=vb->vd;
  27. backend_lookup_state *b=vd->backend_state;
  28. vorbis_info *vi=vd->vi;
  29. codec_setup_info *ci=vi->codec_setup;
  30. int type,ret;
  31. int mode=0;
  32. vb->glue_bits=0;
  33. vb->time_bits=0;
  34. vb->floor_bits=0;
  35. vb->res_bits=0;
  36. /* first things first. Make sure encode is ready */
  37. oggpack_reset(&vb->opb);
  38. /* Encode the packet type */
  39. oggpack_write(&vb->opb,0,1);
  40. /* currently lazy. Short block dispatches to 0, long to 1. */
  41. if(vb->W &&ci->modes>1)mode=1;
  42. type=ci->map_type[ci->mode_param[mode]->mapping];
  43. vb->mode=mode;
  44. /* Encode frame mode, pre,post windowsize, then dispatch */
  45. oggpack_write(&vb->opb,mode,b->modebits);
  46. if(vb->W){
  47. oggpack_write(&vb->opb,vb->lW,1);
  48. oggpack_write(&vb->opb,vb->nW,1);
  49. /*fprintf(stderr,"*");
  50. }else{
  51. fprintf(stderr,".");*/
  52. }
  53. if((ret=_mapping_P[type]->forward(vb,b->mode[mode])))
  54. return(ret);
  55. /* set up the packet wrapper */
  56. op->packet=oggpack_get_buffer(&vb->opb);
  57. op->bytes=oggpack_bytes(&vb->opb);
  58. op->b_o_s=0;
  59. op->e_o_s=vb->eofflag;
  60. op->granulepos=vb->granulepos;
  61. op->packetno=vb->sequence; /* for sake of completeness */
  62. return(0);
  63. }
  64. /* there was no great place to put this.... */
  65. void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB){
  66. int j;
  67. FILE *of;
  68. char buffer[80];
  69. // if(i==5870){
  70. sprintf(buffer,"%s_%d.m",base,i);
  71. of=fopen(buffer,"w");
  72. if(!of)perror("failed to open data dump file");
  73. for(j=0;j<n;j++){
  74. if(dB && v[j]==0)
  75. fprintf(of,"\n\n");
  76. else{
  77. if(bark)
  78. fprintf(of,"%g ",toBARK(22050.f*j/n));
  79. else
  80. fprintf(of,"%g ",(double)j);
  81. if(dB){
  82. fprintf(of,"%g\n",todB(v+j));
  83. }else{
  84. fprintf(of,"%g\n",v[j]);
  85. }
  86. }
  87. }
  88. fclose(of);
  89. // }
  90. }
  91. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB){
  92. #ifdef ANALYSIS
  93. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB);
  94. #endif
  95. }