27 #include <vorbis/vorbisenc.h>
38 #define OGGVORBIS_FRAME_SIZE 64
40 #define BUFFER_SIZE (1024 * 64)
71 if (vorbis_encode_setup_vbr(vi, avccontext->
channels,
80 if (vorbis_encode_setup_managed(vi, avccontext->
channels,
86 if (minrate == -1 && maxrate == -1)
87 if (vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET,
NULL))
92 if (avccontext->
cutoff > 0) {
93 cfreq = avccontext->
cutoff / 1000.0;
94 if (vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))
99 vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->
iblock);
102 return vorbis_encode_setup_init(vi);
108 return 1 + l / 255 + l;
118 vorbis_info_init(&context->
vi);
123 vorbis_analysis_init(&context->
vd, &context->
vi);
124 vorbis_block_init(&context->
vd, &context->
vb);
126 vorbis_comment_init(&context->
vc);
129 vorbis_analysis_headerout(&context->
vd, &context->
vc, &header,
130 &header_comm, &header_code);
141 memcpy(&p[offset], header.packet, header.bytes);
142 offset += header.bytes;
143 memcpy(&p[offset], header_comm.packet, header_comm.bytes);
144 offset += header_comm.bytes;
145 memcpy(&p[offset], header_code.packet, header_code.bytes);
146 offset += header_code.bytes;
150 vorbis_block_clear(&context->
vb);
151 vorbis_dsp_clear(&context->
vd);
152 vorbis_info_clear(&context->
vi);
154 vorbis_comment_clear(&context->
vc);
165 unsigned char *packets,
166 int buf_size,
void *
data)
170 signed short *audio =
data;
176 int c, channels = context->
vi.channels;
178 buffer = vorbis_analysis_buffer(&context->
vd, samples);
179 for (c = 0; c < channels; c++) {
180 int co = (channels > 8) ? c :
183 buffer[c][l] = audio[l * channels + co] / 32768.
f;
185 vorbis_analysis_wrote(&context->
vd, samples);
188 vorbis_analysis_wrote(&context->
vd, 0);
192 while (vorbis_analysis_blockout(&context->
vd, &context->
vb) == 1) {
193 vorbis_analysis(&context->
vb,
NULL);
194 vorbis_bitrate_addblock(&context->
vb);
196 while (vorbis_bitrate_flushpacket(&context->
vd, &op)) {
199 if (op.bytes == 1 && op.e_o_s)
227 memcpy(packets, op2->packet, l);
241 vorbis_analysis_wrote(&context->
vd, 0);
243 vorbis_block_clear(&context->
vb);
244 vorbis_dsp_clear(&context->
vd);
245 vorbis_info_clear(&context->
vi);
264 .priv_class = &
class,