Skip to content

Commit

Permalink
AudioJack: do not use QVector in processCallback()
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
tobydox committed Jul 26, 2010
1 parent 2ba532b commit 2b73083
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/AudioJack.h
Expand Up @@ -102,9 +102,9 @@ private slots:
QSemaphore m_stopSemaphore;

QVector<jack_port_t *> m_outputPorts;
jack_default_audio_sample_t * * m_tempOutBufs;
surroundSampleFrame * m_outBuf;


f_cnt_t m_framesDoneInCurBuf;
f_cnt_t m_framesToDoInCurBuf;

Expand Down
29 changes: 14 additions & 15 deletions src/core/audio/AudioJack.cpp
Expand Up @@ -52,6 +52,7 @@ AudioJack::AudioJack( bool & _success_ful, mixer * _mixer ) :
m_client( NULL ),
m_active( false ),
m_stopSemaphore( 1 ),
m_tempOutBufs( new jack_default_audio_sample_t *[channels()] ),
m_outBuf( new surroundSampleFrame[getMixer()->framesPerPeriod()] ),
m_framesDoneInCurBuf( 0 ),
m_framesToDoInCurBuf( 0 )
Expand All @@ -65,6 +66,7 @@ AudioJack::AudioJack( bool & _success_ful, mixer * _mixer ) :
this, SLOT( restartAfterZombified() ),
Qt::QueuedConnection );
}

}


Expand All @@ -90,6 +92,8 @@ AudioJack::~AudioJack()
jack_client_close( m_client );
}

delete[] m_tempOutBufs;

delete[] m_outBuf;
}

Expand Down Expand Up @@ -332,13 +336,11 @@ void AudioJack::renamePort( AudioPort * _port )

int AudioJack::processCallback( jack_nframes_t _nframes, void * _udata )
{
QVector<jack_default_audio_sample_t *> outbufs( channels(), NULL );
ch_cnt_t chnl = 0;
for( QVector<jack_default_audio_sample_t *>::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
Expand Down Expand Up @@ -373,15 +375,12 @@ int AudioJack::processCallback( jack_nframes_t _nframes, void * _udata )
m_framesToDoInCurBuf -
m_framesDoneInCurBuf );
const float gain = getMixer()->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;
Expand All @@ -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 ) );
}
}
Expand Down

0 comments on commit 2b73083

Please sign in to comment.