Vorbisfile documentation |
vorbisfile version 1.2.0 - 20070723 |
declared in "vorbis/vorbisfile.h";
This is an alternative function used to open and initialize an OggVorbis_File structure when using a data source other than a file, when its necessary to modify default file access behavior, or to initialize a Vorbis decode from a FILE * pointer under Windows where ov_open() cannot be used. It allows the application to specify custom file manipulation routines and sets up all the related decoding structures.
Once ov_open_callbacks() has been called, the same OggVorbis_File struct should be passed to all the libvorbisfile functions. Unlike ov_fopen() and ov_open(), ov_open_callbacks() may be used to instruct vorbisfile to either automatically close or not to close the file/data access handle in ov_clear(). Automatic closure is disabled by passing NULL as the close callback, or using one of the predefined callback sets that specify a NULL close callback. The application is responsible for closing a file when a call to ov_open_callbacks() is unsuccessful.
See also Callbacks and Non-stdio I/O for information on designing and specifying custom callback functions.
int ov_open_callbacks(void *datasource, OggVorbis_File *vf, char *initial, long ibytes, ov_callbacks callbacks); |
0 for success less than zero for failure:
- OV_EREAD - A read from media returned an error.
- OV_ENOTVORBIS - Bitstream does not contain any Vorbis data.
- OV_EVERSION - Vorbis version mismatch.
- OV_EBADHEADER - Invalid Vorbis bitstream header.
- OV_EFAULT - Internal logic fault; indicates a bug or heap/stack corruption.
Windows applications should not use ov_open() due to the likelihood of CRT linking mismatches and runtime protection faults [ov_open:a]. ov_open_callbacks() is a safe substitute; specifically:
ov_open_callbacks(f, vf, initial, ibytes, OV_CALLBACKS_DEFAULT);... provides exactly the same functionality as ov_open() but will always work correctly under Windows, regardless of linking setup details.
{
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);
}
|
Here's the read loop:
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;
}
}
|