[vorbis] ov_pcm_seek

Frank Heckenbach frank at g-n-u.de
Tue Mar 13 14:34:33 PST 2001



Michael Smith wrote:

> At 05:13 AM 3/13/01 +0100, you wrote:
> >How do I seek back to the beginning of a stream using ov_pcm_seek()?
> >ov_pcm_seek(0) doesn't seem to do anything, though ov_pcm_tell()
> >returns 0 right after opening the stream.
> >
> >I'm now using ov_pcm_seek(1) which seems to work, but I'm not sure
> >if that's really right. Are PCM offsets meant to be 0 or 1 based? Is
> >this a bug?
> 
> It's probably a bug elsewhere in your code. ov_pcm_seek() to zero is 
> intended to work, and does work for other people. There have been other
> reports from developers of ov_pcm_seek(0) failing, but all of these have
> either been unreproducible, or turned out to be errors elsewhere in the
> program. The offset is 0-based.

Well, I was wrong in saying that it doesn't do anything -- it does
some seeking, but not to the beginning of the stream. I can
reproduce it with the following code, based on the example in the
documentation (using beta4).

#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <vorbis/vorbisfile.h>

int main(int argc, char **argv)
{
  OggVorbis_File vf;
  char pcmout[4096];
  int i=0, r=44100, s=1, w=16, ret, cs=0, of=open("/dev/dsp",O_WRONLY);
  ioctl(of,SNDCTL_DSP_SAMPLESIZE,&w);
  ioctl(of,SNDCTL_DSP_STEREO,&s);
  ioctl(of,SNDCTL_DSP_SPEED,&r);
  if (argc != 2 || ov_open(fopen(argv[1],"r"),&vf,NULL,0) < 0)
    return 1;
  while (1)
    {
      fprintf(stderr,"%i:",(int)ov_pcm_tell(&vf));
      ret=ov_read(&vf,pcmout,sizeof(pcmout),0,2,1,&cs);
      if (ret < 0)
        break;
      else
        {
          fprintf(stderr,"%i ",ret);
          write(of,pcmout,ret);
          if (++i % 20 == 0)
            {
              ov_pcm_seek(&vf,0);
              fprintf(stderr,"\n");
            }
        }
    }
  ov_clear(&vf);
  return 0;
}

When using it to play a stream that has a clearly audible effect at
the beginning (not a fade-in or something), it's apparent that this
effect it missing in the repetitions.

The offsets that I'm printing for debugging also show that there
seems to be something wrong. The -1 after the seek looks strange,
and later the offset jumps from 11647 to 27008 while only 4096 bytes
(i.e., 1024 samples; 16 bit stereo) are decoded.

0:4096 1024:4096 2048:4096 3072:4096 4096:4096 5120:4096 6144:4096 7168:4096 8192:4096 9216:4096 10240:4096 11264:4096 12288:1536 12672:4096 13696:4096 14720:4096 15744:4096 16768:4096 17792:4096 18816:4096
-1:1536 383:4096 1407:4096 2431:4096 3455:4096 4479:4096 5503:4096 6527:4096 7551:4096 8575:4096 9599:4096 10623:4096 11647:4096 27008:4096 28032:4096 29056:4096 30080:4096 31104:4096 32128:4096 33152:4096
-1:1536 383:4096 1407:4096 2431:4096 3455:4096 4479:4096 5503:4096 6527:4096 7551:4096 8575:4096 9599:4096 10623:4096 11647:4096 27008:4096 28032:4096 29056:4096 30080:4096 31104:4096 32128:4096 33152:4096
...

Well, I did some debugging now. The problem seems to be that
ov_pcm_seek_page returns an error because "verify result" fails.
Maybe it's a simple off-by-one error (or is vf->pcm_offset expected
to be negative when seeking to position 0?). At least, doing the
following change made the test program work.

--- libvorbis-1.0beta4/lib/vorbisfile.c.orig	Tue Mar 13 23:00:59 2001
+++ libvorbis-1.0beta4/lib/vorbisfile.c	Tue Mar 13 23:19:40 2001
@@ -915,7 +915,7 @@
   }
 
   /* verify result */
-  if(vf->pcm_offset>=pos || pos>ov_pcm_total(vf,-1)){
+  if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
     ret=OV_EFAULT;
     goto seek_error;
   }

Frank


-- 
Frank Heckenbach, frank at g-n-u.de
http://fjf.gnu.de/
PGP and GPG keys: http://fjf.gnu.de/plan

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.




More information about the Vorbis mailing list