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-2003 *
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 static ogg_int32_t
*ipcm_vect
[CHANNELS
] IBSS_ATTR
;
30 int vorbis_synthesis(vorbis_block
*vb
,ogg_packet
*op
,int decodep
)
31 ICODE_ATTR_TREMOR_NOT_MDCT
;
32 int vorbis_synthesis(vorbis_block
*vb
,ogg_packet
*op
,int decodep
){
33 vorbis_dsp_state
*vd
=vb
->vd
;
34 private_state
*b
=(private_state
*)vd
->backend_state
;
35 vorbis_info
*vi
=vd
->vi
;
36 codec_setup_info
*ci
=(codec_setup_info
*)vi
->codec_setup
;
37 oggpack_buffer
*opb
=&vb
->opb
;
40 /* first things first. Make sure decode is ready */
41 _vorbis_block_ripcord(vb
);
42 oggpack_readinit(opb
,op
->packet
);
44 /* Check the packet type */
45 if(oggpack_read(opb
,1)!=0){
46 /* Oops. This is not an audio data packet */
50 /* read our mode and pre/post windowsize */
51 mode
=oggpack_read(opb
,b
->modebits
);
52 if(mode
==-1)return(OV_EBADPACKET
);
55 vb
->W
=ci
->mode_param
[mode
]->blockflag
;
57 vb
->lW
=oggpack_read(opb
,1);
58 vb
->nW
=oggpack_read(opb
,1);
59 if(vb
->nW
==-1) return(OV_EBADPACKET
);
66 vb
->granulepos
=op
->granulepos
;
67 vb
->sequence
=op
->packetno
-3; /* first block is third packet */
68 vb
->eofflag
=op
->e_o_s
;
70 if(decodep
&& vi
->channels
<=CHANNELS
)
74 /* set pcm end point */
75 vb
->pcmend
=ci
->blocksizes
[vb
->W
];
76 /* use statically allocated buffer */
77 if(vd
->reset_pcmb
|| vb
->pcm
[0]==NULL
)
79 /* one-time initialisation at codec start
80 NOT for every block synthesis start
81 allows us to flip between buffers once initialised
82 by simply flipping pointers */
83 for(i
=0; i
<vi
->channels
; i
++)
84 vb
->pcm
[i
] = &vd
->first_pcm
[i
*ci
->blocksizes
[1]];
87 vd
->reset_pcmb
= false;
89 /* unpack_header enforces range checking */
90 type
=ci
->map_type
[ci
->mode_param
[mode
]->mapping
];
91 return(_mapping_P
[type
]->inverse(vb
,b
->mode
[mode
]));
101 long vorbis_packet_blocksize(vorbis_info
*vi
,ogg_packet
*op
){
102 codec_setup_info
*ci
=(codec_setup_info
*)vi
->codec_setup
;
106 oggpack_readinit(&opb
,op
->packet
);
108 /* Check the packet type */
109 if(oggpack_read(&opb
,1)!=0){
110 /* Oops. This is not an audio data packet */
111 return(OV_ENOTAUDIO
);
122 /* read our mode and pre/post windowsize */
123 mode
=oggpack_read(&opb
,modebits
);
125 if(mode
==-1)return(OV_EBADPACKET
);
126 return(ci
->blocksizes
[ci
->mode_param
[mode
]->blockflag
]);