21 #include <vorbis/vorbisenc.h>
40 unsigned char *headers[3], *extradata = avccontext->
extradata;
42 vorbis_info_init(&context->
vi) ;
43 vorbis_comment_init(&context->
vc) ;
50 if(p[0] == 0 && p[1] == 30) {
51 for(i = 0; i < 3; i++){
52 hsizes[i] = bytestream_get_be16((
const uint8_t **)&p);
61 while((*p == 0xFF) && (offset < avccontext->extradata_size)) {
68 "vorbis header sizes damaged\n");
78 "vorbis header sizes: %d, %d, %d, / extradata_len is %d \n",
81 headers[0] = extradata +
offset;
82 headers[1] = extradata + offset + hsizes[0];
83 headers[2] = extradata + offset + hsizes[0] + hsizes[1];
86 "vorbis initial header len is wrong: %d\n", *p);
91 context->
op.b_o_s= i==0;
92 context->
op.bytes = hsizes[i];
93 context->
op.packet = headers[i];
94 if(vorbis_synthesis_headerin(&context->
vi, &context->
vc, &context->
op)<0){
104 vorbis_synthesis_init(&context->
vd, &context->
vi);
105 vorbis_block_init(&context->
vd, &context->
vb);
111 static inline int conv(
int samples,
float **pcm,
char *buf,
int channels) {
113 ogg_int16_t *ptr, *
data = (ogg_int16_t*)buf ;
116 for(i = 0 ; i < channels ; i++){
120 for(j = 0 ; j <
samples ; j++) {
121 *ptr = av_clip_int16(mono[j] * 32767.f);
130 int *got_frame_ptr,
AVPacket *avpkt)
135 int samples, total_samples, total_bytes;
149 output = (int16_t *)context->
frame.
data[0];
152 op->packet = avpkt->
data;
153 op->bytes = avpkt->
size;
161 if(vorbis_synthesis(&context->
vb, op) == 0)
162 vorbis_synthesis_blockin(&context->
vd, &context->
vb) ;
167 while((samples = vorbis_synthesis_pcmout(&context->
vd, &pcm)) > 0) {
168 conv(samples, pcm, (
char*)output + total_bytes, context->
vi.channels) ;
169 total_bytes += samples * 2 * context->
vi.channels ;
171 vorbis_synthesis_read(&context->
vd, samples) ;
184 vorbis_info_clear(&context->
vi) ;
185 vorbis_comment_clear(&context->
vc) ;