00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <dec_ogg.h>
00024 #include <jutils.h>
00025 #include <config.h>
00026
00027 #ifdef HAVE_VORBIS
00028
00029
00030
00031 MuseDecOgg::MuseDecOgg() : MuseDec() {
00032 func("MuseDecOgg::MuseDecOgg()");
00033
00034 old_section = current_section = -1;
00035
00036 oggfile = NULL;
00037
00038 strncpy(name,"Ogg",4);
00039 }
00040
00041 MuseDecOgg::~MuseDecOgg() {
00042 func("MuseDecOgg::~MuseDecOgg()");
00043 ov_clear(&vf);
00044 }
00045
00046 IN_DATATYPE *MuseDecOgg::get_audio() {
00047 int res;
00048
00049 old_section = current_section;
00050
00051 if(seekable) {
00052
00053 framepos = ov_pcm_tell(&vf);
00054 fps = samplerate;
00055 }
00056
00057 res =
00058 ov_read(&vf, _inbuf, IN_CHUNK, 0, 2, 1, ¤t_section);
00059
00060 if(res<0) {
00061 warning("MuseDecOgg:_get_audio() : bitstream error");
00062 err = true;
00063 return(NULL);
00064 }
00065
00066 if((res==0)||(old_section != current_section && old_section != -1)) {
00067
00068 eos = true;
00069 return(NULL);
00070 }
00071
00072 frames = res>>1;
00073
00074 return((IN_DATATYPE *)_inbuf);
00075 }
00076
00077 int MuseDecOgg::load(char *file) {
00078 int res = 0;
00079
00080 oggfile = fopen(file,"rb");
00081 if(oggfile==NULL) {
00082 error("MuseDecOgg::open(%s) : can't open file",file);
00083 return(res);
00084 }
00085
00086 if(ov_open(oggfile,&vf,NULL,0) < 0) {
00087 error("MuseDecOgg::open(%s): not a valid OggVorbis audio stream",file);
00088 fclose(oggfile);
00089 return(res);
00090 }
00091
00092 vc = ov_comment(&vf, -1);
00093 vi = ov_info(&vf, -1);
00094
00095 samplerate = vi->rate;
00096 channels = vi->channels;
00097 seekable = ov_seekable(&vf);
00098
00099
00100 framepos = 0;
00101
00102
00103 res = (ov_seekable(&vf)) ? 1 : 2;
00104 seekable = (res>1) ? false : true;
00105
00106 if(seekable)
00107 frametot = ov_pcm_total(&vf,-1);
00108
00109 return(res);
00110 }
00111
00112 bool MuseDecOgg::seek(float pos) {
00113
00114 if(pos==0.0) {
00115 if(ov_pcm_seek(&vf,1)!=0) {
00116 error("MuseDecOgg::pos : error in ov_pcm_seek(%p,1)",&vf);
00117 return(false);
00118 }
00119
00120 } else {
00121
00122 if(ov_pcm_seek_page(&vf,(ogg_int64_t)((double)frametot * pos))!=0) {
00123 error("MuseDecOgg::play : error in ov_pcm_seek_page(%p,%u)",
00124 (ogg_int64_t)((double)frametot * pos));
00125 return(false);
00126 }
00127 }
00128
00129 return(true);
00130 }
00131
00132 #endif