analysis.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
  5. * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
  6. * PLEASE READ THESE TERMS DISTRIBUTING. *
  7. * *
  8. * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
  9. * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
  10. * http://www.xiph.org/ *
  11. * *
  12. ********************************************************************
  13. function: single-block PCM analysis mode dispatch
  14. last mod: $Id: analysis.c,v 1.33.2.2.2.2 2000/09/26 18:45:33 jack Exp $
  15. ********************************************************************/
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <math.h>
  19. #include <ogg/ogg.h>
  20. #include "vorbis/codec.h"
  21. #include "registry.h"
  22. #include "scales.h"
  23. #include "os.h"
  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. vorbis_info *vi=vd->vi;
  28. int type;
  29. int mode=0;
  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. oggpack_reset(&vb->opb);
  36. /* Encode the packet type */
  37. oggpack_write(&vb->opb,0,1);
  38. /* currently lazy. Short block dispatches to 0, long to 1. */
  39. if(vb->W &&vi->modes>1)mode=1;
  40. type=vi->map_type[vi->mode_param[mode]->mapping];
  41. vb->mode=mode;
  42. /* Encode frame mode, pre,post windowsize, then dispatch */
  43. oggpack_write(&vb->opb,mode,vd->modebits);
  44. if(vb->W){
  45. oggpack_write(&vb->opb,vb->lW,1);
  46. oggpack_write(&vb->opb,vb->nW,1);
  47. fprintf(stderr,"*");
  48. }else{
  49. fprintf(stderr,".");
  50. }
  51. if(_mapping_P[type]->forward(vb,vd->mode[mode]))
  52. return(-1);
  53. /* set up the packet wrapper */
  54. op->packet=oggpack_get_buffer(&vb->opb);
  55. op->bytes=oggpack_bytes(&vb->opb);
  56. op->b_o_s=0;
  57. op->e_o_s=vb->eofflag;
  58. op->granulepos=vb->granulepos;
  59. op->packetno=vb->sequence; /* for sake of completeness */
  60. return(0);
  61. }
  62. /* there was no great place to put this.... */
  63. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB){
  64. #ifdef ANALYSIS
  65. int j;
  66. FILE *of;
  67. char buffer[80];
  68. sprintf(buffer,"%s_%d.m",base,i);
  69. of=fopen(buffer,"w");
  70. if(!of)perror("failed to open data dump file");
  71. for(j=0;j<n;j++){
  72. if(dB && v[j]==0)
  73. fprintf(of,"\n\n");
  74. else{
  75. if(bark)
  76. fprintf(of,"%g ",toBARK(22050.*j/n));
  77. else
  78. fprintf(of,"%g ",(double)j);
  79. if(dB){
  80. fprintf(of,"%g\n",todB(fabs(v[j])));
  81. }else{
  82. fprintf(of,"%g\n",v[j]);
  83. }
  84. }
  85. }
  86. fclose(of);
  87. #endif
  88. }