Re: [ANN] StretchPlayer 0.501 - Time Stretching Audio Player

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Dragan and Ivan,

On Sat, 12 Jun 2010, Ivan Tarozzi wrote:

but when i click on 'open file' button, stretchplayer immediately disconnects
from jack:

I can't reproduce the issue, but...

Would you two be willing to try the attached patch? From the source directory, apply like this:

   $ patch -p1 < stretch_zombie_0.501.patch

Dragan: Are you also on squeeze 32-bit, with an AMD64 processor?

Thanks,
Gabriel
diff --git a/src/Engine.cpp b/src/Engine.cpp
index 92697df..b364f0a 100644
--- a/src/Engine.cpp
+++ b/src/Engine.cpp
@@ -38,8 +38,8 @@ using namespace std;
 namespace StretchPlayer
 {
     Engine::Engine()
-	: _playing(false),
-	  _state_changed(false),
+	: _playing(0),
+	  _state_changed(0),
 	  _position(0),
 	  _loop_a(0),
 	  _loop_b(0),
@@ -70,6 +70,7 @@ namespace StretchPlayer
 		)
 	    );
 	_stretcher->setMaxProcessSize(16384);
+	_stretcher->reset();
 
 	if( _audio_system->activate(&err) )
 	    throw std::runtime_error(err.toLocal8Bit().data());
@@ -112,19 +113,27 @@ namespace StretchPlayer
     int Engine::process_callback(uint32_t nframes)
     {
 	bool locked = false;
+	int playing;
+	int state_changed;
+	bool stop_end = false;
+
+	playing = _playing;
+	state_changed = _state_changed;
 
 	try {
 	    locked = _audio_lock.tryLock();
-	    if(_state_changed) {
-		_state_changed = false;
+	    if(state_changed) {
 		_stretcher->reset();
 	    }
+	    while( ! _state_changed.testAndSetOrdered(state_changed, 0) ) {
+		state_changed = _state_changed;
+	    }
 	    if(locked) {
-		if(_playing) {
+		if(playing) {
 		    if(_left.size()) {
 			_process_playing(nframes);
 		    } else {
-			_playing = false;
+			stop_end = true;
 		    }
 		} else {
 		    _zero_buffers(nframes);
@@ -135,6 +144,14 @@ namespace StretchPlayer
 	} catch (...) {
 	}
 
+	if( stop_end ) {
+	    // Unconditionally stop playing.
+	    int p = _playing;
+	    while( ! _playing.testAndSetOrdered(p, playing) ) {
+		p = _playing;
+	    }
+	}
+
 	if(locked) _audio_lock.unlock();
 
 	return 0;
@@ -156,7 +173,7 @@ namespace StretchPlayer
 	_stretcher->setPitchScale( ::pow(2.0, double(_pitch)/12.0) * _sample_rate / srate );
 
 	uint32_t frame;
-	size_t reqd, gend, zeros, feed;
+	uint32_t reqd, gend, zeros, feed;
 
 	frame = 0;
 	while( frame < nframes ) {
@@ -212,7 +229,7 @@ namespace StretchPlayer
 	}
 
 	if(_position >= _left.size()) {
-	    _playing = false;
+	    stop();
 	    _position = 0;
 	}
     }
@@ -284,24 +301,36 @@ namespace StretchPlayer
 
     void Engine::play()
     {
-	if( ! _playing ) {
-	    _state_changed = true;
-	    _playing = true;
+	int playing = _playing.fetchAndAddOrdered(1);
+	if( playing == 0 ) {
+	    _state_changed.fetchAndAddOrdered(1);
 	}
     }
 
     void Engine::play_pause()
     {
-	_playing = (_playing) ? false : true;
-	_state_changed = true;
+	int before = _playing;
+	int after = (before) ? 0 : 1;
+	if( after ) {
+	    _playing.fetchAndAddOrdered(1);
+	} else {
+	    while(_playing != after) {
+		_playing.testAndSetOrdered(_playing, after);
+	    }
+	}
+	_state_changed.fetchAndAddOrdered(1);
     }
 
     void Engine::stop()
     {
-	if( _playing ) {
-	    _playing = false;
-	    _state_changed = true;
+	int playing = _playing;
+	bool change = false;
+	while(playing > 0) {
+	    _playing.testAndSetOrdered(playing, 0);
+	    playing = _playing;
+	    change = true;
 	}
+	if( change ) _state_changed.fetchAndAddOrdered(1);
     }
 
     float Engine::get_position()
@@ -346,7 +375,7 @@ namespace StretchPlayer
 	unsigned long pos = secs * _sample_rate;
 	QMutexLocker lk(&_audio_lock);
 	_position = pos;
-	_state_changed = true;
+	_state_changed.fetchAndAddOrdered(1);
     }
 
     void Engine::_dispatch_message(const Engine::callback_seq_t& seq, const QString& msg) const
diff --git a/src/Engine.hpp b/src/Engine.hpp
index d915651..01a9887 100644
--- a/src/Engine.hpp
+++ b/src/Engine.hpp
@@ -135,8 +135,8 @@ private:
     void _subscribe_list(callback_seq_t& seq, EngineMessageCallback* obj);
     void _unsubscribe_list(callback_seq_t& seq, EngineMessageCallback* obj);
 
-    bool _playing;
-    bool _state_changed;
+    QAtomicInt _playing; // >0 if playing, 0 if not.
+    QAtomicInt _state_changed; // >0 if state changed, 0 if not
     mutable QMutex _audio_lock;
     std::vector<float> _left;
     std::vector<float> _right;
diff --git a/src/JackAudioSystem.cpp b/src/JackAudioSystem.cpp
index 0b795e0..f981bcc 100644
--- a/src/JackAudioSystem.cpp
+++ b/src/JackAudioSystem.cpp
@@ -127,7 +127,7 @@ namespace StretchPlayer
 					     JACK_DEFAULT_AUDIO_TYPE,
 					     JackPortIsInput
 	    );
-	int k, rv;
+	int k, rv = 0;
 	for( k=0 ; ports && ports[k] != 0 ; ++k ) {
 	    if(k==0) {
 		rv = jack_connect( _client,
@@ -156,9 +156,11 @@ namespace StretchPlayer
 
     int JackAudioSystem::deactivate(QString *err_msg)
     {
+	int rv = 0;
 	if(_client) {
-	    jack_deactivate(_client);
+	    rv = jack_deactivate(_client);
 	}
+	return rv;
     }
 
     AudioSystem::sample_t* JackAudioSystem::output_buffer(int index)
@@ -175,13 +177,13 @@ namespace StretchPlayer
 	return 0;
     }
 
-    size_t JackAudioSystem::output_buffer_size(int /*index*/)
+    uint32_t JackAudioSystem::output_buffer_size(int /*index*/)
     {
 	if( !_client ) return 0;
 	return jack_get_buffer_size(_client);
     }
 
-    size_t JackAudioSystem::sample_rate()
+    uint32_t JackAudioSystem::sample_rate()
     {
 	if( !_client ) return 0;
 	return jack_get_sample_rate(_client);
diff --git a/src/JackAudioSystem.hpp b/src/JackAudioSystem.hpp
index a9406de..7fa4f30 100644
--- a/src/JackAudioSystem.hpp
+++ b/src/JackAudioSystem.hpp
@@ -45,8 +45,8 @@ namespace StretchPlayer
 	virtual int activate(QString *err_msg = 0);
 	virtual int deactivate(QString *err_msg = 0);
 	virtual sample_t* output_buffer(int index);
-	virtual size_t output_buffer_size(int index);
-	virtual size_t sample_rate();
+	virtual uint32_t output_buffer_size(int index);
+	virtual uint32_t sample_rate();
 	virtual float dsp_load();
 
     private:
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@xxxxxxxxxxxxxxxxxxxx
http://lists.linuxaudio.org/listinfo/linux-audio-user

[Index of Archives]     [Linux Sound]     [ALSA Users]     [Pulse Audio]     [ALSA Devel]     [Sox Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux