From 206c30ff730e9dee7f50bbd020dbc4d1500e7224 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Mon, 4 Jan 2010 16:47:25 +0100 Subject: [PATCH] AudioJack: do not use QVector in processCallback() Using QVector involves calls to malloc & friends which are not RT safe and thus must not be used in AudioJack::processCallback(). Instead allocate the required array upon initialization. (cherry picked from commit ae7a4e4c2f13432d39b13c25b66231bdd6a1cc65) --- include/AudioJack.h | 2 +- src/core/audio/AudioJack.cpp | 29 ++++++++++++++--------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/include/AudioJack.h b/include/AudioJack.h index 33673fab5..1e99bd91b 100644 --- a/include/AudioJack.h +++ b/include/AudioJack.h @@ -102,9 +102,9 @@ private: QSemaphore m_stopSemaphore; QVector m_outputPorts; + jack_default_audio_sample_t * * m_tempOutBufs; sampleFrameA * m_outBuf; - f_cnt_t m_framesDoneInCurBuf; f_cnt_t m_framesToDoInCurBuf; diff --git a/src/core/audio/AudioJack.cpp b/src/core/audio/AudioJack.cpp index 91a32fe05..a0710e6b1 100644 --- a/src/core/audio/AudioJack.cpp +++ b/src/core/audio/AudioJack.cpp @@ -53,6 +53,7 @@ AudioJack::AudioJack( bool & _success_ful, AudioOutputContext * context ) : m_client( NULL ), m_active( false ), m_stopSemaphore( 1 ), + m_tempOutBufs( new jack_default_audio_sample_t *[channels()] ), m_outBuf( CPU::allocFrames( mixer()->framesPerPeriod() ) ), m_framesDoneInCurBuf( 0 ), m_framesToDoInCurBuf( 0 ) @@ -66,6 +67,7 @@ AudioJack::AudioJack( bool & _success_ful, AudioOutputContext * context ) : this, SLOT( restartAfterZombified() ), Qt::QueuedConnection ); } + } @@ -91,6 +93,8 @@ AudioJack::~AudioJack() jack_client_close( m_client ); } + delete[] m_tempOutBufs; + CPU::freeFrames( m_outBuf ); } @@ -332,13 +336,11 @@ void AudioJack::renamePort( AudioPort * _port ) int AudioJack::processCallback( jack_nframes_t _nframes, void * _udata ) { - QVector outbufs( channels(), NULL ); - ch_cnt_t chnl = 0; - for( QVector::iterator it = - outbufs.begin(); it != outbufs.end(); ++it, ++chnl ) + for( int c = 0; c < channels(); ++c ) { - *it = (jack_default_audio_sample_t *) jack_port_get_buffer( - m_outputPorts[chnl], _nframes ); + m_tempOutBufs[c] = + (jack_default_audio_sample_t *) jack_port_get_buffer( + m_outputPorts[c], _nframes ); } #ifdef AUDIO_PORT_SUPPORT @@ -373,15 +375,12 @@ int AudioJack::processCallback( jack_nframes_t _nframes, void * _udata ) m_framesToDoInCurBuf - m_framesDoneInCurBuf ); const float gain = mixer()->masterGain(); - for( ch_cnt_t chnl = 0; chnl < channels(); ++chnl ) + for( int c = 0; c < channels(); ++c ) { - jack_default_audio_sample_t * o = outbufs[chnl]; - for( jack_nframes_t frame = 0; frame < todo; - ++frame ) + jack_default_audio_sample_t * o = m_tempOutBufs[c]; + for( jack_nframes_t frame = 0; frame < todo; ++frame ) { - o[done+frame] = - m_outBuf[m_framesDoneInCurBuf+ - frame][chnl] * gain; + o[done+frame] = m_outBuf[m_framesDoneInCurBuf+frame][c] * gain; } } done += todo; @@ -400,9 +399,9 @@ int AudioJack::processCallback( jack_nframes_t _nframes, void * _udata ) if( m_stopped == true ) { - for( ch_cnt_t ch = 0; ch < channels(); ++ch ) + for( int c = 0; c < channels(); ++c ) { - jack_default_audio_sample_t * b = outbufs[ch] + done; + jack_default_audio_sample_t * b = m_tempOutBufs[c] + done; memset( b, 0, sizeof( *b ) * ( _nframes - done ) ); } }