analysis.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.24.4.2 2000/04/13 04:53:04 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. }
  47. if(_mapping_P[type]->forward(vb,vd->mode[mode]))
  48. return(-1);
  49. /* set up the packet wrapper */
  50. op->packet=_oggpack_buffer(&vb->opb);
  51. op->bytes=_oggpack_bytes(&vb->opb);
  52. op->b_o_s=0;
  53. op->e_o_s=vb->eofflag;
  54. op->frameno=vb->frameno;
  55. op->packetno=vb->sequence; /* for sake of completeness */
  56. return(0);
  57. }
  58. /* there was no great place to put this.... */
  59. void _analysis_output(char *base,int i,double *v,int n,int bark,int dB){
  60. #ifdef ANALYSIS
  61. int j;
  62. FILE *of;
  63. char buffer[80];
  64. sprintf(buffer,"%s_%d.m",base,i);
  65. of=fopen(buffer,"w");
  66. for(j=0;j<n;j++){
  67. if(dB && v[j]==0)
  68. fprintf(of,"\n\n");
  69. else{
  70. if(bark)
  71. fprintf(of,"%g ",toBARK(22050.*j/n));
  72. else
  73. fprintf(of,"%g ",(double)j);
  74. if(dB){
  75. fprintf(of,"%g\n",todB(fabs(v[j])));
  76. }else{
  77. fprintf(of,"%g\n",v[j]);
  78. }
  79. }
  80. }
  81. fclose(of);
  82. #endif
  83. }