Jump to content

  • Log In with Google      Sign In   
  • Create Account


Ogg Vorbis decoder


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 liamf1986   Members   -  Reputation: 115

Like
0Likes
Like

Posted 19 March 2013 - 11:30 AM

Hello,

 

I'm trying to implement a decoder for ogg vorbis audio files (.ogg). It all compiles and runs fine but the audio is mostly static.

It plays a second or two of the correct audio occasionally but is mostly just static noise.

 

I was wondering if anyone could see any problems in the code, see below.

 

// Defined in .h file
XAUDIO2_BUFFER m_xa;
WAVEFORMATEX m_wf;
 
 

bool COgg::load(const char* szFile, bool loop) { if (szFile == NULL) return false; FILE* file = NULL; OggVorbis_File m_oggFile; errno_t error; error = fopen_s(&file, szFile, "rb"); if (error != 0) return false; // Get info from .ogg file. if (ov_open_callbacks(file, &m_oggFile, NULL, 0, OV_CALLBACKS_DEFAULT) != 0) { fclose(file); return false; } vorbis_info* vInfo = ov_info(&m_oggFile, -1); memset(&m_wf, 0, sizeof(m_wf)); m_wf.cbSize = sizeof(m_wf); m_wf.nChannels = vInfo->channels; m_wf.wBitsPerSample = 16; // Ogg vorbis is always 16 m_wf.nSamplesPerSec = vInfo->rate; m_wf.nAvgBytesPerSec = m_wf.nChannels * 2 * m_wf.nSamplesPerSec; m_wf.nBlockAlign = m_wf.nChannels * 2; m_wf.wFormatTag = WAVE_FORMAT_PCM; // Get size of file. fseek(file, 0, SEEK_END); // Jump to end of file. long fileSize = ftell(file); // Store current position in file (the end). fseek(file, 0, SEEK_SET); // Jump back to the begining. int bitstream = 0; DWORD pos = 0; int ret = 1;
// Read the audio data from the opened .ogg file. char* m_data = new char[fileSize]; while (ret && pos<fileSize) { ret = ov_read(&m_oggFile, m_data+pos, fileSize-pos, 0, 2, 1, &bitstream); pos += ret; } m_xa.AudioBytes = fileSize; m_xa.pAudioData = reinterpret_cast<BYTE*>(m_data); m_xa.PlayBegin = 0; m_xa.PlayLength = 0; // Ignore the zero for now, it should be the length of the track. if (loop == true) { m_xa.LoopBegin = m_xa.PlayBegin; m_xa.LoopLength = m_xa.PlayLength; m_xa.LoopCount = -1; // -1 is an infinate loop. } // Kill the vorbis file. ov_clear(&m_oggFile); // close the file. fclose(file); return true; }

 

 



Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS