analysis.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
  5. * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
  6. * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE OggVorbis 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.34.2.3 2000/11/04 06:21:42 xiphmont 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. 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(char *base,int i,float *v,int n,int bark,int dB){
  66. #ifdef ANALYSIS
  67. int j;
  68. FILE *of;
  69. char buffer[80];
  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.*j/n));
  79. else
  80. fprintf(of,"%g ",(double)j);
  81. if(dB){
  82. fprintf(of,"%g\n",todB(fabs(v[j])));
  83. }else{
  84. fprintf(of,"%g\n",v[j]);
  85. }
  86. }
  87. }
  88. fclose(of);
  89. #endif
  90. }