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)
This commit is contained in:
@@ -102,9 +102,9 @@ private:
|
||||
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;
|
||||
|
||||
|
||||
@@ -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 )
|
||||
@@ -65,6 +66,7 @@ AudioJack::AudioJack( bool & _success_ful, mixer * _mixer ) :
|
||||
this, SLOT( restartAfterZombified() ),
|
||||
Qt::QueuedConnection );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +92,8 @@ AudioJack::~AudioJack()
|
||||
jack_client_close( m_client );
|
||||
}
|
||||
|
||||
delete[] m_tempOutBufs;
|
||||
|
||||
delete[] m_outBuf;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
@@ -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 ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user