| @@ -30,8 +30,6 @@ Audio_File::from_file ( const char * filename ) | |||||
| if ( ( a = Audio_File_SF::from_file( filename ) ) ) | if ( ( a = Audio_File_SF::from_file( filename ) ) ) | ||||
| goto done; | goto done; | ||||
| a->_peaks.open(); | |||||
| // TODO: other formats | // TODO: other formats | ||||
| return NULL; | return NULL; | ||||
| @@ -35,6 +35,7 @@ protected: | |||||
| Peaks _peaks; | Peaks _peaks; | ||||
| const char *_filename; | const char *_filename; | ||||
| nframes_t _length; /* length of file in samples */ | nframes_t _length; /* length of file in samples */ | ||||
| int _channels; | |||||
| public: | public: | ||||
| @@ -47,15 +48,16 @@ public: | |||||
| static Audio_File *from_file ( const char *filename ); | static Audio_File *from_file ( const char *filename ); | ||||
| Peaks const * peaks ( void ) { return &_peaks; } | Peaks const * peaks ( void ) { return &_peaks; } | ||||
| const char *name ( void ) { return _filename; } | |||||
| nframes_t length ( void ) { return _length; } | |||||
| const char *name ( void ) const { return _filename; } | |||||
| nframes_t length ( void ) const { return _length; } | |||||
| int channels ( void ) const { return _channels; } | |||||
| // Peaks const * peaks ( void ) { return &_peaks; } | // Peaks const * peaks ( void ) { return &_peaks; } | ||||
| virtual bool open ( void ) = 0; | virtual bool open ( void ) = 0; | ||||
| virtual void close ( void ) = 0; | virtual void close ( void ) = 0; | ||||
| virtual void seek ( nframes_t offset ) = 0; | virtual void seek ( nframes_t offset ) = 0; | ||||
| virtual nframes_t read ( sample_t *buf, nframes_t len ) = 0; | |||||
| virtual nframes_t read ( sample_t *buf, nframes_t start, nframes_t end ) = 0; | |||||
| virtual nframes_t read ( sample_t *buf, int channel, nframes_t len ) = 0; | |||||
| virtual nframes_t read ( sample_t *buf, int channel, nframes_t start, nframes_t end ) = 0; | |||||
| }; | }; | ||||
| @@ -41,11 +41,11 @@ 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.channels != 1 ) */ | |||||
| /* { */ | |||||
| /* printf( "error: incompatible format\n" ); */ | |||||
| /* goto invalid; */ | |||||
| /* } */ | |||||
| if ( si.samplerate != timeline->sample_rate ) | if ( si.samplerate != timeline->sample_rate ) | ||||
| { | { | ||||
| @@ -57,6 +57,7 @@ Audio_File_SF::from_file ( const char *filename ) | |||||
| c->_filename = filename; | c->_filename = filename; | ||||
| c->_length = si.frames; | c->_length = si.frames; | ||||
| c->_channels = si.channels; | |||||
| sf_close( in ); | sf_close( in ); | ||||
| @@ -94,20 +95,32 @@ Audio_File_SF::seek ( nframes_t offset ) | |||||
| } | } | ||||
| nframes_t | nframes_t | ||||
| Audio_File_SF::read ( sample_t *buf, nframes_t len ) | |||||
| Audio_File_SF::read ( sample_t *buf, int channel, nframes_t len ) | |||||
| { | { | ||||
| return sf_read_float ( _in, buf, len ); | |||||
| if ( _channels == 1 ) | |||||
| return sf_read_float ( _in, buf, len ); | |||||
| sample_t *tmp = new sample_t[ len * _channels ]; | |||||
| nframes_t rlen = sf_readf_float( _in, tmp, len ); | |||||
| for ( int i = channel; i < rlen; i += _channels ) | |||||
| *(buf++) = tmp[ i ]; | |||||
| delete tmp; | |||||
| return rlen; | |||||
| } | } | ||||
| /** read samples from /start/ to /end/ into /buf/ */ | /** read samples from /start/ to /end/ into /buf/ */ | ||||
| nframes_t | nframes_t | ||||
| Audio_File_SF::read ( sample_t *buf, nframes_t start, nframes_t end ) | |||||
| Audio_File_SF::read ( sample_t *buf, int channel, nframes_t start, nframes_t end ) | |||||
| { | { | ||||
| open(); | open(); | ||||
| seek( start ); | seek( start ); | ||||
| nframes_t len = read( buf, end - start ); | |||||
| nframes_t len = read( buf, channel, end - start ); | |||||
| close(); | close(); | ||||
| @@ -34,7 +34,7 @@ public: | |||||
| bool open ( void ); | bool open ( void ); | ||||
| void close ( void ); | void close ( void ); | ||||
| void seek ( nframes_t offset ); | void seek ( nframes_t offset ); | ||||
| nframes_t read ( sample_t *buf, nframes_t len ); | |||||
| nframes_t read ( sample_t *buf, nframes_t start, nframes_t end ); | |||||
| nframes_t read ( sample_t *buf, int channel, nframes_t len ); | |||||
| nframes_t read ( sample_t *buf, int channel, nframes_t start, nframes_t end ); | |||||
| }; | }; | ||||
| @@ -92,7 +92,7 @@ Peaks::clip_read_peaks ( Peak *peaks, int npeaks, int chunksize ) const | |||||
| for ( i = 0; i < npeaks; ++i ) | for ( i = 0; i < npeaks; ++i ) | ||||
| { | { | ||||
| /* read in a buffer */ | /* read in a buffer */ | ||||
| len = _clip->read( fbuf, chunksize ); | |||||
| len = _clip->read( fbuf, 0, chunksize ); | |||||
| Peak &p = peaks[ i ]; | Peak &p = peaks[ i ]; | ||||
| p.min = 0; | p.min = 0; | ||||