From 44fa0c5e5321775080dd42c151bda9a61fc35b95 Mon Sep 17 00:00:00 2001 From: Shmuel H Date: Mon, 6 Nov 2017 22:41:13 +0200 Subject: [PATCH] AudioJack: Basic implementation of capture (without AUDIO_PORT_SUPPORT) --- include/AudioJack.h | 5 +++++ src/core/audio/AudioJack.cpp | 41 ++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/include/AudioJack.h b/include/AudioJack.h index 9bbb3bd48..54e62ab7c 100644 --- a/include/AudioJack.h +++ b/include/AudioJack.h @@ -38,6 +38,8 @@ #include #include +#include + #include "AudioDevice.h" #include "AudioDeviceSetupWidget.h" @@ -110,7 +112,10 @@ private: MidiJack *m_midiClient; QVector m_outputPorts; + QVector m_inputPorts; jack_default_audio_sample_t * * m_tempOutBufs; + jack_default_audio_sample_t * * m_tempInBufs; + std::unique_ptr m_inBuffer; surroundSampleFrame * m_outBuf; f_cnt_t m_framesDoneInCurBuf; diff --git a/src/core/audio/AudioJack.cpp b/src/core/audio/AudioJack.cpp index 24f7b2f4f..012209ee9 100644 --- a/src/core/audio/AudioJack.cpp +++ b/src/core/audio/AudioJack.cpp @@ -47,7 +47,8 @@ AudioJack::AudioJack( bool & _success_ful, Mixer* _mixer ) : AudioDevice( tLimit( ConfigManager::inst()->value( "audiojack", "channels" ).toInt(), DEFAULT_CHANNELS, SURROUND_CHANNELS ), - _mixer ), + _mixer, + true /* supportsCapture */), m_client( NULL ), m_active( false ), m_midiClient( NULL ), @@ -187,11 +188,28 @@ bool AudioJack::initJackClient() JackPortIsOutput, 0 ) ); if( m_outputPorts.back() == NULL ) { - printf( "no more JACK-ports available!\n" ); + printf( "no more out JACK-ports available!\n" ); return false; } } + // Register In ports + for( ch_cnt_t ch = 0; ch < channels(); ++ch ) + { + QString name = QString( "master in " ) + + ( ( ch % 2 ) ? "R" : "L" ) + + QString::number( ch / 2 + 1 ); + m_inputPorts.push_back( jack_port_register( m_client, + name.toLatin1().constData(), + JACK_DEFAULT_AUDIO_TYPE, + JackPortIsInput, 0 ) ); + if( m_inputPorts.back() == NULL ) + { + printf( "no more in JACK-ports available!\n" ); + return false; + } + } + return true; } @@ -351,6 +369,10 @@ int AudioJack::processCallback( jack_nframes_t _nframes, void * _udata ) m_tempOutBufs[c] = (jack_default_audio_sample_t *) jack_port_get_buffer( m_outputPorts[c], _nframes ); + m_tempInBufs[c] = + (jack_default_audio_sample_t *) jack_port_get_buffer( + m_inputPorts[c], _nframes ); + } #ifdef AUDIO_PORT_SUPPORT @@ -405,6 +427,21 @@ int AudioJack::processCallback( jack_nframes_t _nframes, void * _udata ) } } + + m_inBuffer.reset (new sampleFrame[_nframes]); + + const float gain = mixer()->masterGain(); + for( int c = 0; c < channels(); ++c ) { + jack_default_audio_sample_t *channel_buffer = m_tempInBufs[c]; + + for( jack_nframes_t frame = 0; frame < _nframes; ++frame ) + { + m_inBuffer[frame][c] = channel_buffer[frame] /*/ gain*/; + } + } + + mixer()->pushInputFrames (m_inBuffer.get (), _nframes); + if( m_stopped == true ) { for( int c = 0; c < channels(); ++c )