Add mutex to Audio_File objects to prevent read_source_peaks() and IO thread from conflicting.
This commit is contained in:
parent
9b8e7569e7
commit
d7f020ee2e
|
@ -29,9 +29,11 @@
|
|||
#include <map>
|
||||
#include <list>
|
||||
|
||||
#include "Mutex.H"
|
||||
|
||||
class Peak_Writer;
|
||||
|
||||
class Audio_File
|
||||
class Audio_File : protected Mutex
|
||||
{
|
||||
static std::map <std::string, Audio_File*> _open_files;
|
||||
|
||||
|
|
|
@ -163,10 +163,12 @@ Audio_File_SF::close ( void )
|
|||
void
|
||||
Audio_File_SF::seek ( nframes_t offset )
|
||||
{
|
||||
lock();
|
||||
|
||||
if ( offset != _current_read )
|
||||
{
|
||||
sf_seek( _in, _current_read = offset, SEEK_SET | SFM_READ );
|
||||
}
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
||||
/* 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 );
|
||||
|
||||
lock();
|
||||
|
||||
nframes_t rlen;
|
||||
|
||||
if ( _channels == 1 || channel == -1 )
|
||||
|
@ -198,6 +202,8 @@ Audio_File_SF::read ( sample_t *buf, int channel, nframes_t len )
|
|||
|
||||
_current_read += rlen;
|
||||
|
||||
unlock();
|
||||
|
||||
return rlen;
|
||||
}
|
||||
|
||||
|
@ -207,12 +213,15 @@ Audio_File_SF::read ( sample_t *buf, int channel, nframes_t start, nframes_t end
|
|||
{
|
||||
assert( end > start );
|
||||
|
||||
lock();
|
||||
// open();
|
||||
|
||||
seek( start );
|
||||
|
||||
nframes_t len = read( buf, channel, end - start );
|
||||
|
||||
unlock();
|
||||
|
||||
// close();
|
||||
|
||||
return len;
|
||||
|
@ -225,9 +234,13 @@ Audio_File_SF::write ( sample_t *buf, nframes_t nframes )
|
|||
{
|
||||
_peaks.write( buf, nframes );
|
||||
|
||||
// lock();
|
||||
|
||||
nframes_t l = sf_writef_float( _in, buf, nframes );
|
||||
|
||||
_length += l;
|
||||
|
||||
// unlock();
|
||||
|
||||
return l;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class Audio_File_SF : public Audio_File
|
|||
|
||||
/* used to avoid unnecessary seeking--libsndfile isn't smart
|
||||
* enough to do this for us */
|
||||
nframes_t _current_read;
|
||||
volatile nframes_t _current_read;
|
||||
|
||||
Audio_File_SF ( )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue