Don't open the same file twice.
This commit is contained in:
parent
f3d7abfe32
commit
9e47efc585
|
@ -20,6 +20,8 @@
|
||||||
#include "Audio_File.H"
|
#include "Audio_File.H"
|
||||||
#include "Audio_File_SF.H"
|
#include "Audio_File_SF.H"
|
||||||
|
|
||||||
|
map <string, Audio_File*> Audio_File::_open_files;
|
||||||
|
|
||||||
/** attmpet to open any supported filetype */
|
/** attmpet to open any supported filetype */
|
||||||
Audio_File *
|
Audio_File *
|
||||||
Audio_File::from_file ( const char * filename )
|
Audio_File::from_file ( const char * filename )
|
||||||
|
@ -27,6 +29,9 @@ Audio_File::from_file ( const char * filename )
|
||||||
|
|
||||||
Audio_File *a;
|
Audio_File *a;
|
||||||
|
|
||||||
|
if ( ( a = _open_files[ string( filename ) ] ) )
|
||||||
|
return a;
|
||||||
|
|
||||||
if ( ( a = Audio_File_SF::from_file( filename ) ) )
|
if ( ( a = Audio_File_SF::from_file( filename ) ) )
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
@ -36,6 +41,7 @@ Audio_File::from_file ( const char * filename )
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|
||||||
|
|
||||||
a->_peaks = new Peaks[ a->channels() ];
|
a->_peaks = new Peaks[ a->channels() ];
|
||||||
|
|
||||||
for ( int i = a->channels(); i-- ; )
|
for ( int i = a->channels(); i-- ; )
|
||||||
|
@ -45,5 +51,7 @@ done:
|
||||||
a->_peaks[i].open();
|
a->_peaks[i].open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_open_files[ string( filename ) ] = a;
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,13 @@ typedef float sample_t;
|
||||||
|
|
||||||
#include "Peaks.H"
|
#include "Peaks.H"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
class Audio_File
|
class Audio_File
|
||||||
{
|
{
|
||||||
|
static map <string, Audio_File*> _open_files;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,6 @@ Audio_File_SF::from_file ( const char *filename )
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if ( si.channels != 1 ) */
|
|
||||||
/* { */
|
|
||||||
/* printf( "error: incompatible format\n" ); */
|
|
||||||
/* goto invalid; */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
if ( si.samplerate != timeline->sample_rate )
|
if ( si.samplerate != timeline->sample_rate )
|
||||||
{
|
{
|
||||||
printf( "error: samplerate mismatch!\n" );
|
printf( "error: samplerate mismatch!\n" );
|
||||||
|
@ -55,7 +49,7 @@ Audio_File_SF::from_file ( const char *filename )
|
||||||
|
|
||||||
c = new Audio_File_SF;
|
c = new Audio_File_SF;
|
||||||
|
|
||||||
c->_filename = filename;
|
c->_filename = strdup( filename );
|
||||||
c->_length = si.frames;
|
c->_length = si.frames;
|
||||||
c->_channels = si.channels;
|
c->_channels = si.channels;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue