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