Hello, <br>This is the code, it's a little crap but only to see if it works. I assume rate = 16000 and frame_size = 320. <br><br><div style="margin-left: 40px;">if (this->seek_to != -1) // SKIP<br>{<br> ogg_int64_t max_units;<br>
//max_units = speex_seek(fin, this->seek_to, 0, rate);<br><br> int nPages = 0;<br> int nPackets = 0;<br><br> // Pone el cursor en la posición inicial del fichero<br> fseek(fin, 0, SEEK_SET);<br> <br>
ogg_int64_t position = (this->seek_to * rate) / 1000;<br> ogg_int64_t granulepos;<br><br> do<br> { // Skip pages until the page we want to seek<br> granulepos = ogg_page_granulepos(&og); // previous granulepos<br>
while (ogg_sync_pageout(&oy, &og) != 1)<br> { <br> data = ogg_sync_buffer(&oy, 512);<br> nb_read = fread(data, 1, 512, fin);<br> ogg_sync_wrote(&oy, nb_read);<br>
}<br> nPages++;<br> }<br> while (ogg_page_granulepos(&og) < position); <br><br> printf("ogg_page_packets: %d\n", ogg_page_packets(&og));<br><br> // Add page to the bitstream<br>
ogg_stream_pagein(&os, &og);<br><br> printf("ogg_page_packets: %d\n", ogg_page_packets(&og));<br><br> /* Packet counter */<br> int res;<br> while (true)<br> {<br> res = ogg_stream_packetout(&os, &op);<br>
<br> if (res == 1)<br> nPackets++;<br> <br> if (res == -1)<br> printf("out of sync\n");<br> <br> if (res == 0)<br> break;<br> }<br>
printf("nPackets: %d\n", nPackets);<br>}<br></div><br>Output is:<br><br><div style="margin-left: 40px;">ogg_page_granulepos: 164<br>ogg_page_granulepos: 164<br>nPackets: 189 // it depends on the page <br><br>
</div>To do the seeking I change the /*Packet Counter*/ loop by this code and it almost works well but with a little delay sometimes (always starts decoding little before): <br><br><div style="margin-left: 40px;">while (granulepos < position) // this is almost correct but not always<br>
{ // maybe due to the packet number difference<br> if (ogg_stream_packetout(&os, &op) == 1)<br> {<br> granulepos += 320; // granulepos + FRAME_SIZE <br>
//printf("granulepos: %lld\n", granulepos);<br> nPackets++;<br> } <br> }<br></div><br>Thank you, <br>Arnau<br><br><br><div class="gmail_quote">2009/5/16 Conrad Parker <span dir="ltr"><<a href="mailto:conrad@metadecks.org">conrad@metadecks.org</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div class="h5">
<br>
</div></div>you mean the number of packets counted is different? Perhaps you are<br>
feeding pages in differently or something. Can you post your full<br>
code, including the calls to ogg_stream_pagein()?<br>
<font color="#888888"><br>
Conrad.<br>
</font></blockquote></div><br>