Browse Source

Support multichannel sound files.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
6cfe9e8b6c
5 changed files with 31 additions and 18 deletions
  1. +0
    -2
      Audio_File.C
  2. +6
    -4
      Audio_File.H
  3. +22
    -9
      Audio_File_SF.C
  4. +2
    -2
      Audio_File_SF.H
  5. +1
    -1
      Peaks.C

+ 0
- 2
Audio_File.C View File

@@ -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;


+ 6
- 4
Audio_File.H View File

@@ -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;


}; };

+ 22
- 9
Audio_File_SF.C View File

@@ -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();




+ 2
- 2
Audio_File_SF.H View File

@@ -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 );


}; };

+ 1
- 1
Peaks.C View File

@@ -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;


Loading…
Cancel
Save