synthesis.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 synthesis
  14. last mod: $Id: synthesis.c,v 1.18.2.3 2000/11/04 06:21:46 xiphmont 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. backend_lookup_state *b=vd->backend_state;
  25. vorbis_info *vi=vd->vi;
  26. codec_setup_info *ci=vi->codec_setup;
  27. oggpack_buffer *opb=&vb->opb;
  28. int type,mode,i;
  29. /* first things first. Make sure decode is ready */
  30. _vorbis_block_ripcord(vb);
  31. oggpack_readinit(opb,op->packet,op->bytes);
  32. /* Check the packet type */
  33. if(oggpack_read(opb,1)!=0){
  34. /* Oops. This is not an audio data packet */
  35. return(OV_ENOTAUDIO);
  36. }
  37. /* read our mode and pre/post windowsize */
  38. mode=oggpack_read(opb,b->modebits);
  39. if(mode==-1)return(OV_EBADPACKET);
  40. vb->mode=mode;
  41. vb->W=ci->mode_param[mode]->blockflag;
  42. if(vb->W){
  43. vb->lW=oggpack_read(opb,1);
  44. vb->nW=oggpack_read(opb,1);
  45. if(vb->nW==-1) return(OV_EBADPACKET);
  46. }else{
  47. vb->lW=0;
  48. vb->nW=0;
  49. }
  50. /* more setup */
  51. vb->granulepos=op->granulepos;
  52. vb->sequence=op->packetno-3; /* first block is third packet */
  53. vb->eofflag=op->e_o_s;
  54. /* alloc pcm passback storage */
  55. vb->pcmend=ci->blocksizes[vb->W];
  56. vb->pcm=_vorbis_block_alloc(vb,sizeof(float *)*vi->channels);
  57. for(i=0;i<vi->channels;i++)
  58. vb->pcm[i]=_vorbis_block_alloc(vb,vb->pcmend*sizeof(float));
  59. /* unpack_header enforces range checking */
  60. type=ci->map_type[ci->mode_param[mode]->mapping];
  61. return(_mapping_P[type]->inverse(vb,b->mode[mode]));
  62. }