1 /********************************************************************
3 * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. *
5 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
6 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
7 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
9 * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
10 * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ *
12 ********************************************************************
14 function: single-block PCM synthesis
17 ********************************************************************/
21 #include "ivorbiscodec.h"
22 #include "codec_internal.h"
28 int vorbis_synthesis(vorbis_block
*vb
,ogg_packet
*op
){
29 vorbis_dsp_state
*vd
=vb
->vd
;
30 backend_lookup_state
*b
=(backend_lookup_state
*)vd
->backend_state
;
31 vorbis_info
*vi
=vd
->vi
;
32 codec_setup_info
*ci
=(codec_setup_info
*)vi
->codec_setup
;
33 oggpack_buffer
*opb
=&vb
->opb
;
36 /* first things first. Make sure decode is ready */
37 _vorbis_block_ripcord(vb
);
38 oggpack_readinit(opb
,op
->packet
,op
->bytes
);
40 /* Check the packet type */
41 if(oggpack_read(opb
,1)!=0){
42 /* Oops. This is not an audio data packet */
46 /* read our mode and pre/post windowsize */
47 mode
=oggpack_read(opb
,b
->modebits
);
48 if(mode
==-1)return(OV_EBADPACKET
);
51 vb
->W
=ci
->mode_param
[mode
]->blockflag
;
53 vb
->lW
=oggpack_read(opb
,1);
54 vb
->nW
=oggpack_read(opb
,1);
55 if(vb
->nW
==-1) return(OV_EBADPACKET
);
62 vb
->granulepos
=op
->granulepos
;
63 vb
->sequence
=op
->packetno
-3; /* first block is third packet */
64 vb
->eofflag
=op
->e_o_s
;
66 /* alloc pcm passback storage */
67 vb
->pcmend
=ci
->blocksizes
[vb
->W
];
68 vb
->pcm
=(ogg_int32_t
**)_vorbis_block_alloc(vb
,sizeof(*vb
->pcm
)*vi
->channels
);
69 for(i
=0;i
<vi
->channels
;i
++)
70 vb
->pcm
[i
]=(ogg_int32_t
*)_vorbis_block_alloc(vb
,vb
->pcmend
*sizeof(*vb
->pcm
[i
]));
72 /* unpack_header enforces range checking */
73 type
=ci
->map_type
[ci
->mode_param
[mode
]->mapping
];
75 return(_mapping_P
[type
]->inverse(vb
,b
->mode
[mode
]));
78 long vorbis_packet_blocksize(vorbis_info
*vi
,ogg_packet
*op
){
79 codec_setup_info
*ci
=(codec_setup_info
*)vi
->codec_setup
;
83 oggpack_readinit(&opb
,op
->packet
,op
->bytes
);
85 /* Check the packet type */
86 if(oggpack_read(&opb
,1)!=0){
87 /* Oops. This is not an audio data packet */
99 /* read our mode and pre/post windowsize */
100 mode
=oggpack_read(&opb
,modebits
);
102 if(mode
==-1)return(OV_EBADPACKET
);
103 return(ci
->blocksizes
[ci
->mode_param
[mode
]->blockflag
]);