Chris@1: Chris@1: Chris@1: Chris@1: vorbisfile - Example Code Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:

Vorbisfile documentation

vorbisfile version 1.3.2 - 20101101

Chris@1: Chris@1:

Chaining Example Code

Chris@1: Chris@1:

Chris@1: The following is a run-through of the chaining example program supplied Chris@1: with vorbisfile - chaining_example.c. Chris@1: This program demonstrates how to work with a chained bitstream. 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: Chris@1: Chris@1:
Chris@1:

Chris@1: #include "vorbis/codec.h"
Chris@1: #include "vorbis/vorbisfile.h"
Chris@1: #include "../lib/misc.h"
Chris@1: 
Chris@1:
Chris@1: Chris@1:

Inside main(), we declare our primary OggVorbis_File structure. We also declare a other helpful variables to track our progress within the file. Chris@1:

Chris@1: Chris@1: Chris@1: 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: 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: 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: Chris@1:

We call ov_open_callbacks() to Chris@1: initialize the OggVorbis_File Chris@1: structure. ov_open_callbacks() Chris@1: also checks to ensure that we're reading Vorbis format and not Chris@1: something else. The OV_CALLBACKS_NOCLOSE callbacks instruct Chris@1: libvorbisfile not to close stdin later during cleanup.

Chris@1: Chris@1:

Chris@1: Chris@1: 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:

Chris@1: First we check to make sure the stream is seekable using ov_seekable. Chris@1: Chris@1:

Then we're going to find the number of logical bitstreams in the physical bitstream using ov_streams. Chris@1: Chris@1:

We use ov_time_total to determine the total length of the physical bitstream. We specify that we want the entire bitstream by using the argument -1. Chris@1: Chris@1:

Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1:

Chris@1:   if(ov_seekable(&ov)){
Chris@1:     printf("Input bitstream contained %ld logical bitstream section(s).\n",
Chris@1: 	   ov_streams(&ov));
Chris@1:     printf("Total bitstream playing time: %ld seconds\n\n",
Chris@1: 	   (long)ov_time_total(&ov,-1));
Chris@1: 
Chris@1:   }else{
Chris@1:     printf("Standard input was not seekable.\n"
Chris@1: 	   "First logical bitstream information:\n\n");
Chris@1:   }
Chris@1:   
Chris@1: 
Chris@1:
Chris@1: Chris@1:

Now we're going to iterate through each logical bitstream and print information about that bitstream. Chris@1: Chris@1:

We use ov_info to pull out the vorbis_info struct for each logical bitstream. This struct contains bitstream-specific info. Chris@1: Chris@1:

ov_serialnumber retrieves the unique serial number for the logical bistream. ov_raw_total gives the total compressed bytes for the logical bitstream, and ov_time_total gives the total time in the logical bitstream. Chris@1: Chris@1:

Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:
Chris@1:

Chris@1:   for(i=0;i<ov_streams(&ov);i++){
Chris@1:     vorbis_info *vi=ov_info(&ov,i);
Chris@1:     printf("\tlogical bitstream section %d information:\n",i+1);
Chris@1:     printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n",
Chris@1: 	   vi->rate,vi->channels,ov_bitrate(&ov,i)/1000,
Chris@1: 	   ov_serialnumber(&ov,i));
Chris@1:     printf("\t\tcompressed length: %ld bytes ",(long)(ov_raw_total(&ov,i)));
Chris@1:     printf(" play time: %lds\n",(long)ov_time_total(&ov,i));
Chris@1:   } 
Chris@1: 
Chris@1:
Chris@1:

Chris@1: When we're done with the entire physical bitstream, we need to call ov_clear() to release the bitstream. Chris@1: Chris@1:

Chris@1: Chris@1: 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:

Chris@1: The full source for chaining_example.c can be found with the vorbis Chris@1: distribution in chaining_example.c. Chris@1: Chris@1:

Chris@1:


Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1:

copyright © 2000-2010 Xiph.Org

Ogg Vorbis

Vorbisfile documentation

vorbisfile version 1.3.2 - 20101101

Chris@1: Chris@1: Chris@1: Chris@1: