Don't open the same file twice.

This commit is contained in:
Jonathan Moore Liles 2008-02-28 06:35:19 -06:00
parent f3d7abfe32
commit 9e47efc585
3 changed files with 14 additions and 7 deletions

View File

@ -20,6 +20,8 @@
#include "Audio_File.H"
#include "Audio_File_SF.H"
map <string, Audio_File*> Audio_File::_open_files;
/** attmpet to open any supported filetype */
Audio_File *
Audio_File::from_file ( const char * filename )
@ -27,6 +29,9 @@ Audio_File::from_file ( const char * filename )
Audio_File *a;
if ( ( a = _open_files[ string( filename ) ] ) )
return a;
if ( ( a = Audio_File_SF::from_file( filename ) ) )
goto done;
@ -36,6 +41,7 @@ Audio_File::from_file ( const char * filename )
done:
a->_peaks = new Peaks[ a->channels() ];
for ( int i = a->channels(); i-- ; )
@ -45,5 +51,7 @@ done:
a->_peaks[i].open();
}
_open_files[ string( filename ) ] = a;
return a;
}

View File

@ -27,8 +27,13 @@ typedef float sample_t;
#include "Peaks.H"
#include <string>
#include <map>
using namespace std;
class Audio_File
{
static map <string, Audio_File*> _open_files;
protected:

View File

@ -41,12 +41,6 @@ Audio_File_SF::from_file ( const char *filename )
return NULL;
}
/* if ( si.channels != 1 ) */
/* { */
/* printf( "error: incompatible format\n" ); */
/* goto invalid; */
/* } */
if ( si.samplerate != timeline->sample_rate )
{
printf( "error: samplerate mismatch!\n" );
@ -55,7 +49,7 @@ Audio_File_SF::from_file ( const char *filename )
c = new Audio_File_SF;
c->_filename = filename;
c->_filename = strdup( filename );
c->_length = si.frames;
c->_channels = si.channels;