27 #include <vorbis/vorbisenc.h>
39 #define OGGVORBIS_FRAME_SIZE 64
41 #define BUFFER_SIZE (1024 * 64)
85 if (vorbis_encode_setup_vbr(vi, avccontext->
channels,
94 if (vorbis_encode_setup_managed(vi, avccontext->
channels,
100 if (minrate == -1 && maxrate == -1)
101 if (vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET,
NULL))
106 if (avccontext->
cutoff > 0) {
107 cfreq = avccontext->
cutoff / 1000.0;
108 if (vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))
113 vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->
iblock);
116 return vorbis_encode_setup_init(vi);
122 return 1 + l / 255 + l;
132 vorbis_info_init(&context->
vi);
137 vorbis_analysis_init(&context->
vd, &context->
vi);
138 vorbis_block_init(&context->
vd, &context->
vb);
140 vorbis_comment_init(&context->
vc);
143 vorbis_analysis_headerout(&context->
vd, &context->
vc, &header,
144 &header_comm, &header_code);
155 memcpy(&p[offset], header.packet, header.bytes);
156 offset += header.bytes;
157 memcpy(&p[offset], header_comm.packet, header_comm.bytes);
158 offset += header_comm.bytes;
159 memcpy(&p[offset], header_code.packet, header_code.bytes);
160 offset += header_code.bytes;
164 vorbis_block_clear(&context->
vb);
165 vorbis_dsp_clear(&context->
vd);
166 vorbis_info_clear(&context->
vi);
168 vorbis_comment_clear(&context->
vc);
179 unsigned char *packets,
180 int buf_size,
void *
data)
184 signed short *audio =
data;
190 int c, channels = context->
vi.channels;
192 buffer = vorbis_analysis_buffer(&context->
vd, samples);
193 for (c = 0; c < channels; c++) {
194 int co = (channels > 8) ? c :
197 buffer[c][l] = audio[l * channels + co] / 32768.
f;
199 vorbis_analysis_wrote(&context->
vd, samples);
202 vorbis_analysis_wrote(&context->
vd, 0);
206 while (vorbis_analysis_blockout(&context->
vd, &context->
vb) == 1) {
207 vorbis_analysis(&context->
vb,
NULL);
208 vorbis_bitrate_addblock(&context->
vb);
210 while (vorbis_bitrate_flushpacket(&context->
vd, &op)) {
213 if (op.bytes == 1 && op.e_o_s)
241 memcpy(packets, op2->packet, l);
255 vorbis_analysis_wrote(&context->
vd, 0);
257 vorbis_block_clear(&context->
vb);
258 vorbis_dsp_clear(&context->
vd);
259 vorbis_info_clear(&context->
vi);
278 .priv_class = &
class,