[vorbis] Problem using 'ov_open()'...
Ryan Ashley
Lord_Dakron at hotmail.com
Wed Feb 11 14:19:34 PST 2004
OK, I've been developing a small class that I can use in virtually any
application to load and decode OGG files. Everything works fine until it
reaches the line with the call to ov_open, then the application freezes and
has to be killed. This is a single-threaded Win32 app. Below is both the
structure that gets passed around, and my entire OGG class. Maybe one of
you can figure this out.
#include <vorbis\codec.h>
#include <vorbis\vorbisfile.h>
#include <stdio.h>
typedef struct tagSOUNDDATA
{
char *Buffer;
int Channels, Length, Frequency;
} sSOUNDDATA, *pSOUNDDATA;
class OGGDATA
{
public:
OGGDATA();
~OGGDATA();
bool OpenOGG(char*);
pSOUNDDATA DecodeOGGLow();
void CloseOGG(pSOUNDDATA);
private:
FILE *pFile;
OggVorbis_File *pOVFile;
};
OGGDATA::OGGDATA()
{
pFile = NULL;
pOVFile = NULL;
}
OGGDATA::~OGGDATA()
{
if(pOVFile != NULL)
ov_clear(pOVFile);
if(pFile != NULL)
fclose(pFile);
}
bool OGGDATA::OpenOGG(char *Filename)
{
int Result;
if(pOVFile != NULL)
ov_clear(pOVFile);
if(pFile != NULL)
fclose(pFile);
if((pFile = fopen(Filename, "rb")) == NULL)
return false;
Result = ov_open(pFile, pOVFile, NULL, 0);
switch(Result)
{
case 0:
break;
case OV_EREAD:
fclose(pFile);
return false;
case OV_ENOTVORBIS:
fclose(pFile);
return false;
case OV_EVERSION:
fclose(pFile);
return false;
case OV_EBADHEADER:
fclose(pFile);
return false;
case OV_EFAULT:
fclose(pFile);
return false;
}
return true;
}
pSOUNDDATA OGGDATA::DecodeOGGLow()
{
int StreamID;
unsigned int Size, Read, Location;
pSOUNDDATA pData;
if((pFile == NULL) || (pOVFile == NULL))
return NULL;
if((pData = (pSOUNDDATA)malloc(sizeof(sSOUNDDATA))) == NULL)
return NULL;
Size = ov_raw_total(pOVFile, -1);
if((pData->Buffer = (char*)malloc(Size)) == NULL)
{
free(pData);
return NULL;
}
StreamID = 0;
Read = 0;
Location = 0;
while(Size > 0)
{
Read = ov_read(pOVFile, pData->Buffer + Location, Size, 0, 2, 1,
&StreamID);
Location += Read;
Size -= Read;
}
ov_clear(pOVFile);
StreamID = 0;
Size = 0;
Read = 0;
Location = 0;
return pData;
}
void OGGDATA::CloseOGG(pSOUNDDATA pData)
{
if(pData == NULL)
return;
free(pData->Buffer);
free(pData);
}
That's the entire source. Is there a reason it's failing? I've also tried
making 'pOVFile' a static var (not a pointer) and using references to it,
but it still locks on the read line. Thanks for any help you can offer.
Oh, and I named the decoding function 'DecodeOGGLow()' because I plan on
implementing a 'DecodeOGGHigh()' function later that decodes to floats. I
assume that the floats give better sound quality since you can go between
single-digits and carry decimal places.
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the Vorbis
mailing list