use RageFile
This commit is contained in:
@@ -318,7 +318,7 @@ int RageSoundReader_MP3::fill_buffer()
|
|||||||
mad->inbytes = 0;
|
mad->inbytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rc = fread( mad->inbuf + mad->inbytes, 1, sizeof (mad->inbuf)-mad->inbytes, this->rw );
|
int rc = file.Read( mad->inbuf + mad->inbytes, sizeof (mad->inbuf)-mad->inbytes );
|
||||||
if ( rc <= 0 )
|
if ( rc <= 0 )
|
||||||
return rc;
|
return rc;
|
||||||
if ( rc == 0 )
|
if ( rc == 0 )
|
||||||
@@ -450,11 +450,7 @@ int RageSoundReader_MP3::do_mad_frame_decode( bool headers_only )
|
|||||||
int RageSoundReader_MP3::FindOffsetFix()
|
int RageSoundReader_MP3::FindOffsetFix()
|
||||||
{
|
{
|
||||||
/* Do a fake rewind. */
|
/* Do a fake rewind. */
|
||||||
if( fseek(this->rw, 0, SEEK_SET) == -1 )
|
file.Rewind();
|
||||||
{
|
|
||||||
SetError( strerror(errno) );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
mad_frame_mute(&mad->Frame);
|
mad_frame_mute(&mad->Frame);
|
||||||
mad_synth_mute(&mad->Synth);
|
mad_synth_mute(&mad->Synth);
|
||||||
@@ -584,7 +580,7 @@ void RageSoundReader_MP3::synth_output()
|
|||||||
* to use this. */
|
* to use this. */
|
||||||
int RageSoundReader_MP3::seek_stream_to_byte( int byte )
|
int RageSoundReader_MP3::seek_stream_to_byte( int byte )
|
||||||
{
|
{
|
||||||
if( fseek(this->rw, byte, SEEK_SET) == -1 )
|
if( file.Seek(byte) == -1 )
|
||||||
{
|
{
|
||||||
SetError( strerror(errno) );
|
SetError( strerror(errno) );
|
||||||
return 0;
|
return 0;
|
||||||
@@ -682,8 +678,6 @@ RageSoundReader_MP3::~RageSoundReader_MP3()
|
|||||||
mad_synth_finish( &mad->Synth );
|
mad_synth_finish( &mad->Synth );
|
||||||
mad_frame_finish( &mad->Frame );
|
mad_frame_finish( &mad->Frame );
|
||||||
mad_stream_finish( &mad->Stream );
|
mad_stream_finish( &mad->Stream );
|
||||||
if( rw )
|
|
||||||
fclose( rw );
|
|
||||||
|
|
||||||
delete mad;
|
delete mad;
|
||||||
}
|
}
|
||||||
@@ -691,23 +685,19 @@ RageSoundReader_MP3::~RageSoundReader_MP3()
|
|||||||
SoundReader_FileReader::OpenResult RageSoundReader_MP3::Open( CString filename_ )
|
SoundReader_FileReader::OpenResult RageSoundReader_MP3::Open( CString filename_ )
|
||||||
{
|
{
|
||||||
filename = filename_;
|
filename = filename_;
|
||||||
rw = fopen(filename, "rb");
|
if( !file.Open( filename ) )
|
||||||
if( !rw )
|
|
||||||
{
|
{
|
||||||
SetError( ssprintf("Couldn't open file: %s", strerror(errno)) );
|
SetError( ssprintf("Couldn't open file: %s", file.GetError().c_str()) );
|
||||||
return OPEN_NO_MATCH;
|
return OPEN_NO_MATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = fseek( this->rw, 0, SEEK_END );
|
mad->filesize = file.GetFileSize();
|
||||||
ASSERT( ret != -1 );
|
|
||||||
mad->filesize = ftell( this->rw );
|
|
||||||
ASSERT( mad->filesize != -1 );
|
ASSERT( mad->filesize != -1 );
|
||||||
fseek( this->rw, 0, SEEK_SET );
|
|
||||||
|
|
||||||
/* Make sure we can decode at least one frame. This will also fill in header info. */
|
/* Make sure we can decode at least one frame. This will also fill in header info. */
|
||||||
mad->outpos = 0;
|
mad->outpos = 0;
|
||||||
|
|
||||||
ret = do_mad_frame_decode();
|
int ret = do_mad_frame_decode();
|
||||||
switch(ret)
|
switch(ret)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@@ -750,8 +740,8 @@ SoundReader *RageSoundReader_MP3::Copy() const
|
|||||||
RageSoundReader_MP3 *ret = new RageSoundReader_MP3;
|
RageSoundReader_MP3 *ret = new RageSoundReader_MP3;
|
||||||
|
|
||||||
ret->filename = filename;
|
ret->filename = filename;
|
||||||
ret->rw = fopen(filename, "rb");
|
bool b = ret->file.Open( filename );
|
||||||
ASSERT( rw );
|
ASSERT( b );
|
||||||
|
|
||||||
ret->mad->filesize = mad->filesize;
|
ret->mad->filesize = mad->filesize;
|
||||||
ret->mad->bitrate = mad->bitrate;
|
ret->mad->bitrate = mad->bitrate;
|
||||||
@@ -828,8 +818,7 @@ int RageSoundReader_MP3::Read( char *buf, unsigned len )
|
|||||||
|
|
||||||
bool RageSoundReader_MP3::MADLIB_rewind()
|
bool RageSoundReader_MP3::MADLIB_rewind()
|
||||||
{
|
{
|
||||||
int ret = fseek(this->rw, 0, SEEK_SET);
|
this->file.Rewind();
|
||||||
ASSERT( ret == 0 );
|
|
||||||
|
|
||||||
mad_frame_mute(&mad->Frame);
|
mad_frame_mute(&mad->Frame);
|
||||||
mad_synth_mute(&mad->Synth);
|
mad_synth_mute(&mad->Synth);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "SDL_utils.h"
|
#include "SDL_utils.h"
|
||||||
#include "RageSoundReader_FileReader.h"
|
#include "RageSoundReader_FileReader.h"
|
||||||
|
#include "RageFile.h"
|
||||||
|
|
||||||
struct madlib_t;
|
struct madlib_t;
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ public:
|
|||||||
float OffsetFix;
|
float OffsetFix;
|
||||||
|
|
||||||
CString filename;
|
CString filename;
|
||||||
FILE *rw;
|
RageFile file;
|
||||||
madlib_t *mad;
|
madlib_t *mad;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user