Browse Source

Add mutex to Audio_File objects to prevent read_source_peaks() and IO thread from conflicting.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
d7f020ee2e
3 changed files with 19 additions and 4 deletions
  1. +3
    -1
      Timeline/Audio_File.H
  2. +15
    -2
      Timeline/Audio_File_SF.C
  3. +1
    -1
      Timeline/Audio_File_SF.H

+ 3
- 1
Timeline/Audio_File.H View File

@@ -29,9 +29,11 @@
#include <map> #include <map>
#include <list> #include <list>


#include "Mutex.H"

class Peak_Writer; class Peak_Writer;


class Audio_File
class Audio_File : protected Mutex
{ {
static std::map <std::string, Audio_File*> _open_files; static std::map <std::string, Audio_File*> _open_files;




+ 15
- 2
Timeline/Audio_File_SF.C View File

@@ -163,10 +163,12 @@ Audio_File_SF::close ( void )
void void
Audio_File_SF::seek ( nframes_t offset ) Audio_File_SF::seek ( nframes_t offset )
{ {
lock();

if ( offset != _current_read ) if ( offset != _current_read )
{
sf_seek( _in, _current_read = offset, SEEK_SET | SFM_READ ); sf_seek( _in, _current_read = offset, SEEK_SET | SFM_READ );
}

unlock();
} }


/* if channels is -1, then all channels are read into buffer /* if channels is -1, then all channels are read into buffer
@@ -179,6 +181,8 @@ Audio_File_SF::read ( sample_t *buf, int channel, nframes_t len )


// printf( "len = %lu, channels = %d\n", len, _channels ); // printf( "len = %lu, channels = %d\n", len, _channels );


lock();

nframes_t rlen; nframes_t rlen;


if ( _channels == 1 || channel == -1 ) if ( _channels == 1 || channel == -1 )
@@ -198,6 +202,8 @@ Audio_File_SF::read ( sample_t *buf, int channel, nframes_t len )


_current_read += rlen; _current_read += rlen;


unlock();

return rlen; return rlen;
} }


@@ -207,12 +213,15 @@ Audio_File_SF::read ( sample_t *buf, int channel, nframes_t start, nframes_t end
{ {
assert( end > start ); assert( end > start );


lock();
// open(); // open();


seek( start ); seek( start );


nframes_t len = read( buf, channel, end - start ); nframes_t len = read( buf, channel, end - start );


unlock();

// close(); // close();


return len; return len;
@@ -225,9 +234,13 @@ Audio_File_SF::write ( sample_t *buf, nframes_t nframes )
{ {
_peaks.write( buf, nframes ); _peaks.write( buf, nframes );


// lock();

nframes_t l = sf_writef_float( _in, buf, nframes ); nframes_t l = sf_writef_float( _in, buf, nframes );


_length += l; _length += l;


// unlock();

return l; return l;
} }

+ 1
- 1
Timeline/Audio_File_SF.H View File

@@ -29,7 +29,7 @@ class Audio_File_SF : public Audio_File


/* used to avoid unnecessary seeking--libsndfile isn't smart /* used to avoid unnecessary seeking--libsndfile isn't smart
* enough to do this for us */ * enough to do this for us */
nframes_t _current_read;
volatile nframes_t _current_read;


Audio_File_SF ( ) Audio_File_SF ( )
{ {


Loading…
Cancel
Save