ogg sample program not working...

Started by
-1 comments, last by Amresh Kumar 17 years, 10 months ago
Hi, This is the simple code i tried out, which is not working. Problem comes in as soon as it goes into the LoadOGG function Please help me on this topic. Here is the code:- #include "AL/al.h" #include "AL/alut.h" #include "vorbis/vorbisfile.h" #include <cstdio> #include <iostream> #include <vector> #define BUFFER_SIZE 32768000 using namespace std; // This function loads a .ogg file into a memory buffer and returns // the format and frequency. bool LoadOGG(const char *fileName, vector<char> &buffer, ALenum &format, ALsizei &freq) { int endian = 0; int bitStream; long bytes; char array[BUFFER_SIZE]; FILE *f (NULL); f = fopen(fileName, "rb"); if (f == NULL) return false; vorbis_info *pInfo; OggVorbis_File oggFile; if (ov_open(f, &oggFile, NULL, 0) != 0) return false; pInfo = ov_info(&oggFile, -1); if (pInfo->channels == 1) format = AL_FORMAT_MONO16; else format = AL_FORMAT_STEREO16; freq = pInfo->rate; do { bytes = ov_read(&oggFile, array, BUFFER_SIZE, endian, 2, 1, &bitStream); if (bytes < 0) { ov_clear(&oggFile); return false; } buffer.insert(buffer.end(), array, array + bytes); } while (bytes > 0); ov_clear(&oggFile); return true; } int main(int argc, char *argv[]) { ALint state; // The state of the sound source ALuint bufferID; // The OpenAL sound buffer ID ALuint sourceID; // The OpenAL sound source ALenum format; // The sound data format ALsizei freq; // The frequency of the sound data vector<char> bufferData; // The sound buffer data from file if (argc < 2) { cerr << "Syntax: " << argv[0] << " OGGFile" << endl; return -1; } alutInit(&argc, argv); alGenBuffers(1, &bufferID); alGenSources(1, &sourceID); alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f); alSource3f(sourceID, AL_POSITION, 0.0f, 0.0f, 0.0f); if (!LoadOGG(argv[1], bufferData, format, freq)) { cerr << "Couldn't load file." << endl; return -1; } alBufferData(bufferID, format, &bufferData[0], static_cast<ALsizei>(bufferData.size()), freq); alSourcei(sourceID, AL_BUFFER, bufferID); alSourcePlay(sourceID); do alGetSourcei(sourceID, AL_SOURCE_STATE, &state); while (state != AL_STOPPED); alDeleteBuffers(1, &bufferID); alDeleteSources(1, &sourceID); alutExit(); return 0; } // end of main
Amar

This topic is closed to new replies.

Advertisement