43 #ifndef _audiovorbisdecoder_cpp
44 #define _audiovorbisdecoder_cpp
46 #ifdef ENABLE_VORBIS_ENCODE
48 #include "Audio/vorbisdecoder.h"
53 #include <vorbis/codec.h>
54 #include <vorbis/vorbisfile.h>
60 size_t VorbisRead(
void *ptr,
size_t byteSize,
size_t sizeToRead,
void *datasource)
63 return Stream->
Read(ptr,byteSize * sizeToRead);
68 int VorbisSeek(
void *datasource,ogg_int64_t offset,
int whence)
82 long VorbisTell(
void *datasource)
89 int VorbisClose(
void *datasource)
104 class MEZZ_LIB VorbisDecoderInternalData
112 vorbis_info* VorbisInfo;
114 vorbis_comment* VorbisComments;
116 ov_callbacks VorbisCallbacks;
118 OggVorbis_File VorbisFile;
124 VorbisDecoderInternalData()
126 VorbisCallbacks.read_func = VorbisRead;
127 VorbisCallbacks.seek_func = VorbisSeek;
128 VorbisCallbacks.tell_func = VorbisTell;
129 VorbisCallbacks.close_func = VorbisClose;
132 ~VorbisDecoderInternalData() { }
137 : VorbisStream(Stream),
140 this->VDID =
new VorbisDecoderInternalData();
141 this->Valid = ( ov_open_callbacks(VorbisStream.get(),&(this->VDID->VorbisFile),NULL,0,this->VDID->VorbisCallbacks) == 0 );
145 this->VDID->VorbisInfo = ov_info( &(this->VDID->VorbisFile), -1 );
146 this->VDID->VorbisComments = ov_comment( &(this->VDID->VorbisFile), -1 );
150 VorbisDecoder::~VorbisDecoder()
152 ov_clear( &(this->VDID->VorbisFile) );
158 String VorbisDecoder::GetUserComment(
const UInt32 Index)
160 Char8* Comment = this->VDID->VorbisComments->user_comments[Index];
161 Integer CommentLength = this->VDID->VorbisComments->comment_lengths[Index];
162 return String(Comment,CommentLength);
165 UInt32 VorbisDecoder::GetNumUserComments()
const
167 return this->VDID->VorbisComments->comments;
173 bool VorbisDecoder::IsValid()
183 bool VorbisDecoder::IsSeekingSupported()
185 if( this->Valid )
return (ov_seekable( &(this->VDID->VorbisFile) ) != 0);
193 switch( this->VDID->VorbisInfo->channels )
195 case 1:
return Audio::BC_16Bit_Mono;
break;
196 case 2:
return Audio::BC_16Bit_Stereo;
break;
200 return Audio::BC_8Bit_Mono;
203 UInt32 VorbisDecoder::GetFrequency()
const
205 if( this->Valid )
return this->VDID->VorbisInfo->rate;
211 return this->VorbisStream;
214 bool VorbisDecoder::SetPosition(
Int32 Position,
bool Relative)
216 if( this->IsSeekingSupported() )
219 Real CurrPos = ov_raw_tell( &(this->VDID->VorbisFile) );
220 return ( ov_raw_seek( &(this->VDID->VorbisFile), CurrPos + Position ) == 0 );
222 return ( ov_raw_seek( &(this->VDID->VorbisFile), Position ) == 0 );
228 bool VorbisDecoder::Seek(
const Real Seconds,
bool Relative)
230 if( this->IsSeekingSupported() )
233 Real CurrTime = ov_time_tell( &(this->VDID->VorbisFile) );
234 return ( ov_time_seek( &(this->VDID->VorbisFile), CurrTime + Seconds ) == 0 );
236 return ( ov_time_seek( &(this->VDID->VorbisFile), Seconds ) == 0 );
242 UInt32 VorbisDecoder::ReadAudioData(
void* Output,
UInt32 Amount)
246 Integer Ret = ov_read( &(this->VDID->VorbisFile), (
Char8*)Output, Amount, 0, 2, 1, &Temp );
256 Real VorbisDecoder::GetTotalTime()
const
258 return ov_time_total( &(this->VDID->VorbisFile), -1 );
261 Real VorbisDecoder::GetCurrentTime()
const
263 return ov_time_tell( &(this->VDID->VorbisFile) );
266 UInt32 VorbisDecoder::GetTotalSize()
const
268 return ov_pcm_total( &(this->VDID->VorbisFile), -1 ) * this->VDID->VorbisInfo->channels;
271 UInt32 VorbisDecoder::GetCompressedSize()
const
273 return ov_raw_total( &(this->VDID->VorbisFile), -1 );
276 UInt32 VorbisDecoder::GetCurrentPosition()
const
278 return ov_pcm_tell( &(this->VDID->VorbisFile) ) * this->VDID->VorbisInfo->channels;
281 UInt32 VorbisDecoder::GetCurrentCompressedPosition()
const
283 return ov_raw_tell( &(this->VDID->VorbisFile) );
288 #endif //ENABLE_VORBIS_ENCODE