bool libname::COggStreamSample::Load( const char *szFilename ) { vorbis_info * pInfo; if ( !m_pFile ) m_pFile = fopen( szFilename, "rb"); if( ov_open_callbacks( m_pFile , &m_OggFile, NULL, 0, OV_CALLBACKS_DEFAULT) < 0) { cerr << "Input does not appear to be an Ogg bitstream." << endl; return false; } pInfo = ov_info(&m_OggFile,-1); SetNumChannels( pInfo->channels); // number of channels SetFreq( pInfo->rate); // The frequency of the sampling rate // Check the number of channels... always use 16-bit samples if (GetNumChannels() == 1) SetFormat( AL_FORMAT_MONO16 ); else SetFormat( AL_FORMAT_STEREO16 ); cerr << "Freq: " << GetFreq() << endl; cerr << "Channels: " << GetNumChannels() << endl; cerr << "Encoded: " << ov_comment(&m_OggFile,-1)->vendor << endl; m_lFileSize = ov_raw_total( &m_OggFile, -1); return true; }
/* returns: total raw (compressed) length of content if i==-1 raw (compressed) length of that logical bitstream for i==0 to n OV_EINVAL if the stream is not seekable (we can't know the length) or if stream is only partially open */ ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){ if(vf->ready_state<OPENED)return(OV_EINVAL); if(!vf->seekable || i>=vf->links)return(OV_EINVAL); if(i<0){ long acc=0; int i; for(i=0;i<vf->links;i++) acc+=ov_raw_total(vf,i); return(acc); }else{ return(vf->offsets[i+1]-vf->offsets[i]); } }
int main(){ OggVorbis_File ov; int i; #ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */ /* Beware the evil ifdef. We avoid these where we can, but this one we cannot. Don't add any more, you'll probably go to hell if you do. */ _setmode( _fileno( stdin ), _O_BINARY ); _setmode( _fileno( stdout ), _O_BINARY ); #endif /* open the file/pipe on stdin */ if(ov_open(stdin,&ov,NULL,-1)<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 samples: %ld\n\n", (long)ov_pcm_total(&ov,-1)); 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;i<ov_streams(&ov);i++){ vorbis_info *vi=ov_info(&ov,i); printf("\tlogical bitstream section %d information:\n",i+1); printf("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld\n", vi->rate,vi->channels,ov_bitrate(&ov,i)/1000, ov_serialnumber(&ov,i)); printf("\t\theader length: %ld bytes\n",(long) (ov.dataoffsets[i]-ov.offsets[i])); printf("\t\tcompressed length: %ld bytes\n",(long)(ov_raw_total(&ov,i))); printf("\t\tplay time: %lds\n",(long)ov_time_total(&ov,i)); } ov_clear(&ov); return 0; }
bool isis::codecs::ogg_vorbis::DecoderImpl::init() { int result = ov_open_callbacks(source_.get(), &vf_, NULL, 0, isis_ogg_vorbis_callbacks); if (0 != result) return false; vi_ = ov_info(&vf_, -1); if (!vi_) return false; source_size_ = ov_raw_total(&vf_, -1); pcm_count_ = ov_pcm_total(&vf_, -1); duration_ = ov_time_total(&vf_, -1); if (duration_ < 0) return false; return true; }
int alogg_get_length_bytes_ogg(ALOGG_OGG *ogg) { return ov_raw_total(&(ogg->vf), -1); }
int cOggDecoder::getCompressedSize() { return ov_raw_total(&oggStream, -1); }
/* open ogg/vorbis file */ static void oggread_open(t_oggread *x, t_symbol *filename) { int i; x->x_stream = 0; /* first close previous file */ if(x->x_fd > 0) { ov_clear(&x->x_ov); post("oggread~: previous file closed"); } /* open file for reading */ if((x->x_file = sys_fopen(filename->s_name, "rb")) <= 0) { post("oggread~: could not open file \"%s\"", filename->s_name); x->x_eos = 1; x->x_fd = -1; } else { x->x_stream = 0; x->x_eos = 0; x->x_fd = 1; x->x_outreadposition = 0; x->x_outwriteposition = 0; x->x_outunread = 0; post("oggread~: file \"%s\" opened", filename->s_name); outlet_float( x->x_out_position, 0); /* try to open as ogg vorbis file */ if(ov_open(x->x_file, &x->x_ov, NULL, -1) < 0) { /* an error occured (no ogg vorbis file ?) */ post("oggread~: error: could not open \"%s\" as an OggVorbis file", filename->s_name); ov_clear(&x->x_ov); post("oggread~: file closed due to error"); x->x_fd=-1; x->x_eos=1; return; } /* print details about each logical bitstream in the input */ if(ov_seekable(&x->x_ov)) { post("oggread~: input bitstream contained %ld logical bitstream section(s)", ov_streams(&x->x_ov)); post("oggread~: total bitstream playing time: %ld seconds", (long)ov_time_total(&x->x_ov,-1)); post("oggread~: encoded by: %s\n",ov_comment(&x->x_ov,-1)->vendor); } else { post("oggread~: file \"%s\" was not seekable\n" "oggread~: first logical bitstream information:", filename->s_name); } for(i = 0; i < ov_streams(&x->x_ov); i++) { x->x_vi = ov_info(&x->x_ov,i); post("\tlogical bitstream section %d information:",i+1); post("\t\t%ldHz %d channels bitrate %ldkbps serial number=%ld", x->x_vi->rate,x->x_vi->channels,ov_bitrate(&x->x_ov,i)/1000, ov_serialnumber(&x->x_ov,i)); post("\t\theader length: %ld bytes",(long) (x->x_ov.dataoffsets[i] - x->x_ov.offsets[i])); post("\t\tcompressed length: %ld bytes",(long)(ov_raw_total(&x->x_ov,i))); post("\t\tplay time: %ld seconds\n",(long)ov_time_total(&x->x_ov,i)); } } }