5 #include "cOggDecoder.h" 7 #if CAUDIO_COMPILE_WITH_OGG_DECODER == 1 12 size_t VorbisRead(
void *ptr,
size_t byteSize,
size_t sizeToRead,
void *datasource)
14 IDataSource* Stream = (IDataSource*)datasource;
15 return Stream->read(ptr,byteSize*sizeToRead);
19 int VorbisSeek(
void *datasource,ogg_int64_t offset,
int whence)
21 IDataSource* Stream = (IDataSource*)datasource;
25 Stream->seek(offset,
false);
29 Stream->seek(offset,
true);
33 Stream->seek(Stream->getSize()-offset,
false);
40 long VorbisTell(
void *datasource)
42 return ((IDataSource*)datasource)->getCurrentPos();
45 int VorbisCloseFunc(
void *datasource)
50 cOggDecoder::cOggDecoder(IDataSource* stream) : IAudioDecoder(stream)
52 vorbisCallbacks.read_func = VorbisRead;
53 vorbisCallbacks.close_func = VorbisCloseFunc;
54 vorbisCallbacks.seek_func = VorbisSeek;
55 vorbisCallbacks.tell_func = VorbisTell;
56 Valid = (ov_open_callbacks(Stream,&oggStream,NULL,0,vorbisCallbacks) == 0);
60 vorbisInfo = ov_info(&oggStream, -1);
61 vorbisComment = ov_comment(&oggStream,-1);
65 cOggDecoder::~cOggDecoder()
74 if(vorbisInfo->channels == 1)
76 return EAF_16BIT_MONO;
80 return EAF_16BIT_STEREO;
86 int cOggDecoder::getFrequency()
90 return vorbisInfo->rate;
95 bool cOggDecoder::isSeekingSupported()
99 return (ov_seekable(&oggStream)!=0);
104 bool cOggDecoder::isValid()
109 int cOggDecoder::readAudioData(
void* output,
int amount)
114 return ov_read(&oggStream,(
char*)output,amount,0,2,1,&temp);
119 bool cOggDecoder::setPosition(
int position,
bool relative)
123 if(ov_seekable(&oggStream))
125 return (ov_raw_seek(&oggStream,position)==0);
131 bool cOggDecoder::seek(
float seconds,
bool relative)
135 if(ov_seekable(&oggStream))
139 double curtime = ov_time_tell(&oggStream);
140 return (ov_time_seek(&oggStream,curtime+seconds)==0);
143 return (ov_time_seek(&oggStream,seconds)==0);
149 float cOggDecoder::getTotalTime()
151 return ov_time_total(&oggStream, -1);
154 int cOggDecoder::getTotalSize()
157 return ov_pcm_total(&oggStream, -1) * vorbisInfo->channels * 2;
160 int cOggDecoder::getCompressedSize()
162 return ov_raw_total(&oggStream, -1);
165 float cOggDecoder::getCurrentTime()
167 return ov_time_tell(&oggStream);
170 int cOggDecoder::getCurrentPosition()
173 return ov_pcm_tell(&oggStream) * vorbisInfo->channels * 2;
176 int cOggDecoder::getCurrentCompressedPosition()
178 return ov_raw_tell(&oggStream);
181 cAudioString cOggDecoder::getType()
const 183 return cAudioString(_CTEXT(
"cOggDecoder"));
AudioFormats
Enumeration of audio formats supported by the engine.
Main namespace for the entire cAudio library.