Update, improve error handling, make it work in Windows.
This commit is contained in:
@@ -6,24 +6,26 @@
|
||||
#include "SDL_utils.h"
|
||||
#include "RageSoundReader_Vorbisfile.h"
|
||||
|
||||
#ifdef _XBOX
|
||||
#include "vorbis/vorbisfile.h"
|
||||
#else
|
||||
#include "tremor/ivorbisfile.h"
|
||||
#if defined(INTEGER_OGG)
|
||||
#endif
|
||||
|
||||
#if defined _XBOX
|
||||
#pragma comment(lib, "SDL_sound-1.0.0/lib/xbox_ogg_static.lib")
|
||||
#pragma comment(lib, "SDL_sound-1.0.0/lib/xbox_vorbis_static.lib")
|
||||
#pragma comment(lib, "SDL_sound-1.0.0/lib/xbox_vorbisfile_static.lib")
|
||||
#elif defined _WINDOWS
|
||||
#pragma comment(lib, "SDL_sound-1.0.0/lib/ogg_static.lib")
|
||||
#pragma comment(lib, "SDL_sound-1.0.0/lib/vorbis_static.lib")
|
||||
#pragma comment(lib, "SDL_sound-1.0.0/lib/vorbisfile_static.lib")
|
||||
#if defined(_XBOX) || defined(_WINDOWS)
|
||||
#include "vorbis/vorbisfile.h"
|
||||
#endif
|
||||
|
||||
#if defined(_XBOX)
|
||||
#pragma comment(lib, "vorbis/xbox/ogg_static.lib")
|
||||
#pragma comment(lib, "vorbis/xbox/vorbis_static.lib")
|
||||
#pragma comment(lib, "vorbis/xbox/vorbisfile_static.lib")
|
||||
#elif defined(_WINDOWS)
|
||||
#pragma comment(lib, "vorbis/win32/ogg_static.lib")
|
||||
#pragma comment(lib, "vorbis/win32/vorbis_static.lib")
|
||||
#pragma comment(lib, "vorbis/win32/vorbisfile_static.lib")
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include "RageFile.h"
|
||||
#include "RageLog.h"
|
||||
|
||||
/* What is this file, and why is it needed? Seems to compile on
|
||||
* Win32 w/o it. -Chris */
|
||||
@@ -36,12 +38,39 @@ const int channels = 2;
|
||||
/* The amount of data to read from SDL_sound at once. */
|
||||
const int read_block_size = 1024;
|
||||
|
||||
static CString ov_ssprintf( int err, const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
CString s = vssprintf( fmt, va );
|
||||
va_end(va);
|
||||
|
||||
CString errstr;
|
||||
switch( err )
|
||||
{
|
||||
case OV_EREAD: errstr = "Read error"; break;
|
||||
case OV_EFAULT: errstr = "Internal error"; break;
|
||||
case OV_EIMPL: errstr = "Feature not implemented"; break;
|
||||
case OV_EINVAL: errstr = "Invalid argument"; break;
|
||||
case OV_ENOTVORBIS: errstr = "Not Vorbis data"; break;
|
||||
case OV_EBADHEADER: errstr = "Invalid Vorbis bitstream header"; break;
|
||||
case OV_EVERSION: errstr = "Vorbis version mismatch"; break;
|
||||
case OV_ENOTAUDIO: errstr = "OV_ENOTAUDIO"; break;
|
||||
case OV_EBADPACKET: errstr = "OV_EBADPACKET"; break;
|
||||
case OV_EBADLINK: errstr = "Link corrupted"; break;
|
||||
case OV_ENOSEEK: errstr = "Stream is not seekable"; break;
|
||||
default: errstr = ssprintf( "unknown error %i", err ); break;
|
||||
}
|
||||
|
||||
return s + ssprintf( " (%s)", errstr.c_str() );
|
||||
}
|
||||
|
||||
bool RageSoundReader_Vorbisfile::Open(CString filename_)
|
||||
{
|
||||
filename=filename_;
|
||||
|
||||
vf = new OggVorbis_File;
|
||||
FILE *f = Ragefopen(filename, "r");
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if(f == NULL)
|
||||
{
|
||||
SetError(ssprintf("ogg fopen(%s) failed: %s", filename.c_str(), strerror(errno)));
|
||||
@@ -51,11 +80,11 @@ bool RageSoundReader_Vorbisfile::Open(CString filename_)
|
||||
int ret = ov_open(f, vf, NULL, 0);
|
||||
if(ret < 0)
|
||||
{
|
||||
SetError(ssprintf("ogg failed %i", ret));
|
||||
SetError( ov_ssprintf(ret, "ov_open failed") );
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
avail = 0;
|
||||
|
||||
return true;
|
||||
@@ -63,8 +92,11 @@ bool RageSoundReader_Vorbisfile::Open(CString filename_)
|
||||
|
||||
int RageSoundReader_Vorbisfile::GetLength() const
|
||||
{
|
||||
#if defined(INTEGER_OGG)
|
||||
int len = ov_time_total(vf, -1);
|
||||
|
||||
#else
|
||||
int len = int(ov_time_total(vf, -1) * 1000);
|
||||
#endif
|
||||
if(len == OV_EINVAL)
|
||||
RageException::Throw("RageSoundReader_Vorbisfile::GetLength: ov_time_total returned OV_EINVAL");
|
||||
|
||||
@@ -83,7 +115,7 @@ int RageSoundReader_Vorbisfile::SetPosition(int ms, bool accurate)
|
||||
int ret = ov_time_seek(vf, ms);
|
||||
if(ret < 0)
|
||||
{
|
||||
SetError(ssprintf("ogg: SetPosition failed: %i", ret));
|
||||
SetError( ov_ssprintf(ret, "ogg: SetPosition failed") );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -103,10 +135,10 @@ int RageSoundReader_Vorbisfile::Read(char *buf, unsigned len)
|
||||
char tmpbuf[4096];
|
||||
int bstream;
|
||||
|
||||
#ifdef _XBOX // float vorbis decoder
|
||||
int ret = ov_read(vf, tmpbuf, sizeof(tmpbuf), 0, 2, 1, &bstream);
|
||||
#else // integer vorbis decoder
|
||||
#if defined(INTEGER_OGG)
|
||||
int ret = ov_read(vf, tmpbuf, sizeof(tmpbuf), &bstream);
|
||||
#else // float vorbis decoder
|
||||
int ret = ov_read(vf, tmpbuf, sizeof(tmpbuf), 0, 2, 1, &bstream);
|
||||
#endif
|
||||
|
||||
//int ret = 4096;
|
||||
|
||||
Reference in New Issue
Block a user