synthesis.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 synthesis
  14. last mod: $Id: synthesis.c,v 1.17.4.1.2.2 2000/09/26 18:45:34 jack Exp $
  15. ********************************************************************/
  16. #include <stdio.h>
  17. #include <ogg/ogg.h>
  18. #include "vorbis/codec.h"
  19. #include "registry.h"
  20. #include "misc.h"
  21. #include "os.h"
  22. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  23. vorbis_dsp_state *vd=vb->vd;
  24. vorbis_info *vi=vd->vi;
  25. oggpack_buffer *opb=&vb->opb;
  26. int type,mode,i;
  27. /* first things first. Make sure decode is ready */
  28. _vorbis_block_ripcord(vb);
  29. oggpack_readinit(opb,op->packet,op->bytes);
  30. /* Check the packet type */
  31. if(oggpack_read(opb,1)!=0){
  32. /* Oops. This is not an audio data packet */
  33. return(-1);
  34. }
  35. /* read our mode and pre/post windowsize */
  36. mode=oggpack_read(opb,vd->modebits);
  37. if(mode==-1)return(-1);
  38. vb->mode=mode;
  39. vb->W=vi->mode_param[mode]->blockflag;
  40. if(vb->W){
  41. vb->lW=oggpack_read(opb,1);
  42. vb->nW=oggpack_read(opb,1);
  43. if(vb->nW==-1) return(-1);
  44. }else{
  45. vb->lW=0;
  46. vb->nW=0;
  47. }
  48. /* more setup */
  49. vb->granulepos=op->granulepos;
  50. vb->sequence=op->packetno-3; /* first block is third packet */
  51. vb->eofflag=op->e_o_s;
  52. /* alloc pcm passback storage */
  53. vb->pcmend=vi->blocksizes[vb->W];
  54. vb->pcm=_vorbis_block_alloc(vb,sizeof(float *)*vi->channels);
  55. for(i=0;i<vi->channels;i++)
  56. vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(float));
  57. /* unpack_header enforces range checking */
  58. type=vi->map_type[vi->mode_param[mode]->mapping];
  59. return(_mapping_P[type]->inverse(vb,vd->mode[mode]));
  60. }