Chris@1: Chris@1: Chris@1:
Chris@1:Vorbisfile documentation |
Chris@1: vorbisfile version 1.3.2 - 20101101 |
Chris@1:
Chris@1: The following is a run-through of the seeking example program supplied Chris@1: with vorbisfile - seeking_test.c. Chris@1: This program tests the vorbisfile ov_time_seek function by seeking to random points within the file. Chris@1: Chris@1:
Chris@1: First, relevant headers, including vorbis-specific "codec.h" and "vorbisfile.h" have to be included.
Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1: #include <stdlib.h> Chris@1: #include <stdio.h> Chris@1: #include "vorbis/codec.h" Chris@1: #include "vorbis/vorbisfile.h" Chris@1:Chris@1: |
Chris@1:
Inside main(), we declare our primary OggVorbis_File structure. We also declare other helpful variables to track our progress within the file.
Chris@1:
Chris@1:
Chris@1: Chris@1: int main(){ Chris@1: OggVorbis_File ov; Chris@1: int i; Chris@1:Chris@1: |
Chris@1:
This example takes its input on stdin which is in 'text' mode by default under Windows; this will corrupt the input data unless set to binary mode. This applies only to Windows.
Chris@1:
Chris@1:
Chris@1: Chris@1: #ifdef _WIN32 /* We need to set stdin to binary mode under Windows */ Chris@1: _setmode( _fileno( stdin ), _O_BINARY ); Chris@1: #endif Chris@1:Chris@1: |
Chris@1:
ov_open() must be
Chris@1: called to initialize the OggVorbis_File structure with default values.
Chris@1: ov_open_callbacks() also checks to ensure that we're reading Vorbis format and not something else.
Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1: if(ov_open_callbacks(stdin,&ov,NULL,-1, OV_CALLBACKS_NOCLOSE)<0){ Chris@1: printf("Could not open input as an OggVorbis file.\n\n"); Chris@1: exit(1); Chris@1: } Chris@1: Chris@1:Chris@1: |
Chris@1:
Chris@1: First we check to make sure the stream is seekable using ov_seekable. Chris@1: Chris@1:
Then we seek to 100 random spots in the bitstream using ov_time_seek with randomly generated values.
Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1: Chris@1: /* print details about each logical bitstream in the input */ Chris@1: if(ov_seekable(&ov)){ Chris@1: double length=ov_time_total(&ov,-1); Chris@1: printf("testing seeking to random places in %g seconds....\n",length); Chris@1: for(i=0;i<100;i++){ Chris@1: double val=(double)rand()/RAND_MAX*length; Chris@1: ov_time_seek(&ov,val); Chris@1: printf("\r\t%d [%gs]... ",i,val); Chris@1: fflush(stdout); Chris@1: } Chris@1: Chris@1: printf("\r \nOK.\n\n"); Chris@1: }else{ Chris@1: printf("Standard input was not seekable.\n"); Chris@1: } Chris@1: Chris@1:Chris@1: |
Chris@1:
Chris@1: When we're done seeking, we need to call ov_clear() to release the bitstream.
Chris@1:
Chris@1:
Chris@1:
Chris@1: Chris@1: ov_clear(&ov); Chris@1: return 0; Chris@1: } Chris@1:Chris@1: |
Chris@1:
Chris@1: The full source for seeking_test.c can be found with the vorbis
Chris@1: distribution in seeking_test.c.
Chris@1:
Chris@1:
Chris@1:
copyright © 2000-2010 Xiph.Org |
Chris@1: Chris@1: |
Vorbisfile documentation |
Chris@1: vorbisfile version 1.3.2 - 20101101 |
Chris@1: