analysis.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.29.2.1 2000/06/23 08:36:36 xiphmont Exp $
  15. ********************************************************************/
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <math.h>
  19. #include "vorbis/codec.h"
  20. #include "bitwise.h"
  21. #include "registry.h"
  22. #include "scales.h"
  23. /* decides between modes, dispatches to the appropriate mapping. */
  24. int vorbis_analysis(vorbis_block *vb,ogg_packet *op){
  25. vorbis_dsp_state *vd=vb->vd;
  26. vorbis_info *vi=vd->vi;
  27. int type;
  28. int mode=0;
  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. /* Encode the packet type */
  36. _oggpack_write(&vb->opb,0,1);
  37. /* currently lazy. Short block dispatches to 0, long to 1. */
  38. if(vb->W &&vi->modes>1)mode=1;
  39. type=vi->map_type[vi->mode_param[mode]->mapping];
  40. vb->mode=mode;
  41. /* Encode frame mode, pre,post windowsize, then dispatch */
  42. _oggpack_write(&vb->opb,mode,vd->modebits);
  43. if(vb->W){
  44. _oggpack_write(&vb->opb,vb->lW,1);
  45. _oggpack_write(&vb->opb,vb->nW,1);
  46. fprintf(stderr,"*");
  47. }else{
  48. fprintf(stderr,".");
  49. }
  50. if(_mapping_P[type]->forward(vb,vd->mode[mode]))
  51. return(-1);
  52. /* set up the packet wrapper */
  53. op->packet=_oggpack_buffer(&vb->opb);
  54. op->bytes=_oggpack_bytes(&vb->opb);
  55. op->b_o_s=0;
  56. op->e_o_s=vb->eofflag;
  57. op->frameno=vb->frameno;
  58. op->packetno=vb->sequence; /* for sake of completeness */
  59. return(0);
  60. }
  61. /* there was no great place to put this.... */
  62. void _analysis_output(char *base,int i,double *v,int n,int bark,int dB){
  63. #ifdef ANALYSIS
  64. int j;
  65. FILE *of;
  66. char buffer[80];
  67. sprintf(buffer,"%s_%d.m",base,i);
  68. of=fopen(buffer,"w");
  69. for(j=0;j<n;j++){
  70. if(dB && v[j]==0)
  71. fprintf(of,"\n\n");
  72. else{
  73. if(bark)
  74. fprintf(of,"%g ",toBARK(22050.*j/n));
  75. else
  76. fprintf(of,"%g ",(double)j);
  77. if(dB){
  78. fprintf(of,"%g\n",todB(fabs(v[j])));
  79. }else{
  80. fprintf(of,"%g\n",v[j]);
  81. }
  82. }
  83. }
  84. fclose(of);
  85. #endif
  86. }