22 #if USE_OGGVORBIS != 1
23 #error USE_OGGVORBIS was not set to 1 in your settings.cfg file, but you are including files that require this. Please fix your settings.cfg
30 #include <vorbis/vorbisfile.h>
42 OggVorbisCodec::OggVorbisCodec()
60 OggVorbis_File vorbisFile;
62 memset( &vorbisFile, 0,
sizeof(OggVorbis_File) );
64 fileHandle = fopen( uri.c_str(),
"rb" );
66 if ( !fileHandle || ferror(fileHandle) != 0 )
74 int retval = ov_open( fileHandle, &vorbisFile,
NULL, 0 );
85 ov_clear( &vorbisFile );
96 if ( (hdr.GetChannels() < 0) || ( hdr.GetChannels() > 255) )
98 if ( (hdr.GetSampleRate() < 8000.) || ( hdr.GetSampleRate() > 192000.) )
112 OggVorbis_File vorbisFile;
114 if ( ( fileHandle = fopen( uri.c_str(),
"rb" ) ) ==
NULL )
117 if ( ov_open( fileHandle, &vorbisFile,
NULL, 0 ) < 0 )
119 fclose( fileHandle );
123 vorbis_info* fileInfo = ov_info( &vorbisFile, -1 );
137 hdr.SetSampleRate( (
TData)fileInfo->rate );
138 hdr.SetChannels( (
TSize)fileInfo->channels );
139 hdr.SetLength( (
TTime)ov_time_total( &vorbisFile, -1) * 1000. );
144 double duration = hdr.GetLength()/1000.;
145 hdr.SetSamples(
TSize(duration*hdr.GetSampleRate()) );
149 ov_clear( &vorbisFile );
155 OggVorbis_File vorbisFile;
157 if ( ( fileHandle = fopen( uri.c_str(),
"rb" ) ) ==
NULL )
160 if ( ov_open( fileHandle, &vorbisFile,
NULL, 0 ) < 0 )
162 fclose( fileHandle );
166 vorbis_info* fileInfo = ov_info( &vorbisFile, -1 );
172 vorbis_comment* fileComments = ov_comment( &vorbisFile, -1 );
179 int nComments = fileComments->comments;
180 char** commentVector = fileComments->user_comments;
181 int* commentLenVector = fileComments->comment_lengths;
183 for (
int i = 0; i < nComments; i++ )
186 std::string currentComment;
187 currentComment.assign( commentVector[i],
188 commentVector[i]+commentLenVector[i] );
190 std::string::iterator eqPos = std::find( currentComment.begin(),
191 currentComment.end(),
'=' );
193 if ( eqPos < currentComment.end() )
195 std::string fieldName;
196 fieldName.assign( currentComment.begin(), eqPos );
198 if( fieldName ==
"ARTIST" )
202 txtDesc.GetArtist().assign( eqPos+1, currentComment.end() );
204 else if ( fieldName ==
"TITLE" )
208 txtDesc.GetTitle().assign( eqPos+1, currentComment.end() );
210 else if ( fieldName ==
"ALBUM" )
214 txtDesc.GetAlbum().assign( eqPos+1, currentComment.end() );
216 else if ( fieldName ==
"TRACKNUMBER" )
218 txtDesc.AddTrackNumber();
220 txtDesc.GetTrackNumber().assign( eqPos+1, currentComment.end() );
222 else if ( fieldName ==
"PERFORMER" )
224 txtDesc.AddPerformer();
226 txtDesc.GetPerformer().assign( eqPos+1, currentComment.end() );
228 else if ( fieldName ==
"COMPOSER" )
230 txtDesc.AddComposer();
232 txtDesc.GetComposer().assign( eqPos+1, currentComment.end() );
236 std::string msg = fieldName;
237 msg+=
": Ignored comment field!";
244 ov_clear( &vorbisFile );