27 #include <vorbis/codec.h>
31 #if defined ( __powerpc__ ) || defined ( __POWERPC__ )
32 #define HOST_ENDIANESS 1
34 #define HOST_ENDIANESS 0
66 std::string msgString =
"Could not open ";
68 msgString +=
" for reading!";
76 std::string msgString =
mName;
77 msgString +=
" is not a valid Ogg/Vorbis file!";
83 "OggVorbisAudioStream: channels info changed before opening");
101 std::string msgString =
"Could not open ";
103 msgString +=
" for writing!";
106 VorbisI_EncoderSetup();
110 void OggVorbisAudioStream::VorbisI_EncoderSetup()
115 int retValue = vorbis_encode_init_vbr(
118 CLAM_ASSERT( retValue == 0,
"Error trying to initialize Vorbis encoder!" );
133 WriteBitstreamHeader();
136 void OggVorbisAudioStream::WriteBitstreamHeader()
143 ogg_packet header_codec_setup;
144 ogg_packet header_comments;
145 ogg_packet header_codebooks;
189 PushAnalysisBlocksOntoOggStream();
203 void OggVorbisAudioStream::ConsumeDecodedSamples()
209 "This method cannot be called if the decode buffer"
210 " has less samples than requested by the upper level");
212 static const TData norm = 1.0 / 32768.0;
214 const TData* pSamplesEnd = pSamples + nItems;
215 typedef std::deque<TInt16> sampleDeque;
216 for( sampleDeque::iterator i =
mDecodeBuffer.begin(); pSamples < pSamplesEnd; i++)
217 *pSamples++ =
TData(*i)*norm;
230 unsigned samplesRead = 0;
266 ConsumeDecodedSamples();
276 unsigned currentOffset = 0;
297 void OggVorbisAudioStream::PushAnalysisBlocksOntoOggStream()
317 eos = ( ogg_page_eos( &
mOggPage ) )? 1 : 0;
323 void OggVorbisAudioStream::DoVorbisAnalysis()
325 float** encBuffer = vorbis_analysis_buffer(
328 for (
unsigned j = 0; j <
mChannels; j++ )
341 encBuffer[j][i] = 0.0;
346 PushAnalysisBlocksOntoOggStream();