00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include "ogg.h"
00021 #include "ivorbiscodec.h"
00022 #include "codec_internal.h"
00023 #include "registry.h"
00024 #include "misc.h"
00025 #include "os.h"
00026 int _vorbis_block_ripcord(vorbis_block *vb);
00027 void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
00028 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op,int decodep){
00029 vorbis_dsp_state *vd=vb->vd;
00030 private_state *b=(private_state *)vd->backend_state;
00031 vorbis_info *vi=vd->vi;
00032 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
00033 oggpack_buffer *opb=&vb->opb;
00034 int type,mode,i;
00035
00036
00037 _vorbis_block_ripcord(vb);
00038 oggpack_readinit(opb,op->packet);
00039
00040
00041 if(oggpack_read(opb,1)!=0){
00042
00043 return(OV_ENOTAUDIO);
00044 }
00045
00046
00047 mode=oggpack_read(opb,b->modebits);
00048 if(mode==-1)return(OV_EBADPACKET);
00049
00050 vb->mode=mode;
00051 vb->W=ci->mode_param[mode]->blockflag;
00052 if(vb->W){
00053 vb->lW=oggpack_read(opb,1);
00054 vb->nW=oggpack_read(opb,1);
00055 if(vb->nW==-1) return(OV_EBADPACKET);
00056 }else{
00057 vb->lW=0;
00058 vb->nW=0;
00059 }
00060
00061
00062 vb->granulepos=op->granulepos;
00063 vb->sequence=op->packetno-3;
00064 vb->eofflag=op->e_o_s;
00065
00066 if(decodep){
00067
00068 vb->pcmend=ci->blocksizes[vb->W];
00069 vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
00070 for(i=0;i<vi->channels;i++)
00071 vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
00072
00073
00074 type=ci->map_type[ci->mode_param[mode]->mapping];
00075
00076 return(_mapping_P[type]->inverse(vb,b->mode[mode]));
00077 }else{
00078
00079 vb->pcmend=0;
00080 vb->pcm=NULL;
00081
00082 return(0);
00083 }
00084 }
00085
00086 long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
00087 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
00088 oggpack_buffer opb;
00089 int mode;
00090
00091 oggpack_readinit(&opb,op->packet);
00092
00093
00094 if(oggpack_read(&opb,1)!=0){
00095
00096 return(OV_ENOTAUDIO);
00097 }
00098
00099 {
00100 int modebits=0;
00101 int v=ci->modes;
00102 while(v>1){
00103 modebits++;
00104 v>>=1;
00105 }
00106
00107
00108 mode=oggpack_read(&opb,modebits);
00109 }
00110 if(mode==-1)return(OV_EBADPACKET);
00111 return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
00112 }
00113
00114