[Speex-dev] Speex seek with high precision
Arnau Alemany
arnau.alemany at gmail.com
Sat May 16 02:50:01 PDT 2009
Hello,
This is the code, it's a little crap but only to see if it works. I assume
rate = 16000 and frame_size = 320.
if (this->seek_to != -1) // SKIP
{
ogg_int64_t max_units;
//max_units = speex_seek(fin, this->seek_to, 0, rate);
int nPages = 0;
int nPackets = 0;
// Pone el cursor en la posición inicial del fichero
fseek(fin, 0, SEEK_SET);
ogg_int64_t position = (this->seek_to * rate) / 1000;
ogg_int64_t granulepos;
do
{ // Skip pages until the page we want to seek
granulepos = ogg_page_granulepos(&og); // previous granulepos
while (ogg_sync_pageout(&oy, &og) != 1)
{
data = ogg_sync_buffer(&oy, 512);
nb_read = fread(data, 1, 512, fin);
ogg_sync_wrote(&oy, nb_read);
}
nPages++;
}
while (ogg_page_granulepos(&og) < position);
printf("ogg_page_packets: %d\n", ogg_page_packets(&og));
// Add page to the bitstream
ogg_stream_pagein(&os, &og);
printf("ogg_page_packets: %d\n", ogg_page_packets(&og));
/* Packet counter */
int res;
while (true)
{
res = ogg_stream_packetout(&os, &op);
if (res == 1)
nPackets++;
if (res == -1)
printf("out of sync\n");
if (res == 0)
break;
}
printf("nPackets: %d\n", nPackets);
}
Output is:
ogg_page_granulepos: 164
ogg_page_granulepos: 164
nPackets: 189 // it depends on the page
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):
while (granulepos < position) // this is almost correct but not always
{ // maybe due to the packet
number difference
if (ogg_stream_packetout(&os, &op) == 1)
{
granulepos += 320; // granulepos + FRAME_SIZE
//printf("granulepos: %lld\n", granulepos);
nPackets++;
}
}
Thank you,
Arnau
2009/5/16 Conrad Parker <conrad at metadecks.org>
>
> you mean the number of packets counted is different? Perhaps you are
> feeding pages in differently or something. Can you post your full
> code, including the calls to ogg_stream_pagein()?
>
> Conrad.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/speex-dev/attachments/20090516/d4574592/attachment.htm
More information about the Speex-dev
mailing list