<div dir="ltr">Thank you for the suggestions Ian and Ralph.<div><br></div><div>I was able to get around the issue by adding an additional call to this chunk of code :</div><div><br></div><div><pre style="white-space:pre-wrap;word-wrap:break-word">
vorbis_analysis_wrote(&vd,0); /* Length set to 0 to signal end of buffer */
/* vorbis does some data preanalysis, then divvies up blocks for
more involved (potentially parallel) processing. Get a single
block for encoding now */
while(vorbis_analysis_blockout(&vd,&vb)==1){
/* analysis, assume we want to use bitrate management */
vorbis_analysis(&vb,NULL);
vorbis_bitrate_addblock(&vb);
while(vorbis_bitrate_flushpacket(&vd,&op)){
/* weld the packet into the bitstream */
ogg_stream_packetin(&os,&op);
/* write out pages (if any) */
while(!eos){
int result=ogg_stream_pageout(&os,&og);
if(result==0)break;
fwrite(og.header,1,og.header_len,stdout);
fwrite(og.body,1,og.body_len,stdout);
/* this could be set above, but for illustrative purposes, I do
it here (to show that vorbis does know where the stream ends) */
if(ogg_page_eos(&og))eos=1;
}
}</pre><pre style="white-space:pre-wrap;word-wrap:break-word"><br></pre><pre style="white-space:pre-wrap;word-wrap:break-word">I still have a small issue in that a small amount of the audio is clipped at the start of the stream. In general, my input is a buffer of PCM data that I convert to either OGG or WAV. A small amount of data is missing in the ogg relative to the wav. Any thoughts on what could cause this?</pre>
</div></div><div class="gmail_extra"><br clear="all"><div>-Ilya Ganelin</div>
<br><br><div class="gmail_quote">On Tue, Oct 22, 2013 at 5:28 PM, Ian Malone <span dir="ltr"><<a href="mailto:ibmalone@gmail.com" target="_blank">ibmalone@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 22 October 2013 22:09, Ilya Ganelin <<a href="mailto:ilganeli@gmail.com">ilganeli@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> I am using the Ogg Vorbis library to encode PCM data into ogg format. The<br>
> conversion seems to work fine with the exception that the first and last<br>
> little bit of audio appears cut off in each converted stream. It's about .25<br>
> seconds that are lost.<br>
><br>
> I am essentially following the example from here:<br>
> <a href="http://svn.xiph.org/trunk/vorbis/examples/encoder_example.c" target="_blank">http://svn.xiph.org/trunk/vorbis/examples/encoder_example.c</a><br>
><br>
> When I added a "Sleep(5)" between writing the ogg data to file, and clearing<br>
> the ogg/vorbis state structures, the ogg output files were closer in length<br>
> but still seemed somewhat shorter. I figured that I might have been<br>
> interrupting the output but this seems like a hacky way of doing things.<br>
><br>
> Is there a more proper way of solving this issue?<br>
><br>
<br>
</div></div>It's very hard to say without seeing the code. What I do know is the<br>
sleep function[1] should not affect a simple procedural program. So,<br>
randomly guessing, I suspect problems with file handling and not<br>
closing the output stream explaining the end of the output file<br>
missing. Not sure about the start.<br>
<br>
[1] I assume we do both mean the C function sleep:<br>
#include <unistd.h><br>
<br>
unsigned int sleep(unsigned int seconds);<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
imalone<br>
<a href="http://ibmalone.blogspot.co.uk" target="_blank">http://ibmalone.blogspot.co.uk</a><br>
_______________________________________________<br>
Vorbis-dev mailing list<br>
<a href="mailto:Vorbis-dev@xiph.org">Vorbis-dev@xiph.org</a><br>
<a href="http://lists.xiph.org/mailman/listinfo/vorbis-dev" target="_blank">http://lists.xiph.org/mailman/listinfo/vorbis-dev</a><br>
</font></span></blockquote></div><br></div>