14280
|
1 /********************************************************************
|
|
2 * *
|
|
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
|
|
4 * *
|
|
5 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
|
|
6 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
|
|
7 * ALL REDISTRIBUTION RIGHTS RESERVED. *
|
|
8 * *
|
|
9 ********************************************************************
|
|
10
|
|
11 function: single-block PCM synthesis
|
|
12 last mod: $Id$
|
|
13
|
|
14 ********************************************************************/
|
|
15
|
|
16 #include <stdio.h>
|
|
17 #include "ogg.h"
|
|
18 #include "ivorbiscodec.h"
|
|
19 #include "codec_internal.h"
|
|
20 #include "registry.h"
|
|
21 #include "misc.h"
|
|
22 #include "os.h"
|
|
23
|
|
24 int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
|
|
25 vorbis_dsp_state *vd=vb->vd;
|
|
26 backend_lookup_state *b=(backend_lookup_state *)vd->backend_state;
|
|
27 vorbis_info *vi=vd->vi;
|
|
28 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
|
|
29 oggpack_buffer *opb=&vb->opb;
|
|
30 int type,mode,i;
|
|
31
|
|
32 /* first things first. Make sure decode is ready */
|
|
33 _vorbis_block_ripcord(vb);
|
|
34 oggpack_readinit(opb,op->packet,op->bytes);
|
|
35
|
|
36 /* Check the packet type */
|
|
37 if(oggpack_read(opb,1)!=0){
|
|
38 /* Oops. This is not an audio data packet */
|
|
39 return(OV_ENOTAUDIO);
|
|
40 }
|
|
41
|
|
42 /* read our mode and pre/post windowsize */
|
|
43 mode=oggpack_read(opb,b->modebits);
|
|
44 if(mode==-1)return(OV_EBADPACKET);
|
|
45
|
|
46 vb->mode=mode;
|
|
47 vb->W=ci->mode_param[mode]->blockflag;
|
|
48 if(vb->W){
|
|
49 vb->lW=oggpack_read(opb,1);
|
|
50 vb->nW=oggpack_read(opb,1);
|
|
51 if(vb->nW==-1) return(OV_EBADPACKET);
|
|
52 }else{
|
|
53 vb->lW=0;
|
|
54 vb->nW=0;
|
|
55 }
|
|
56
|
|
57 /* more setup */
|
|
58 vb->granulepos=op->granulepos;
|
|
59 vb->sequence=op->packetno-3; /* first block is third packet */
|
|
60 vb->eofflag=op->e_o_s;
|
|
61
|
|
62 /* alloc pcm passback storage */
|
|
63 vb->pcmend=ci->blocksizes[vb->W];
|
|
64 vb->pcm=(ogg_int32_t **)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
|
|
65 for(i=0;i<vi->channels;i++)
|
|
66 vb->pcm[i]=(ogg_int32_t *)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
|
|
67
|
|
68 /* unpack_header enforces range checking */
|
|
69 type=ci->map_type[ci->mode_param[mode]->mapping];
|
|
70
|
|
71 return(_mapping_P[type]->inverse(vb,b->mode[mode]));
|
|
72 }
|
|
73
|
|
74 long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
|
|
75 codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
|
|
76 oggpack_buffer opb;
|
|
77 int mode;
|
|
78
|
|
79 oggpack_readinit(&opb,op->packet,op->bytes);
|
|
80
|
|
81 /* Check the packet type */
|
|
82 if(oggpack_read(&opb,1)!=0){
|
|
83 /* Oops. This is not an audio data packet */
|
|
84 return(OV_ENOTAUDIO);
|
|
85 }
|
|
86
|
|
87 {
|
|
88 int modebits=0;
|
|
89 int v=ci->modes;
|
|
90 while(v>1){
|
|
91 modebits++;
|
|
92 v>>=1;
|
|
93 }
|
|
94
|
|
95 /* read our mode and pre/post windowsize */
|
|
96 mode=oggpack_read(&opb,modebits);
|
|
97 }
|
|
98 if(mode==-1)return(OV_EBADPACKET);
|
|
99 return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
|
|
100 }
|
|
101
|
|
102
|