### Libvorbisenc Functions for Setup Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisenc/overview.html Lists key functions used in the libvorbisenc setup process. These functions handle different aspects of initializing and configuring the Vorbis encoder. ```c vorbis_encode_setup_vbr(vorbis_info *vi, int channels, long rate, float base_quality) vorbis_encode_setup_managed(vorbis_info *vi, int channels, long rate, int bitrate) vorbis_encode_ctl(vorbis_info *vi, int request, void *data) vorbis_encode_setup_init(vorbis_info *vi) vorbis_encode_init_vbr(vorbis_info *vi, int channels, long rate, float quality) vorbis_encode_init(vorbis_info *vi, int channels, long rate, int bitrate, int max_bitrate, int min_bitrate, int nominal_bitrate, int vbrmode) OV_ECTL_COUPLE_SET: A request code for vorbis_encode_ctl to control stereo coupling. ``` -------------------------------- ### Vorbisfile C Example: Opening the Bitstream Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/seekingexample.html Initializes the OggVorbis_File structure using ov_open_callbacks and verifies that the input is a valid Ogg bitstream. ```C if(ov_open_callbacks(stdin, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) { fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n"); exit(1); } ``` -------------------------------- ### Vorbisfile C Example: Main Function Initialization Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/seekingexample.html Initializes the OggVorbis_File structure, declares variables for tracking progress, and sets stdin/stdout to binary mode for Windows compatibility. ```C int main(int argc, char **argv){ OggVorbis_File vf; int eof=0; int current_section; #ifdef _WIN32 _setmode( _fileno( stdin ), _O_BINARY ); #endif ``` -------------------------------- ### Vorbis Encode Setup VBR Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisenc/vorbis_encode_setup_vbr.html Initializes the variable bitrate (VBR) encoding setup for Vorbis. This function is the first step in a three-step VBR setup, allowing for further configuration via vorbis_encode_ctl before finalizing with vorbis_encode_setup_init. The vorbis_info struct must be initialized beforehand. ```c extern int vorbis_encode_init_vbr(vorbis_info *vi, long channels, long rate, float base_quality); ``` -------------------------------- ### Vorbisfile C Example: Include Headers Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/seekingexample.html Includes standard I/O, standard library, math, and vorbis-specific headers for audio decoding. Also includes Windows-specific headers for binary mode file operations. ```C #include #include #include #include "vorbis/codec.h" #include "vorbis/vorbisfile.h" ``` ```C #ifdef _WIN32 #include #include #endif ``` -------------------------------- ### Vorbisfile Chaining Example Initialization Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/chainingexample.html Includes necessary headers for Vorbisfile and initializes the OggVorbis_File structure. It also handles setting stdin to binary mode on Windows. ```C #include "vorbis/codec.h" #include "vorbis/vorbisfile.h" #include "../lib/misc.h" int main(){ OggVorbis_File ov; int i; ``` ```C #ifdef _WIN32 /* We need to set stdin to binary mode under Windows */ _setmode( _fileno( stdin ), _O_BINARY ); #endif ``` -------------------------------- ### Vorbisfile Chaining Example in C Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/chaining_example_c.html This C code demonstrates how to open and process chained Ogg Vorbis bitstreams from standard input using the vorbisfile library. It iterates through each logical bitstream, printing details like sample rate, channels, bitrate, and playback duration. The example includes platform-specific handling for Windows and checks for seekability. ```c #include #include int main(){ OggVorbis_File ov; int i; #ifdef _WIN32 /* We need to set stdin to binary mode on windows. */ _setmode( _fileno( stdin ), _O_BINARY ); #endif /* open the file/pipe on stdin */ if(ov_open_callbacks(stdin,&ov,NULL,-1,OV_CALLBACKS_NOCLOSE)<0){ printf("Could not open input as an OggVorbis file.\n\n"); exit(1); } /* print details about each logical bitstream in the input */ if(ov_seekable(&ov)){ printf("Input bitstream contained %ld logical bitstream section(s).\n", ov_streams(&ov)); printf("Total bitstream playing time: %ld seconds\n\n", (long)ov_time_total(&ov,-1)); }else{ printf("Standard input was not seekable.\n" "First logical bitstream information:\n\n"); } for(i=0;irate,vi->channels,ov_bitrate(&ov,i)/1000, ov_serialnumber(&ov,i)); printf("\t\tcompressed length: %ld bytes ",(long)(ov_raw_total(&ov,i))); printf(" play time: %lds\n",(long)ov_time_total(&ov,i)); } ov_clear(&ov); return 0; } ``` -------------------------------- ### Vorbisfile Example Code Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/exampleindex.html Includes three sample programs demonstrating vorbisfile functionality: decoding, seeking, and bitstream chaining. ```English vorbisfile decoding (example.html) vorbisfile seeking (seekexample.html) vorbisfile bitstream chaining (chainingexample.html) ``` -------------------------------- ### Vorbisfile C Example: Retrieving File Information Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/seekingexample.html Retrieves and displays channel count, bitrate, and user comments from the Ogg Vorbis file using ov_info and ov_comment. ```C { char **ptr=ov_comment(&vf,-1)->user_comments; vorbis_info *vi=ov_info(&vf,-1); while(*ptr){ fprintf(stderr,"%s\n",*ptr); ++ptr; } fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate); fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor); } ``` -------------------------------- ### Vorbisfile Seeking Example Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/seekexample.html Demonstrates seeking within an Ogg Vorbis audio stream using the vorbisfile library. Includes header includes, structure initialization, handling Windows-specific binary mode for stdin, opening the stream, checking seekability, performing random seeks using ov_time_seek, and clearing the stream resources. ```c #include #include #include "vorbis/codec.h" #include "vorbis/vorbisfile.h" ``` ```c int main(){ OggVorbis_File ov; int i; ``` ```c #ifdef _WIN32 /* We need to set stdin to binary mode under Windows */ _setmode( _fileno( stdin ), _O_BINARY ); #endif ``` ```c if(ov_open_callbacks(stdin,&ov,NULL,-1, OV_CALLBACKS_NOCLOSE)<0){ printf("Could not open input as an OggVorbis file.\n\n"); exit(1); } ``` ```c /* print details about each logical bitstream in the input */ if(ov_seekable(&ov)){ double length=ov_time_total(&ov,-1); printf("testing seeking to random places in %g seconds....\n",length); for(i=0;i<100;i++){ double val=(double)rand()/RAND_MAX*length; ov_time_seek(&ov,val); printf("\r\t%d [\%gs]... ",i,val); fflush(stdout); } printf("\r \nOK.\n\n"); }else{ printf("Standard input was not seekable.\n"); } ``` ```c ov_clear(&ov); return 0; } ``` -------------------------------- ### vorbis_encode_setup_init Function Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisenc/vorbis_encode_setup_init.html Finalizes the high-level encoding structure into a complete encoding setup for Ogg Vorbis. Requires prior initialization of vorbis_info and either vorbis_encode_setup_managed or vorbis_encode_setup_vbr. ```APIDOC vorbis_encode_setup_init(vi) Parameters: vi: Pointer to an initialized vorbis_info struct. Return Values: 0 for success less than zero for failure: OV_EFAULT - Internal logic fault; indicates a bug or heap/stack corruption. OV_EINVAL - Attempt to use vorbis_encode_setup_init() without first calling one of vorbis_encode_setup_managed() or vorbis_encode_setup_vbr() to initialize the high-level encoding setup. ``` -------------------------------- ### Vorbisfile Example C Program Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/vorbisfile_example_c.html This C code demonstrates how to open, read, and process an Ogg Vorbis audio file using the vorbisfile library. It reads audio data from stdin and writes decoded PCM to stdout. ```c #include #include #include #include "vorbis/codec.h" #include "vorbis/vorbisfile.h" #ifdef _WIN32 #include #include #endif char pcmout[4096]; int main(int argc, char **argv){ OggVorbis_File vf; int eof=0; int current_section; #ifdef _WIN32 _setmode( _fileno( stdin ), _O_BINARY ); _setmode( _fileno( stdout ), _O_BINARY ); #endif if(ov_open_callbacks(stdin, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) { fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n"); exit(1); } { char **ptr=ov_comment(&vf,-1)->user_comments; vorbis_info *vi=ov_info(&vf,-1); while(*ptr){ fprintf(stderr,"%s\n",*ptr); ++ptr; } fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate); fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor); } while(!eof){ long ret=ov_read(&vf,pcmout,sizeof(pcmout),0,2,1,¤t_section); if (ret == 0) { /* EOF */ eof=1; } else if (ret < 0) { /* error in the stream. Not a problem, just reporting it in case we (the app) cares. In this case, we don't. */ } else { /* we don't bother dealing with sample rate changes, etc, but you'll have to */ fwrite(pcmout,1,ret,stdout); } } ov_clear(&vf); fprintf(stderr,"Done.\n"); return(0); } ``` -------------------------------- ### Vorbisfile Decoding Example Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/example.html This C code demonstrates how to decode an Ogg Vorbis bitstream from standard input and write the raw PCM audio data to standard output using the libvorbisfile library. It includes necessary headers, buffer declarations, initialization with ov_open_callbacks, reading audio data with ov_read, and cleanup with ov_clear. It also includes Windows-specific handling for binary file modes. ```C #include #include #include #include "vorbis/codec.h" #include "vorbisfile.h" #ifdef _WIN32 #include #include #endif char pcmout[4096]; int main(int argc, char **argv){ OggVorbis_File vf; int eof=0; int current_section; #ifdef _WIN32 _setmode( _fileno( stdin ), _O_BINARY ); _setmode( _fileno( stdout ), _O_BINARY ); #endif if(ov_open_callbacks(stdin, &vf, NULL, 0, OV_CALLBACKS_NOCLOSE) < 0) { fprintf(stderr,"Input does not appear to be an Ogg bitstream.\n"); exit(1); } { char **ptr=ov_comment(&vf,-1)->user_comments; vorbis_info *vi=ov_info(&vf,-1); while(*ptr){ fprintf(stderr,"%s\n",*ptr); ++ptr; } fprintf(stderr,"\nBitstream is %d channel, %ldHz\n",vi->channels,vi->rate); fprintf(stderr,"\nDecoded length: %ld samples\n", (long)ov_pcm_total(&vf,-1)); fprintf(stderr,"Encoded by: %s\n\n",ov_comment(&vf,-1)->vendor); } while(!eof){ long ret=ov_read(&vf,pcmout,sizeof(pcmout),0,2,1,¤t_section); if (ret == 0) { /* EOF */ eof=1; } else if (ret < 0) { /* error in the stream. Not a problem, just reporting it in case we (the app) cares. In this case, we don't. */ } else { /* we don't bother dealing with sample rate changes, etc, but you'll have to*/ fwrite(pcmout,1,ret,stdout); } } ov_clear(&vf); fprintf(stderr,"Done.\n"); return(0); } ``` -------------------------------- ### Ogg Vorbis Programming Guides Source: https://github.com/xiph/vorbis/blob/main/doc/index.html Programming documentation for using Ogg Vorbis libraries, including libvorbis, vorbisfile, and vorbisenc. ```Documentation - [Programming with libvorbis](libvorbis/index.html) - [Programming with vorbisfile](vorbisfile/index.html) - [Programming with vorbisenc](vorbisenc/index.html) ``` -------------------------------- ### Vorbisfile API Reference - Setup and Teardown Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/reference.html Functions for initializing and clearing Vorbisfile resources, including opening files from various sources and testing stream integrity. ```APIDOC Setup/Teardown: [ov_fopen()](ov_fopen.html) [ov_open()](ov_open.html) [ov_open_callbacks()](ov_open_callbacks.html) [ov_clear()](ov_clear.html) [ov_test()](ov_test.html) [ov_test_callbacks()](ov_test_callbacks.html) [ov_test_open()](ov_test_open.html) ``` -------------------------------- ### APIDOC: vorbis_encode_setup_managed Function Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisenc/vorbis_encode_setup_managed.html Initializes the bitrate-managed encoding setup for libvorbisenc. This function sets up the encoding parameters based on specified channel count, sample rate, and bitrate constraints, allowing for subsequent fine-tuning. ```APIDOC vorbis_encode_setup_managed(vorbis_info *vi, long channels, long rate, long max_bitrate, long nominal_bitrate, long min_bitrate) Parameters: vi: Pointer to an initialized vorbis_info struct. channels: The number of channels to be encoded. rate: The sampling rate of the source audio. max_bitrate: Desired maximum bitrate (limit). -1 indicates unset. nominal_bitrate: Desired average, or central, bitrate. -1 indicates unset. min_bitrate: Desired minimum bitrate. -1 indicates unset. Return Values: 0 for success < 0 for failure: OV_EFAULT - Internal logic fault. OV_EINVAL - Invalid setup request. OV_EIMPL - Unimplemented mode. ``` -------------------------------- ### Libvorbis API Reference Source: https://github.com/xiph/vorbis/blob/main/doc/libvorbis/index.html Contains the detailed reference for the Libvorbis API, including function signatures, parameter descriptions, return values, and usage examples for the Vorbis encoder and decoder. ```APIDOC Libvorbis API Reference: This is the lowest-level interface to the Vorbis encoder and decoder. It includes functions for managing the encoding and decoding process, handling audio data, and configuring parameters. For simpler tasks like extracting audio from Ogg Vorbis files, consider using the [vorbisfile](../vorbisfile/index.html) interface. Key components: - Encoder functions: For compressing audio data into the Vorbis format. - Decoder functions: For decompressing Vorbis audio data back into raw audio. - Stream management: Functions for initializing, processing, and clearing encoder/decoder contexts. ``` -------------------------------- ### Vorbisenc Encoder Setup Functions Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisenc/reference.html Provides functions for initializing and configuring the Vorbis encoder, including managed and VBR (Variable Bitrate) modes. These functions are essential for setting up the encoding process. ```APIDOC vorbis_encode_ctl(): Controls the Vorbis encoder settings. vorbis_encode_init(): Initializes the Vorbis encoder. vorbis_encode_init_vbr(): Initializes the Vorbis encoder with VBR settings. vorbis_encode_setup_init(): Initializes the encoder setup structure. vorbis_encode_setup_managed(): Sets up the encoder for managed bitrate. vorbis_encode_setup_vbr(): Sets up the encoder for VBR. ``` -------------------------------- ### Build Vorbis from Source (autotools) Source: https://github.com/xiph/vorbis/blob/main/README.md Instructions for building the Vorbis libraries from development source using autotools. Requires autoconf, automake, libtool, and pkg-config. Installs libraries to /usr/local/lib. ```Shell ./autogen.sh ./configure make make install ``` -------------------------------- ### Vorbisfile Stream Opening and Information Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/chainingexample.html Opens the OggVorbis_File structure using ov_open_callbacks and checks for seekability. It then retrieves and prints the number of logical bitstreams and the total playback time. ```C if(ov_open_callbacks(stdin,&ov,NULL,-1,OV_CALLBACKS_NOCLOSE)<0){ printf("Could not open input as an OggVorbis file.\n\n"); exit(1); } ``` ```C if(ov_seekable(&ov)){ printf("Input bitstream contained %ld logical bitstream section(s).\n", ov_streams(&ov)); printf("Total bitstream playing time: %ld seconds\n\n", (long)ov_time_total(&ov,-1)); }else{ printf("Standard input was not seekable.\n" "First logical bitstream information:\n\n"); } ``` -------------------------------- ### Vorbis Pkg-config Installation Source: https://github.com/xiph/vorbis/blob/main/CMakeLists.txt Configures and installs the pkg-config files for Vorbis, vorbisenc, and vorbisfile. These files are placed in the installation's lib/pkgconfig directory, enabling other projects to easily link against Vorbis. ```cmake configure_pkg_config_file(vorbis.pc.in) configure_pkg_config_file(vorbisenc.pc.in) configure_pkg_config_file(vorbisfile.pc.in) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/vorbis.pc ${CMAKE_CURRENT_BINARY_DIR}/vorbisenc.pc ${CMAKE_CURRENT_BINARY_DIR}/vorbisfile.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) ``` -------------------------------- ### Libvorbisenc Workflow and Initialization Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisenc/overview.html Describes the typical workflow for using libvorbisenc to set up Vorbis encoding. It involves high-level initialization, optional parameter adjustments, and finalization for libvorbis. It also mentions convenience functions for direct setup. ```c 1. High-level initialization: Call vorbis_encode_setup_vbr() or vorbis_encode_setup_managed() with basic audio parameters. 2. Optional adjustment: Use vorbis_encode_ctl() to modify default settings. 3. Finalization: Call vorbis_encode_setup_init() to prepare vorbis_info for libvorbis. Alternatively, use vorbis_encode_init_vbr() for VBR setup or vorbis_encode_init() for managed bitrate setup. ``` -------------------------------- ### Vorbisfile C Example: PCM Output Buffer Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/seekingexample.html Declares a character buffer to hold the decoded PCM audio output data. ```C char pcmout[4096]; ``` -------------------------------- ### Vorbisfile C Example: Cleanup Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/seekingexample.html Cleans up the OggVorbis_File structure using ov_clear after processing is complete and returns 0 to indicate successful execution. ```C ov_clear(&vf); fprintf(stderr,"Done.\n"); return(0); } ``` -------------------------------- ### Vorbis Encode Setup VBR Parameters and Return Values Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisenc/vorbis_encode_setup_vbr.html Details the parameters and return values for the vorbis_encode_init_vbr function. Parameters include the vorbis_info struct, channel count, sample rate, and desired quality level. Return values indicate success (0) or various error codes for failures. ```APIDOC vorbis_encode_init_vbr(vi, channels, rate, base_quality) Parameters: vi: Pointer to an initialized vorbis_info struct. channels: The number of channels to be encoded. rate: The sampling rate of the source audio. base_quality: Desired quality level, currently from -0.1 to 1.0 (lo to hi). Return Values: 0 for success less than zero for failure: OV_EFAULT - Internal logic fault; indicates a bug or heap/stack corruption. OV_EINVAL - Invalid setup request, eg, out of range argument. OV_EIMPL - Unimplemented mode; unable to comply with quality level request. ``` -------------------------------- ### Vorbisfile Seeking Test Program (C) Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/seeking_example_c.html This C program demonstrates how to use the vorbisfile library to open an Ogg Vorbis file from standard input, test its seekability, and perform random seeks within the audio stream. It includes platform-specific handling for Windows and provides feedback on the seeking process. ```c #include #include #include "vorbis/codec.h" #include "vorbis/vorbisfile.h" int main(){ OggVorbis_File ov; int i; #ifdef _WIN32 /* We need to set stdin to binary mode under Windows */ _setmode( _fileno( stdin ), _O_BINARY ); #endif /* open the file/pipe on stdin */ if(ov_open_callbacks(stdin,&ov,NULL,-1,OV_CALLBACKS_NOC আকার)==-1){ printf("Could not open input as an OggVorbis file.\n\n"); exit(1); } /* print details about each logical bitstream in the input */ if(ov_seekable(&ov)){ double length=ov_time_total(&ov,-1); printf("testing seeking to random places in %g seconds....\n",length); for(i=0;i<100;i++){ double val=(double)rand()/RAND_MAX*length; ov_time_seek(&ov,val); printf("\r\t%d [%gs]... ",i,val); fflush(stdout); } printf("\r \nOK.\n\n"); }else{ printf("Standard input was not seekable.\n"); } ov_clear(&ov); return 0; } ``` -------------------------------- ### Vorbisfile C Example: Reading and Writing PCM Data Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/seekingexample.html Enters a loop to read PCM data in blocks using ov_read, writing valid data to stdout and handling end-of-file or invalid data conditions. ```C while(!eof){ long ret=ov_read(&vf,pcmout,sizeof(pcmout),0,2,1,¤t_section); switch(ret){ case 0: /* EOF */ eof=1; break; case -1: break; default: fwrite(pcmout,1,ret,stdout); break; } } ``` -------------------------------- ### Vorbisfile Seeking Test Program (C) Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/seeking_test_c.html This C program demonstrates how to use the vorbisfile library to open an Ogg Vorbis file from standard input, test its seekability, and perform random seeks within the audio stream. It includes platform-specific handling for Windows and provides feedback on the seeking process. ```c #include #include #include "vorbis/codec.h" #include "vorbis/vorbisfile.h" int main(){ OggVorbis_File ov; int i; #ifdef _WIN32 /* We need to set stdin to binary mode under Windows */ _setmode( _fileno( stdin ), _O_BINARY ); #endif /* open the file/pipe on stdin */ if(ov_open_callbacks(stdin,&ov,NULL,-1,OV_CALLBACKS_NOC আকার)==-1){ printf("Could not open input as an OggVorbis file.\n\n"); exit(1); } /* print details about each logical bitstream in the input */ if(ov_seekable(&ov)){ double length=ov_time_total(&ov,-1); printf("testing seeking to random places in %g seconds....\n",length); for(i=0;i<100;i++){ double val=(double)rand()/RAND_MAX*length; ov_time_seek(&ov,val); printf("\r\t%d [%gs]... ",i,val); fflush(stdout); } printf("\r \nOK.\n\n"); }else{ printf("Standard input was not seekable.\n"); } ov_clear(&ov); return 0; } ``` -------------------------------- ### Example RTP Packet with Two Vorbis Packets Source: https://github.com/xiph/vorbis/blob/main/doc/rfc5215.txt Illustrates an example RTP packet containing two Vorbis packets. It shows the RTP header fields and the payload data structure, including the payload header indicating 2 packets. ```APIDOC +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 2 |0|0| 0 |0| PT | sequence number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | timestamp (in sample rate units) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | synchronisation source (SSRC) identifier | +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ | contributing source (CSRC) identifiers | | ... | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Ident | 0 | 0 | 2 pks | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | length | vorbis data |.. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ .. vorbis data | ``` -------------------------------- ### Vorbisfile Initialization and Teardown Functions Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/initialization.html This section details the core functions for initializing and cleaning up Ogg Vorbis audio streams using the libvorbisfile library. These functions manage the bitstream and associated resources for decoding. ```APIDOC ov_fopen(const char *path) Opens a file and initializes the Ogg Vorbis bitstream with default values. This must be called before other functions in the library may be used. ov_open(FILE *f, int close_existing) Initializes the Ogg Vorbis bitstream with default values from a passed in file handle. This must be called before other functions in the library may be used. Do not use this call under Windows; Use ov_fopen() or ov_open_callbacks() instead. ov_open_callbacks(void *datasource, ov_callbacks callbacks, int close_existing) Initializes the Ogg Vorbis bitstream from a file handle and custom file/bitstream manipulation routines. Used instead of ov_open() or ov_fopen() when altering or replacing libvorbis's default stdio I/O behavior, or when a bitstream must be initialized from a FILE * under Windows. ov_test(const char *path) Partially opens a file just far enough to determine if the file is an Ogg Vorbis file or not. A successful return indicates that the file appears to be an Ogg Vorbis file, but the OggVorbis_File struct is not yet fully initialized for actual decoding. After a successful return, the file may be closed using ov_clear() or fully opened for decoding using ov_test_open(). This call is intended to be used as a less expensive file open test than a full ov_open(). Note that libvorbisfile owns the passed in file resource is it returns success; do not fclose() files owned by libvorbisfile. ov_test_callbacks(void *datasource, ov_callbacks callbacks) As above but allowing application-define I/O callbacks. Note that libvorbisfile owns the passed in file resource is it returns success; do not fclose() files owned by libvorbisfile. ov_test_open(OggVorbis_File *vf) Finish opening a file after a successful call to ov_test() or ov_test_callbacks(). ov_clear(OggVorbis_File *vf) Closes the bitstream and cleans up loose ends. Must be called when finished with the bitstream. After return, the OggVorbis_File struct is invalid and may not be used before being initialized again before begin reinitialized. ``` -------------------------------- ### Vorbisfile Cleanup Source: https://github.com/xiph/vorbis/blob/main/doc/vorbisfile/chainingexample.html Cleans up the OggVorbis_File structure to release resources after processing. ```C ov_clear(&ov); return 0; } ``` -------------------------------- ### Libvorbis Encoding Workflow Source: https://github.com/xiph/vorbis/blob/main/doc/libvorbis/overview.html Details the steps required to encode audio using the libvorbis library. It covers initialization of Vorbis structures, buffer management, block processing, and packet output. ```APIDOC Encoding workflow: 1. Initialize vorbis_info structure using vorbis_info_init() and libvorbisenc functions. 2. Initialize vorbis_dsp_state for encoding using vorbis_analysis_init(). 3. Initialize vorbis_comment structure using vorbis_comment_init(), populate comments, and call vorbis_analysis_headerout() to get header packets. 4. Initialize vorbis_block structure using vorbis_block_init(). 5. While encoding: a. Submit audio data using vorbis_analysis_buffer() and vorbis_analysis_wrote(). b. Obtain blocks using vorbis_analysis_blockout(). c. Encode block using vorbis_analysis() or manage bitrate with vorbis_bitrate_addblock() and vorbis_bitrate_flushpacket(). d. Output packets. 6. Submit empty buffer for end-of-stream packet. 7. Clear structures using vorbis_*_clear routines. ``` -------------------------------- ### Vorbis Decoding Example Source: https://github.com/xiph/vorbis/blob/main/doc/Vorbis_I_spec.html Illustrates reading arbitrary-width integer fields from a bytestream, explaining the interpretation of signedness and the handling of bitstream boundaries. ```C // Reading two, two-bit integer fields from the bytestream. // Results: 'b00' and 'b11'. // Interpretation of 'b11' can be unsigned '3' or signed '-1'. ``` -------------------------------- ### Vorbis Coding Examples Source: https://github.com/xiph/vorbis/blob/main/doc/Vorbis_I_spec.html Demonstrates coding integer values of various bit widths into a bytestream, showing the resulting bit patterns and byte alignments. ```C // Coding a 4 bit integer value '12' [b1100] into an empty bytestream. // Bytestream result: // byte 0 [0 0 0 0 1 1 0 0] <- ``` ```C // Coding a 3 bit integer value '-1' [b111] into the bytestream. // Bytestream result: // byte 0 [0 1 1 1 1 1 0 0] <- ``` ```C // Coding a 7 bit integer value '17' [b0010001] into the bytestream. // Bytestream result: // byte 0 [1 1 1 1 1 1 0 0] // byte 1 [0 0 0 0 1 0 0 0] <- ``` ```C // Coding a 13 bit integer value '6969' [b110 11001110 01] into the bytestream. // Bytestream result: // byte 0 [1 1 1 1 1 1 0 0] // byte 1 [0 1 0 0 1 0 0 0] // byte 2 [1 1 0 0 1 1 1 0] // byte 3 [0 0 0 0 0 1 1 0] <- ``` -------------------------------- ### Libvorbis Decoding Workflow Source: https://github.com/xiph/vorbis/blob/main/doc/libvorbis/overview.html Outlines the process for decoding audio streams using the libvorbis library. It includes steps for header processing, synthesis initialization, block decoding, and PCM output. ```APIDOC Decoding workflow: 1. Check for Vorbis stream using vorbis_synthesis_idheader(). 2. Initialize vorbis_info and vorbis_comment structures using vorbis_*_init() and process header packets with vorbis_synthesis_headerin(). 3. Initialize vorbis_dsp_state for decoding using vorbis_synthesis_init(). 4. Initialize vorbis_block structure using vorbis_block_init(). 5. While decoding: a. Decode packet into block using vorbis_synthesis(). b. Submit block to reassembly layer using vorbis_synthesis_blockin(). c. Obtain decoded audio using vorbis_synthesis_pcmout() and vorbis_synthesis_read(). 6. Clear structures using vorbis_*_clear routines. ```