21 #include <vorbis/vorbisenc.h>
39 unsigned char *headers[3], *extradata = avccontext->
extradata;
41 vorbis_info_init(&context->
vi) ;
42 vorbis_comment_init(&context->
vc) ;
49 if(p[0] == 0 && p[1] == 30) {
50 for(i = 0; i < 3; i++){
51 hsizes[i] = bytestream_get_be16((
const uint8_t **)&p);
60 while((*p == 0xFF) && (offset < avccontext->extradata_size)) {
67 "vorbis header sizes damaged\n");
77 "vorbis header sizes: %d, %d, %d, / extradata_len is %d \n",
80 headers[0] = extradata +
offset;
81 headers[1] = extradata + offset + hsizes[0];
82 headers[2] = extradata + offset + hsizes[0] + hsizes[1];
85 "vorbis initial header len is wrong: %d\n", *p);
90 context->
op.b_o_s= i==0;
91 context->
op.bytes = hsizes[i];
92 context->
op.packet = headers[i];
93 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)
136 int samples, total_samples, total_bytes;
148 output = (int16_t *)frame->
data[0];
151 op->packet = avpkt->
data;
152 op->bytes = avpkt->
size;
160 if(vorbis_synthesis(&context->
vb, op) == 0)
161 vorbis_synthesis_blockin(&context->
vd, &context->
vb) ;
166 while((samples = vorbis_synthesis_pcmout(&context->
vd, &pcm)) > 0) {
167 conv(samples, pcm, (
char*)output + total_bytes, context->
vi.channels) ;
168 total_bytes += samples * 2 * context->
vi.channels ;
169 total_samples += samples ;
170 vorbis_synthesis_read(&context->
vd, samples) ;
182 vorbis_info_clear(&context->
vi) ;
183 vorbis_comment_clear(&context->
vc) ;