Gabriel M. Beddingfield wrote:
[*] All singleton classes need to be instanced by
    Hydrogen rather than created on the first call
    to get_instance().

[*] Redo the Logger so that it doesn't lock for
    a long time.  Bonus points if we can have
    low-overhead debug/warning/error message
    filtering.

These are both complete on the jack_zombies branch... but the work is not yet done. This branch touches nearly every file and _will_ trigger an entire rebuild. The attached patch is my work-in-progress. With the attached patch, zombies happen a lot less (and usually only at startup).

I'm attaching the patch because this stuff is ready for some more eyes, but I won't be able to touch it for a couple days.

More details....

LOGGING___________________________________________

It is now possible to configure the logging verbosity at run-time. By default, only error messages will be outputted. However, you can enable "Warning" and "Info" messages like this:

   $ ./hydrogen -V Warning
   $ ./hydrogen --verbose Info
   $ ./hydrogne --verbose
   (see ./hydrogen --help)

The logging verbosity is controlled by an integer that is OR-ed before calling the Logger::log() function:

   if( logLevel & Logger::Debug ) {
       Logger::log(...);
   }

This makes logging messages _very_ low overhead if you don't want them.

THE PATCH______________________________________________

I'm currently working on the Hydrogen state variables, and short-circuiting the process() function. The attached patch is my work-in-progress (applied on top of the jack_zombies branch). It's not right... but I wanted to make it available.

There is a bug that allows random noise to be played whenever the process() function is short-circuited. This usually happens when opening and closing Hydrogen... and I think when opening and closing a song file.

Apply the patch like this:

  $ patch -p1 < jack_zombies_wip_1188.diff

KNOWN ISSUES____________________________________________

`./hydrogen --help' will instance everything and start all the audio drivers... but it should not.

Thanks,
Gabriel

diff --git a/libs/hydrogen/include/hydrogen/hydrogen.h b/libs/hydrogen/include/hydrogen/hydrogen.h
index 9a2206d..7cc926e 100644
--- a/libs/hydrogen/include/hydrogen/hydrogen.h
+++ b/libs/hydrogen/include/hydrogen/hydrogen.h
@@ -31,12 +31,12 @@
 #include <hydrogen/SoundLibrary.h>
 #include <cassert>
 
-// Engine state
-#define STATE_UNINITIALIZED	1
-#define STATE_INITIALIZED	2
-#define STATE_PREPARED		3
-#define STATE_READY		4
-#define STATE_PLAYING		5
+// Engine states  (It's ok to use ==, <, and > when testing)
+#define STATE_UNINITIALIZED	1     // Not even the constructors have been called.
+#define STATE_INITIALIZED	2     // Not ready, but most pointers are now valid or NULL
+#define STATE_PREPARED		3     // Drivers are set up, but not ready to process audio.
+#define STATE_READY		4     // Ready to process audio
+#define STATE_PLAYING		5     // Currently playing a sequence.
 
 inline int randomValue( int max );
 
diff --git a/libs/hydrogen/src/audio_engine.cpp b/libs/hydrogen/src/audio_engine.cpp
index 1fc69a7..3198e4d 100644
--- a/libs/hydrogen/src/audio_engine.cpp
+++ b/libs/hydrogen/src/audio_engine.cpp
@@ -118,7 +118,7 @@ bool AudioEngine::try_lock( const QString& locker )
 		WARNINGLOG( "trylock != 0. Lock in " + __locker );
 		return false;
 	}
-	__locker = locker;
+	//__locker = locker;
 
 	return true;
 }
diff --git a/libs/hydrogen/src/hydrogen.cpp b/libs/hydrogen/src/hydrogen.cpp
index 1d57f78..0551651 100644
--- a/libs/hydrogen/src/hydrogen.cpp
+++ b/libs/hydrogen/src/hydrogen.cpp
@@ -684,6 +684,7 @@ void audioEngine_clearNoteQueue()
 /// Clear all audio buffers
 inline void audioEngine_process_clearAudioBuffers( uint32_t nFrames )
 {
+	#warning "JACK API Error:  Can not cache output port pointers."
 	// clear main out Left and Right
 	if ( m_pMainBuffer_L ) {
 		memset( m_pMainBuffer_L, 0, nFrames * sizeof( float ) );
@@ -692,8 +693,7 @@ inline void audioEngine_process_clearAudioBuffers( uint32_t nFrames )
 		memset( m_pMainBuffer_R, 0, nFrames * sizeof( float ) );
 	}
 
-	if ( ( m_audioEngineState == STATE_READY )
-	     || ( m_audioEngineState == STATE_PLAYING ) ) {
+	if ( m_audioEngineState >= STATE_READY ) {
 #ifdef LADSPA_SUPPORT
 		Effects* pEffects = Effects::get_instance();
 		for ( unsigned i = 0; i < MAX_FX; ++i ) {	// clear FX buffers
@@ -712,7 +712,19 @@ inline void audioEngine_process_clearAudioBuffers( uint32_t nFrames )
 /// Main audio processing function. Called by audio drivers.
 int audioEngine_process( uint32_t nframes, void* /*arg*/ )
 {
-	if ( AudioEngine::get_instance()->try_lock( "audioEngine_process" ) == false ) {
+	static QString me("audioEngine_process");
+
+	if( m_audioEngineState < STATE_PREPARED) {
+		return 0;
+	}
+
+
+	if ( AudioEngine::get_instance()->try_lock( me ) == false ) {
+		return 0;
+	}
+
+	if( m_audioEngineState < STATE_READY) {
+		AudioEngine::get_instance()->unlock();
 		return 0;
 	}
 
@@ -790,8 +802,7 @@ int audioEngine_process( uint32_t nframes, void* /*arg*/ )
 	timeval ladspaTime_start = renderTime_end;
 #ifdef LADSPA_SUPPORT
 	// Process LADSPA FX
-	if ( ( m_audioEngineState == STATE_READY )
-	     || ( m_audioEngineState == STATE_PLAYING ) ) {
+	if ( m_audioEngineState >= STATE_READY ) {
 		for ( unsigned nFX = 0; nFX < MAX_FX; ++nFX ) {
 			LadspaFX *pFX = Effects::get_instance()->getLadspaFX( nFX );
 			if ( ( pFX ) && ( pFX->isEnabled() ) ) {
@@ -822,8 +833,7 @@ int audioEngine_process( uint32_t nframes, void* /*arg*/ )
 	// update master peaks
 	float val_L;
 	float val_R;
-	if ( m_audioEngineState == STATE_PLAYING
-	     || m_audioEngineState == STATE_READY ) {
+	if ( m_audioEngineState >= STATE_READY ) {
 		for ( unsigned i = 0; i < nframes; ++i ) {
 			val_L = m_pMainBuffer_L[i];
 			val_R = m_pMainBuffer_R[i];
@@ -1589,18 +1599,6 @@ void audioEngine_startAudioDrivers()
 #endif
 	}
 
-	// change the current audio engine state
-	if ( m_pSong == NULL ) {
-		m_audioEngineState = STATE_PREPARED;
-	} else {
-		m_audioEngineState = STATE_READY;
-	}
-
-
-	if ( m_pSong ) {
-		m_pAudioDriver->setBpm( m_pSong->__bpm );
-	}
-
 	// update the audiodriver reference in the sampler
 	AudioEngine::get_instance()->get_sampler()->set_audio_output( m_pAudioDriver );
 
@@ -1633,6 +1631,18 @@ void audioEngine_startAudioDrivers()
 
 
 
+	// change the current audio engine state
+	if ( m_pSong == NULL ) {
+		m_audioEngineState = STATE_PREPARED;
+	} else {
+		m_audioEngineState = STATE_READY;
+	}
+
+
+	if ( m_pSong ) {
+		m_pAudioDriver->setBpm( m_pSong->__bpm );
+	}
+
 	if ( m_audioEngineState == STATE_PREPARED ) {
 		EventQueue::get_instance()->push_event( EVENT_STATE, STATE_PREPARED );
 	} else if ( m_audioEngineState == STATE_READY ) {
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Hydrogen-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hydrogen-devel

Reply via email to