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 /* IRAM buffer keep the block pcm data; only for windows size upto 2048
29 for space restrictions.
30 libVorbis 1.1 Oggenc doesn't use larger windows anyway. */
31 /* max 2 channels on the ihp-1xx (stereo), 2048 samples (2*2048*4=16Kb) */
32 #define IRAM_PCM_END 2048
35 static ogg_int32_t
*ipcm_vect
[CHANNELS
] IBSS_ATTR
;
36 static ogg_int32_t ipcm_buff
[CHANNELS
*IRAM_PCM_END
] IBSS_ATTR LINE_ATTR
;
38 int vorbis_synthesis(vorbis_block
*vb
,ogg_packet
*op
,int decodep
)
39 ICODE_ATTR_TREMOR_NOT_MDCT
;
40 int vorbis_synthesis(vorbis_block
*vb
,ogg_packet
*op
,int decodep
){
41 vorbis_dsp_state
*vd
=vb
->vd
;
42 private_state
*b
=(private_state
*)vd
->backend_state
;
43 vorbis_info
*vi
=vd
->vi
;
44 codec_setup_info
*ci
=(codec_setup_info
*)vi
->codec_setup
;
45 oggpack_buffer
*opb
=&vb
->opb
;
48 /* first things first. Make sure decode is ready */
49 _vorbis_block_ripcord(vb
);
50 oggpack_readinit(opb
,op
->packet
);
52 /* Check the packet type */
53 if(oggpack_read(opb
,1)!=0){
54 /* Oops. This is not an audio data packet */
58 /* read our mode and pre/post windowsize */
59 mode
=oggpack_read(opb
,b
->modebits
);
60 if(mode
==-1)return(OV_EBADPACKET
);
63 vb
->W
=ci
->mode_param
[mode
]->blockflag
;
65 vb
->lW
=oggpack_read(opb
,1);
66 vb
->nW
=oggpack_read(opb
,1);
67 if(vb
->nW
==-1) return(OV_EBADPACKET
);
74 vb
->granulepos
=op
->granulepos
;
75 vb
->sequence
=op
->packetno
-3; /* first block is third packet */
76 vb
->eofflag
=op
->e_o_s
;
78 if(decodep
&& vi
->channels
<=CHANNELS
){
79 /* alloc pcm passback storage */
80 vb
->pcmend
=ci
->blocksizes
[vb
->W
];
81 if (vb
->pcmend
<=IRAM_PCM_END
) {
82 /* use statically allocated iram buffer */
84 for(i
=0; i
<CHANNELS
; i
++)
85 vb
->pcm
[i
] = &ipcm_buff
[i
*IRAM_PCM_END
];
87 /* dynamic allocation (slower) */
88 vb
->pcm
=(ogg_int32_t
**)_vorbis_block_alloc(vb
,sizeof(*vb
->pcm
)*vi
->channels
);
89 for(i
=0;i
<vi
->channels
;i
++)
90 vb
->pcm
[i
]=(ogg_int32_t
*)_vorbis_block_alloc(vb
,vb
->pcmend
*sizeof(*vb
->pcm
[i
]));
93 /* unpack_header enforces range checking */
94 type
=ci
->map_type
[ci
->mode_param
[mode
]->mapping
];
96 return(_mapping_P
[type
]->inverse(vb
,b
->mode
[mode
]));
106 long vorbis_packet_blocksize(vorbis_info
*vi
,ogg_packet
*op
){
107 codec_setup_info
*ci
=(codec_setup_info
*)vi
->codec_setup
;
111 oggpack_readinit(&opb
,op
->packet
);
113 /* Check the packet type */
114 if(oggpack_read(&opb
,1)!=0){
115 /* Oops. This is not an audio data packet */
116 return(OV_ENOTAUDIO
);
127 /* read our mode and pre/post windowsize */
128 mode
=oggpack_read(&opb
,modebits
);
130 if(mode
==-1)return(OV_EBADPACKET
);
131 return(ci
->blocksizes
[ci
->mode_param
[mode
]->blockflag
]);