2021-02-11 19:18:35 +00:00
/*
2022-03-23 15:45:51 +00:00
This class handles both RX and TX audio , each is created as a separate instance of the class
2021-05-23 15:09:41 +00:00
but as the setup / handling if output ( RX ) and input ( TX ) devices is so similar I have combined them .
2021-02-11 19:18:35 +00:00
*/
2021-06-16 22:44:59 +00:00
2021-02-11 19:18:35 +00:00
# include "audiohandler.h"
2021-05-16 20:16:59 +00:00
2021-02-23 21:21:22 +00:00
# include "logcategories.h"
2021-05-24 17:00:38 +00:00
# include "ulaw.h"
2021-02-13 00:45:59 +00:00
2021-11-01 20:27:33 +00:00
2021-06-16 22:44:59 +00:00
2021-06-04 07:24:26 +00:00
audioHandler : : audioHandler ( QObject * parent )
2021-02-11 19:18:35 +00:00
{
2021-05-30 11:07:51 +00:00
Q_UNUSED ( parent )
2021-02-11 19:18:35 +00:00
}
audioHandler : : ~ audioHandler ( )
{
2021-06-02 17:36:33 +00:00
2021-06-03 11:05:28 +00:00
if ( isInitialized ) {
2021-06-04 07:24:26 +00:00
stop ( ) ;
2021-06-02 17:36:33 +00:00
}
2022-04-03 23:01:08 +00:00
if ( audioInput ! = Q_NULLPTR ) {
audioInput = Q_NULLPTR ;
delete audioInput ;
}
if ( audioOutput ! = Q_NULLPTR ) {
delete audioOutput ;
audioOutput = Q_NULLPTR ;
}
2021-06-04 07:24:26 +00:00
if ( resampler ! = Q_NULLPTR ) {
speex_resampler_destroy ( resampler ) ;
qDebug ( logAudio ( ) ) < < " Resampler closed " ;
}
2021-06-16 08:49:38 +00:00
if ( encoder ! = Q_NULLPTR ) {
2021-08-15 10:36:08 +00:00
qInfo ( logAudio ( ) ) < < " Destroying opus encoder " ;
2021-06-16 08:49:38 +00:00
opus_encoder_destroy ( encoder ) ;
}
if ( decoder ! = Q_NULLPTR ) {
2021-08-15 10:36:08 +00:00
qInfo ( logAudio ( ) ) < < " Destroying opus decoder " ;
2021-06-16 08:49:38 +00:00
opus_decoder_destroy ( decoder ) ;
}
2021-02-11 19:18:35 +00:00
}
2021-06-04 07:24:26 +00:00
bool audioHandler : : init ( audioSetup setupIn )
2021-02-11 19:18:35 +00:00
{
2021-05-23 15:09:41 +00:00
if ( isInitialized ) {
return false ;
}
2021-06-04 07:24:26 +00:00
/*
0x01 uLaw 1 ch 8 bit
0x02 PCM 1 ch 8 bit
0x04 PCM 1 ch 16 bit
0x08 PCM 2 ch 8 bit
0x10 PCM 2 ch 16 bit
0x20 uLaw 2 ch 8 bit
*/
setup = setupIn ;
2022-04-03 19:16:52 +00:00
setup . format . setChannelCount ( 1 ) ;
setup . format . setSampleSize ( 8 ) ;
setup . format . setSampleType ( QAudioFormat : : UnSignedInt ) ;
2022-01-04 21:26:03 +00:00
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " audio handler starting: " < < setup . name ;
2021-06-04 07:24:26 +00:00
2022-04-05 15:47:43 +00:00
if ( setup . port . isNull ( ) )
{
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " No audio device was found. You probably need to install libqt5multimedia-plugins. " ;
return false ;
}
2021-06-04 07:24:26 +00:00
if ( setup . codec = = 0x01 | | setup . codec = = 0x20 ) {
setup . ulaw = true ;
2022-05-03 09:37:41 +00:00
setup . format . setSampleSize ( 16 ) ;
setup . format . setSampleType ( QAudioFormat : : SignedInt ) ;
2021-06-04 07:24:26 +00:00
}
2022-04-28 09:02:51 +00:00
2021-08-14 09:06:17 +00:00
if ( setup . codec = = 0x08 | | setup . codec = = 0x10 | | setup . codec = = 0x20 | | setup . codec = = 0x80 ) {
2022-04-03 19:16:52 +00:00
setup . format . setChannelCount ( 2 ) ;
2021-06-04 07:24:26 +00:00
}
2022-04-05 15:47:43 +00:00
2022-04-07 17:35:44 +00:00
if ( setup . codec = = 0x04 | | setup . codec = = 0x10 ) {
2022-04-03 19:16:52 +00:00
setup . format . setSampleSize ( 16 ) ;
setup . format . setSampleType ( QAudioFormat : : SignedInt ) ;
2021-06-04 07:24:26 +00:00
}
2021-03-09 17:22:16 +00:00
2022-04-07 17:35:44 +00:00
if ( setup . codec = = 0x40 | | setup . codec = = 0x80 ) {
setup . format . setSampleType ( QAudioFormat : : Float ) ;
}
2022-05-04 14:43:34 +00:00
2022-01-14 19:40:25 +00:00
qDebug ( logAudio ( ) ) < < " Creating " < < ( setup . isinput ? " Input " : " Output " ) < < " audio device: " < < setup . name < <
2022-04-03 19:16:52 +00:00
" , bits " < < setup . format . sampleSize ( ) < <
2022-01-14 19:40:25 +00:00
" , codec " < < setup . codec < <
" , latency " < < setup . latency < <
" , localAFGain " < < setup . localAFgain < <
2022-04-03 19:16:52 +00:00
" , radioChan " < < setup . format . channelCount ( ) < <
2022-01-14 19:40:25 +00:00
" , resampleQuality " < < setup . resampleQuality < <
2022-04-03 19:16:52 +00:00
" , samplerate " < < setup . format . sampleRate ( ) < <
2022-01-14 19:40:25 +00:00
" , uLaw " < < setup . ulaw ;
2021-07-06 06:24:35 +00:00
if ( ! setup . isinput )
{
this - > setVolume ( setup . localAFgain ) ;
}
2021-06-04 07:24:26 +00:00
2022-04-04 18:22:11 +00:00
format = setup . port . preferredFormat ( ) ;
2022-04-05 15:47:43 +00:00
qDebug ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Preferred Format: SampleSize " < < format . sampleSize ( ) < < " Channel Count " < < format . channelCount ( ) < <
2022-04-04 18:22:11 +00:00
" Sample Rate " < < format . sampleRate ( ) < < " Codec " < < format . codec ( ) < < " Sample Type " < < format . sampleType ( ) ;
2021-06-04 07:24:26 +00:00
if ( format . channelCount ( ) > 2 ) {
format . setChannelCount ( 2 ) ;
}
2021-06-07 13:04:52 +00:00
else if ( format . channelCount ( ) < 1 )
{
qCritical ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " No channels found, aborting setup. " ;
return false ;
}
2022-04-20 12:35:23 +00:00
if ( format . channelCount ( ) = = 1 & & setup . format . channelCount ( ) = = 2 ) {
format . setChannelCount ( 2 ) ;
if ( ! setup . port . isFormatSupported ( format ) ) {
qCritical ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Cannot request stereo input! " ;
format . setChannelCount ( 1 ) ;
}
}
2021-06-07 13:04:52 +00:00
2022-05-04 21:29:05 +00:00
if ( format . sampleType ( ) = = QAudioFormat : : SignedInt ) {
format . setSampleType ( QAudioFormat : : Float ) ;
format . setSampleSize ( 32 ) ;
if ( ! setup . port . isFormatSupported ( format ) ) {
qCritical ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Attempt to select 32bit Float failed, reverting to SignedInt " ;
format . setSampleType ( QAudioFormat : : SignedInt ) ;
format . setSampleSize ( 16 ) ;
}
}
2022-04-11 22:24:56 +00:00
if ( format . sampleSize ( ) = = 24 ) {
2022-04-28 09:02:51 +00:00
// We can't convert this easily so use 32 bit instead.
format . setSampleSize ( 32 ) ;
if ( ! setup . port . isFormatSupported ( format ) ) {
qCritical ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " 24 bit requested and 32 bit audio not supported, try 16 bit instead " ;
format . setSampleSize ( 16 ) ;
}
2022-04-11 22:24:56 +00:00
}
2022-05-04 14:43:34 +00:00
qDebug ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Selected format: SampleSize " < < format . sampleSize ( ) < < " Channel Count " < < format . channelCount ( ) < <
" Sample Rate " < < format . sampleRate ( ) < < " Codec " < < format . codec ( ) < < " Sample Type " < < format . sampleType ( ) ;
2021-06-04 07:24:26 +00:00
// We "hopefully" now have a valid format that is supported so try connecting
2021-06-07 09:40:04 +00:00
2021-06-04 07:24:26 +00:00
if ( setup . isinput ) {
audioInput = new QAudioInput ( setup . port , format , this ) ;
2022-04-10 22:13:51 +00:00
2022-04-06 20:52:22 +00:00
connect ( audioInput , SIGNAL ( stateChanged ( QAudio : : State ) ) , SLOT ( stateChanged ( QAudio : : State ) ) ) ;
2021-06-04 07:24:26 +00:00
}
else {
audioOutput = new QAudioOutput ( setup . port , format , this ) ;
2022-04-06 20:52:22 +00:00
connect ( audioOutput , SIGNAL ( stateChanged ( QAudio : : State ) ) , SLOT ( stateChanged ( QAudio : : State ) ) ) ;
2021-06-04 07:24:26 +00:00
}
2021-08-14 09:29:22 +00:00
// Setup resampler and opus if they are needed.
2021-06-04 07:24:26 +00:00
int resample_error = 0 ;
2021-08-14 09:29:22 +00:00
int opus_err = 0 ;
2021-06-04 07:24:26 +00:00
if ( setup . isinput ) {
2022-04-05 15:47:43 +00:00
resampler = wf_resampler_init ( format . channelCount ( ) , format . sampleRate ( ) , setup . format . sampleRate ( ) , setup . resampleQuality , & resample_error ) ;
2021-08-14 09:29:22 +00:00
if ( setup . codec = = 0x40 | | setup . codec = = 0x80 ) {
// Opus codec
2022-04-03 19:16:52 +00:00
encoder = opus_encoder_create ( setup . format . sampleRate ( ) , setup . format . channelCount ( ) , OPUS_APPLICATION_AUDIO , & opus_err ) ;
2021-08-14 09:29:22 +00:00
opus_encoder_ctl ( encoder , OPUS_SET_LSB_DEPTH ( 16 ) ) ;
opus_encoder_ctl ( encoder , OPUS_SET_INBAND_FEC ( 1 ) ) ;
opus_encoder_ctl ( encoder , OPUS_SET_DTX ( 1 ) ) ;
opus_encoder_ctl ( encoder , OPUS_SET_PACKET_LOSS_PERC ( 5 ) ) ;
2022-05-02 16:15:41 +00:00
opus_encoder_ctl ( encoder , OPUS_SET_COMPLEXITY ( 7 ) ) ; // Reduce complexity to maybe lower CPU?
2021-08-15 10:36:08 +00:00
qInfo ( logAudio ( ) ) < < " Creating opus encoder: " < < opus_strerror ( opus_err ) ;
2021-08-14 09:29:22 +00:00
}
2021-06-04 07:24:26 +00:00
}
else {
2022-04-03 19:16:52 +00:00
//resampBufs = new r8b::CFixedBuffer<double>[format.channelCount()];
//resamps = new r8b::CPtrKeeper<r8b::CDSPResampler24*>[format.channelCount()];
2022-04-05 15:47:43 +00:00
resampler = wf_resampler_init ( format . channelCount ( ) , setup . format . sampleRate ( ) , format . sampleRate ( ) , setup . resampleQuality , & resample_error ) ;
2021-08-14 09:29:22 +00:00
if ( setup . codec = = 0x40 | | setup . codec = = 0x80 ) {
// Opus codec
2022-04-07 15:03:50 +00:00
decoder = opus_decoder_create ( setup . format . sampleRate ( ) , setup . format . channelCount ( ) , & opus_err ) ;
2021-08-15 10:36:08 +00:00
qInfo ( logAudio ( ) ) < < " Creating opus decoder: " < < opus_strerror ( opus_err ) ;
2021-08-14 09:29:22 +00:00
}
2021-06-04 07:24:26 +00:00
}
2021-11-07 13:27:52 +00:00
unsigned int ratioNum ;
unsigned int ratioDen ;
2021-06-04 07:24:26 +00:00
2021-11-07 13:27:52 +00:00
wf_resampler_get_ratio ( resampler , & ratioNum , & ratioDen ) ;
2021-11-07 13:49:00 +00:00
resampleRatio = static_cast < double > ( ratioDen ) / ratioNum ;
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " wf_resampler_init() returned: " < < resample_error < < " resampleRatio: " < < resampleRatio ;
2021-08-14 09:29:22 +00:00
2021-06-04 07:24:26 +00:00
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " thread id " < < QThread : : currentThreadId ( ) ;
2022-04-06 21:02:43 +00:00
underTimer = new QTimer ( ) ;
underTimer - > setSingleShot ( true ) ;
2022-05-02 14:58:41 +00:00
connect ( underTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( clearUnderrun ( ) ) ) ;
2022-04-06 21:02:43 +00:00
2022-04-03 23:01:08 +00:00
this - > start ( ) ;
2022-04-06 21:02:43 +00:00
2022-04-05 15:47:43 +00:00
return true ;
2021-02-11 19:18:35 +00:00
}
2021-06-04 07:24:26 +00:00
void audioHandler : : start ( )
{
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " start() running " ;
if ( setup . isinput ) {
2022-04-03 23:01:08 +00:00
audioDevice = audioInput - > start ( ) ;
2022-05-02 14:58:41 +00:00
connect ( audioInput , SIGNAL ( destroyed ( ) ) , audioDevice , SLOT ( deleteLater ( ) ) , Qt : : UniqueConnection ) ;
2022-05-02 15:01:54 +00:00
connect ( audioDevice , SIGNAL ( readyRead ( ) ) , this , SLOT ( getNextAudioChunk ( ) ) , Qt : : UniqueConnection ) ;
2021-06-04 07:24:26 +00:00
}
else {
2022-05-02 10:52:23 +00:00
// Buffer size must be set before audio is started.
2022-05-02 11:55:58 +00:00
# ifdef Q_OS_WIN
audioOutput - > setBufferSize ( format . bytesForDuration ( setup . latency * 100 ) ) ;
# else
audioOutput - > setBufferSize ( format . bytesForDuration ( setup . latency * 1000 ) ) ;
# endif
2022-04-03 19:16:52 +00:00
audioDevice = audioOutput - > start ( ) ;
2022-05-02 14:58:41 +00:00
connect ( audioOutput , SIGNAL ( destroyed ( ) ) , audioDevice , SLOT ( deleteLater ( ) ) , Qt : : UniqueConnection ) ;
2022-04-03 23:01:08 +00:00
}
if ( ! audioDevice ) {
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Audio device failed to start() " ;
return ;
2021-06-04 07:24:26 +00:00
}
2022-04-06 18:40:14 +00:00
2021-06-04 07:24:26 +00:00
}
2022-04-04 10:47:55 +00:00
void audioHandler : : stop ( )
{
qDebug ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " stop() running " ;
if ( audioOutput ! = Q_NULLPTR & & audioOutput - > state ( ) ! = QAudio : : StoppedState ) {
// Stop audio output
audioOutput - > stop ( ) ;
}
if ( audioInput ! = Q_NULLPTR & & audioInput - > state ( ) ! = QAudio : : StoppedState ) {
// Stop audio output
audioInput - > stop ( ) ;
}
audioDevice = Q_NULLPTR ;
}
2021-03-22 18:53:34 +00:00
void audioHandler : : setVolume ( unsigned char volume )
2021-03-22 16:02:22 +00:00
{
2021-07-06 19:02:09 +00:00
this - > volume = audiopot [ volume ] ;
2022-04-04 10:12:06 +00:00
qDebug ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " setVolume: " < < volume < < " ( " < < this - > volume < < " ) " ;
2021-02-11 19:18:35 +00:00
}
2021-05-29 17:59:45 +00:00
void audioHandler : : incomingAudio ( audioPacket inPacket )
2021-02-11 19:18:35 +00:00
{
2022-05-02 10:56:40 +00:00
QTime startProcessing = QTime : : currentTime ( ) ;
2022-01-06 13:44:29 +00:00
audioPacket livePacket = inPacket ;
2022-04-07 15:03:50 +00:00
// Process uLaw.
if ( setup . ulaw )
{
// Current packet is 8bit so need to create a new buffer that is 16bit
QByteArray outPacket ( ( int ) livePacket . data . length ( ) * 2 , ( char ) 0xff ) ;
qint16 * out = ( qint16 * ) outPacket . data ( ) ;
for ( int f = 0 ; f < livePacket . data . length ( ) ; f + + )
{
* out + + = ulaw_decode [ ( quint8 ) livePacket . data [ f ] ] ;
}
livePacket . data . clear ( ) ;
livePacket . data = outPacket ; // Replace incoming data with converted.
}
2021-06-16 08:49:38 +00:00
2022-04-03 19:16:52 +00:00
/* Opus data */
2022-04-07 15:03:50 +00:00
if ( setup . codec = = 0x40 | | setup . codec = = 0x80 ) {
2021-06-16 18:14:21 +00:00
unsigned char * in = ( unsigned char * ) inPacket . data . data ( ) ;
2021-08-13 23:56:16 +00:00
2022-04-07 15:03:50 +00:00
//Decode the frame.
2022-04-03 19:16:52 +00:00
int nSamples = opus_packet_get_nb_samples ( in , livePacket . data . size ( ) , setup . format . sampleRate ( ) ) ;
2022-01-07 14:52:33 +00:00
if ( nSamples = = - 1 ) {
// No opus data yet?
return ;
2022-04-07 15:03:50 +00:00
}
2022-04-07 18:23:38 +00:00
QByteArray outPacket ( nSamples * sizeof ( float ) * setup . format . channelCount ( ) , ( char ) 0xff ) ; // Preset the output buffer size.
float * out = ( float * ) outPacket . data ( ) ;
2022-01-06 13:44:29 +00:00
if ( livePacket . seq > lastSentSeq + 1 ) {
2022-04-07 18:23:38 +00:00
nSamples = opus_decode_float ( decoder , Q_NULLPTR , 0 , out , nSamples , 1 ) ;
2022-01-05 15:27:46 +00:00
}
else {
2022-04-07 18:23:38 +00:00
nSamples = opus_decode_float ( decoder , in , livePacket . data . size ( ) , out , nSamples , 0 ) ;
2022-01-05 15:27:46 +00:00
}
2022-04-07 18:23:38 +00:00
2021-08-13 23:01:45 +00:00
if ( nSamples < 0 )
{
2022-01-06 13:44:29 +00:00
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Opus decode failed: " < < opus_strerror ( nSamples ) < < " packet size " < < livePacket . data . length ( ) ;
2021-06-16 08:49:38 +00:00
return ;
}
2021-06-16 09:35:45 +00:00
else {
2022-04-07 15:03:50 +00:00
if ( int ( nSamples * sizeof ( float ) * setup . format . channelCount ( ) ) ! = outPacket . size ( ) )
2021-06-16 22:44:59 +00:00
{
2022-04-07 15:03:50 +00:00
qDebug ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Opus decoder mismatch: nBytes: " < < nSamples * sizeof ( float ) * setup . format . channelCount ( ) < < " outPacket: " < < outPacket . size ( ) ;
outPacket . resize ( nSamples * sizeof ( float ) * setup . format . channelCount ( ) ) ;
2021-06-16 22:44:59 +00:00
}
2022-01-06 13:44:29 +00:00
//qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Opus decoded" << livePacket.data.size() << "bytes, into" << outPacket.length() << "bytes";
livePacket . data . clear ( ) ;
livePacket . data = outPacket ; // Replace incoming data with converted.
2021-06-16 09:35:45 +00:00
}
2021-06-16 08:49:38 +00:00
}
2021-06-16 18:14:21 +00:00
2022-04-03 19:16:52 +00:00
if ( ! livePacket . data . isEmpty ( ) ) {
Eigen : : VectorXf samplesF ;
2022-04-28 09:02:51 +00:00
if ( setup . format . sampleType ( ) = = QAudioFormat : : SignedInt & & setup . format . sampleSize ( ) = = 32 )
{
2022-04-28 11:32:40 +00:00
Eigen : : Ref < VectorXint32 > samplesI = Eigen : : Map < VectorXint32 > ( reinterpret_cast < qint32 * > ( livePacket . data . data ( ) ) , livePacket . data . size ( ) / int ( sizeof ( qint32 ) ) ) ;
2022-04-28 09:02:51 +00:00
samplesF = samplesI . cast < float > ( ) / float ( std : : numeric_limits < qint32 > : : max ( ) ) ;
}
else if ( setup . format . sampleType ( ) = = QAudioFormat : : SignedInt & & setup . format . sampleSize ( ) = = 16 )
2022-04-03 19:16:52 +00:00
{
2022-04-28 11:32:40 +00:00
Eigen : : Ref < VectorXint16 > samplesI = Eigen : : Map < VectorXint16 > ( reinterpret_cast < qint16 * > ( livePacket . data . data ( ) ) , livePacket . data . size ( ) / int ( sizeof ( qint16 ) ) ) ;
2022-04-03 23:01:08 +00:00
samplesF = samplesI . cast < float > ( ) / float ( std : : numeric_limits < qint16 > : : max ( ) ) ;
2022-04-03 19:16:52 +00:00
}
2022-04-28 09:02:51 +00:00
else if ( setup . format . sampleType ( ) = = QAudioFormat : : SignedInt & & setup . format . sampleSize ( ) = = 8 )
{
2022-04-28 11:32:40 +00:00
Eigen : : Ref < VectorXint8 > samplesI = Eigen : : Map < VectorXint8 > ( reinterpret_cast < qint8 * > ( livePacket . data . data ( ) ) , livePacket . data . size ( ) / int ( sizeof ( qint8 ) ) ) ;
2022-04-28 09:02:51 +00:00
samplesF = samplesI . cast < float > ( ) / float ( std : : numeric_limits < qint8 > : : max ( ) ) ; ;
}
2022-04-04 18:22:11 +00:00
else if ( setup . format . sampleType ( ) = = QAudioFormat : : UnSignedInt & & setup . format . sampleSize ( ) = = 8 )
2022-04-03 19:16:52 +00:00
{
2022-04-28 11:32:40 +00:00
Eigen : : Ref < VectorXuint8 > samplesI = Eigen : : Map < VectorXuint8 > ( reinterpret_cast < quint8 * > ( livePacket . data . data ( ) ) , livePacket . data . size ( ) / int ( sizeof ( quint8 ) ) ) ;
2022-04-03 19:16:52 +00:00
samplesF = samplesI . cast < float > ( ) / float ( std : : numeric_limits < quint8 > : : max ( ) ) ; ;
}
2022-04-07 15:03:50 +00:00
else if ( setup . format . sampleType ( ) = = QAudioFormat : : Float ) {
samplesF = Eigen : : Map < Eigen : : VectorXf > ( reinterpret_cast < float * > ( livePacket . data . data ( ) ) , livePacket . data . size ( ) / int ( sizeof ( float ) ) ) ;
}
else
{
2022-04-05 15:47:43 +00:00
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Unsupported Sample Type: " < < format . sampleType ( ) ;
}
2022-04-03 19:16:52 +00:00
2022-04-04 18:22:11 +00:00
/* samplesF is now an Eigen Vector of the current samples in float format */
2022-04-06 18:40:14 +00:00
2022-04-03 19:16:52 +00:00
// Set the max amplitude found in the vector
2022-04-04 18:22:11 +00:00
// Should it be before or after volume is applied?
2022-04-06 18:40:14 +00:00
2022-04-03 19:16:52 +00:00
amplitude = samplesF . array ( ) . abs ( ) . maxCoeff ( ) ;
// Set the volume
samplesF * = volume ;
2022-04-28 09:02:51 +00:00
if ( setup . format . channelCount ( ) = = 2 & & format . channelCount ( ) = = 1 ) {
// If we need to drop one of the audio channels, do it now
Eigen : : VectorXf samplesTemp ( samplesF . size ( ) / 2 ) ;
samplesTemp = Eigen : : Map < Eigen : : VectorXf , 0 , Eigen : : InnerStride < 2 > > ( samplesF . data ( ) , samplesF . size ( ) / 2 ) ;
samplesF = samplesTemp ;
}
else if ( setup . format . channelCount ( ) = = 1 & & format . channelCount ( ) = = 2 ) {
// Convert mono to stereo if required
2022-04-03 19:16:52 +00:00
Eigen : : VectorXf samplesTemp ( samplesF . size ( ) * 2 ) ;
Eigen : : Map < Eigen : : VectorXf , 0 , Eigen : : InnerStride < 2 > > ( samplesTemp . data ( ) , samplesF . size ( ) ) = samplesF ;
Eigen : : Map < Eigen : : VectorXf , 0 , Eigen : : InnerStride < 2 > > ( samplesTemp . data ( ) + 1 , samplesF . size ( ) ) = samplesF ;
samplesF = samplesTemp ;
}
2022-04-28 09:02:51 +00:00
// We now have format.channelCount() (native) channels of audio.
2022-04-03 19:16:52 +00:00
2022-04-05 15:47:43 +00:00
if ( resampleRatio ! = 1.0 ) {
// We need to resample
// We have a stereo 16bit stream.
2022-04-05 18:02:29 +00:00
quint32 outFrames = ( ( samplesF . size ( ) / format . channelCount ( ) ) * resampleRatio ) ;
quint32 inFrames = ( samplesF . size ( ) / format . channelCount ( ) ) ;
2022-04-05 15:47:43 +00:00
QByteArray outPacket ( outFrames * format . channelCount ( ) * sizeof ( float ) , ( char ) 0xff ) ; // Preset the output buffer size.
2022-04-05 18:02:29 +00:00
const float * in = ( float * ) samplesF . data ( ) ;
2022-04-05 15:47:43 +00:00
float * out = ( float * ) outPacket . data ( ) ;
int err = 0 ;
2022-04-07 15:03:50 +00:00
if ( format . channelCount ( ) = = 1 ) {
err = wf_resampler_process_float ( resampler , 0 , in , & inFrames , out , & outFrames ) ;
}
else {
err = wf_resampler_process_interleaved_float ( resampler , in , & inFrames , out , & outFrames ) ;
}
2022-04-05 15:47:43 +00:00
if ( err ) {
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Resampler error " < < err < < " inFrames: " < < inFrames < < " outFrames: " < < outFrames ;
}
samplesF = Eigen : : Map < Eigen : : VectorXf > ( reinterpret_cast < float * > ( outPacket . data ( ) ) , outPacket . size ( ) / int ( sizeof ( float ) ) ) ;
}
2022-04-04 18:22:11 +00:00
if ( format . sampleType ( ) = = QAudioFormat : : UnSignedInt & & format . sampleSize ( ) = = 8 )
{
Eigen : : VectorXf samplesITemp = samplesF * float ( std : : numeric_limits < quint8 > : : max ( ) ) ;
VectorXuint8 samplesI = samplesITemp . cast < quint8 > ( ) ;
livePacket . data = QByteArray ( reinterpret_cast < char * > ( samplesI . data ( ) ) , int ( samplesI . size ( ) ) * int ( sizeof ( quint8 ) ) ) ;
}
2022-04-28 09:02:51 +00:00
if ( format . sampleType ( ) = = QAudioFormat : : SignedInt & & format . sampleSize ( ) = = 8 )
{
Eigen : : VectorXf samplesITemp = samplesF * float ( std : : numeric_limits < qint8 > : : max ( ) ) ;
VectorXint8 samplesI = samplesITemp . cast < qint8 > ( ) ;
livePacket . data = QByteArray ( reinterpret_cast < char * > ( samplesI . data ( ) ) , int ( samplesI . size ( ) ) * int ( sizeof ( qint8 ) ) ) ;
}
2022-04-04 18:22:11 +00:00
if ( format . sampleType ( ) = = QAudioFormat : : SignedInt & & format . sampleSize ( ) = = 16 )
2022-04-03 19:16:52 +00:00
{
2022-04-03 23:01:08 +00:00
Eigen : : VectorXf samplesITemp = samplesF * float ( std : : numeric_limits < qint16 > : : max ( ) ) ;
VectorXint16 samplesI = samplesITemp . cast < qint16 > ( ) ;
2022-04-03 19:16:52 +00:00
livePacket . data = QByteArray ( reinterpret_cast < char * > ( samplesI . data ( ) ) , int ( samplesI . size ( ) ) * int ( sizeof ( qint16 ) ) ) ;
}
2022-04-04 18:22:11 +00:00
else if ( format . sampleType ( ) = = QAudioFormat : : SignedInt & & format . sampleSize ( ) = = 32 )
{
Eigen : : VectorXf samplesITemp = samplesF * float ( std : : numeric_limits < qint32 > : : max ( ) ) ;
VectorXint32 samplesI = samplesITemp . cast < qint32 > ( ) ;
livePacket . data = QByteArray ( reinterpret_cast < char * > ( samplesI . data ( ) ) , int ( samplesI . size ( ) ) * int ( sizeof ( qint32 ) ) ) ;
}
else if ( format . sampleType ( ) = = QAudioFormat : : Float )
2022-04-03 19:16:52 +00:00
{
livePacket . data = QByteArray ( reinterpret_cast < char * > ( samplesF . data ( ) ) , int ( samplesF . size ( ) ) * int ( sizeof ( float ) ) ) ;
}
2022-04-04 18:22:11 +00:00
else {
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Unsupported Sample Type: " < < format . sampleType ( ) ;
}
2022-04-03 19:16:52 +00:00
2022-05-02 11:55:58 +00:00
currentLatency = livePacket . time . msecsTo ( QTime : : currentTime ( ) ) + ( format . durationForBytes ( audioOutput - > bufferSize ( ) - audioOutput - > bytesFree ( ) ) / 1000 ) ;
2022-04-04 10:12:06 +00:00
if ( audioDevice ! = Q_NULLPTR ) {
audioDevice - > write ( livePacket . data ) ;
2022-05-02 12:08:42 +00:00
if ( lastReceived . msecsTo ( QTime : : currentTime ( ) ) > 100 ) {
2022-05-02 10:56:40 +00:00
qDebug ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Time since last audio packet " < < lastReceived . msecsTo ( QTime : : currentTime ( ) ) < < " Expected around " < < setup . blockSize < < " Processing time " < < startProcessing . msecsTo ( QTime : : currentTime ( ) ) ;
}
lastReceived = QTime : : currentTime ( ) ;
2022-04-04 10:12:06 +00:00
}
2022-04-03 19:16:52 +00:00
if ( ( inPacket . seq > lastSentSeq + 1 ) & & ( setup . codec = = 0x40 | | setup . codec = = 0x80 ) ) {
qDebug ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Attempting FEC on packet " < < inPacket . seq < < " as last is " < < lastSentSeq ;
lastSentSeq = inPacket . seq ;
incomingAudio ( inPacket ) ; // Call myself again to run the packet a second time (FEC)
2021-03-09 17:22:16 +00:00
}
2021-05-27 12:54:52 +00:00
2022-01-05 15:27:46 +00:00
lastSentSeq = inPacket . seq ;
2021-05-27 10:41:08 +00:00
}
2022-03-18 15:41:11 +00:00
2022-04-06 20:52:22 +00:00
emit haveLevels ( getAmplitude ( ) , setup . latency , currentLatency , isUnderrun ) ;
2021-05-27 17:34:44 +00:00
return ;
2021-02-11 19:18:35 +00:00
}
2021-08-14 15:04:50 +00:00
2022-04-10 22:13:51 +00:00
void audioHandler : : getNextAudioChunk ( )
2021-02-12 20:42:56 +00:00
{
2022-04-10 23:23:08 +00:00
tempBuf . data . append ( audioDevice - > readAll ( ) ) ;
2022-05-02 12:53:49 +00:00
while ( tempBuf . data . length ( ) > = format . bytesForDuration ( setup . blockSize * 1000 ) ) {
audioPacket livePacket ;
livePacket . time = QTime : : currentTime ( ) ;
livePacket . sent = 0 ;
memcpy ( & livePacket . guid , setup . guid , GUIDLEN ) ;
2022-05-02 10:56:40 +00:00
QTime startProcessing = QTime : : currentTime ( ) ;
2022-04-11 11:11:10 +00:00
livePacket . data . clear ( ) ;
livePacket . data = tempBuf . data . mid ( 0 , format . bytesForDuration ( setup . blockSize * 1000 ) ) ;
tempBuf . data . remove ( 0 , format . bytesForDuration ( setup . blockSize * 1000 ) ) ;
2022-04-11 10:44:53 +00:00
if ( livePacket . data . length ( ) > 0 )
2021-02-27 09:34:56 +00:00
{
2022-04-11 10:44:53 +00:00
Eigen : : VectorXf samplesF ;
if ( format . sampleType ( ) = = QAudioFormat : : SignedInt & & format . sampleSize ( ) = = 32 )
{
2022-04-28 11:32:40 +00:00
Eigen : : Ref < VectorXint32 > samplesI = Eigen : : Map < VectorXint32 > ( reinterpret_cast < qint32 * > ( livePacket . data . data ( ) ) , livePacket . data . size ( ) / int ( sizeof ( qint32 ) ) ) ;
2022-04-11 10:44:53 +00:00
samplesF = samplesI . cast < float > ( ) / float ( std : : numeric_limits < qint32 > : : max ( ) ) ;
}
else if ( format . sampleType ( ) = = QAudioFormat : : SignedInt & & format . sampleSize ( ) = = 16 )
{
2022-04-28 11:32:40 +00:00
Eigen : : Ref < VectorXint16 > samplesI = Eigen : : Map < VectorXint16 > ( reinterpret_cast < qint16 * > ( livePacket . data . data ( ) ) , livePacket . data . size ( ) / int ( sizeof ( qint16 ) ) ) ;
2022-04-11 10:44:53 +00:00
samplesF = samplesI . cast < float > ( ) / float ( std : : numeric_limits < qint16 > : : max ( ) ) ;
}
else if ( format . sampleType ( ) = = QAudioFormat : : UnSignedInt & & format . sampleSize ( ) = = 8 )
{
2022-04-28 11:32:40 +00:00
Eigen : : Ref < VectorXuint8 > samplesI = Eigen : : Map < VectorXuint8 > ( reinterpret_cast < quint8 * > ( livePacket . data . data ( ) ) , livePacket . data . size ( ) / int ( sizeof ( quint8 ) ) ) ;
2022-04-11 10:44:53 +00:00
samplesF = samplesI . cast < float > ( ) / float ( std : : numeric_limits < quint8 > : : max ( ) ) ; ;
}
else if ( format . sampleType ( ) = = QAudioFormat : : SignedInt & & format . sampleSize ( ) = = 8 )
{
2022-04-28 11:32:40 +00:00
Eigen : : Ref < VectorXint8 > samplesI = Eigen : : Map < VectorXint8 > ( reinterpret_cast < qint8 * > ( livePacket . data . data ( ) ) , livePacket . data . size ( ) / int ( sizeof ( qint8 ) ) ) ;
2022-04-11 10:44:53 +00:00
samplesF = samplesI . cast < float > ( ) / float ( std : : numeric_limits < qint8 > : : max ( ) ) ; ;
}
else if ( format . sampleType ( ) = = QAudioFormat : : Float )
{
samplesF = Eigen : : Map < Eigen : : VectorXf > ( reinterpret_cast < float * > ( livePacket . data . data ( ) ) , livePacket . data . size ( ) / int ( sizeof ( float ) ) ) ;
}
else {
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Unsupported Sample Type: " < < format . sampleType ( ) < < format . sampleSize ( ) ;
}
2021-05-29 17:59:45 +00:00
2022-04-11 10:44:53 +00:00
/* samplesF is now an Eigen Vector of the current samples in float format */
2022-04-05 15:47:43 +00:00
2022-04-11 10:44:53 +00:00
// Set the max amplitude found in the vector
if ( samplesF . size ( ) > 0 ) {
amplitude = samplesF . array ( ) . abs ( ) . maxCoeff ( ) ;
2021-06-16 18:00:56 +00:00
2022-04-11 10:44:53 +00:00
if ( resampleRatio ! = 1.0 ) {
2021-06-16 08:49:38 +00:00
2022-04-11 10:44:53 +00:00
// We need to resample
// We have a stereo 16bit stream.
quint32 outFrames = ( ( samplesF . size ( ) / format . channelCount ( ) ) * resampleRatio ) ;
quint32 inFrames = ( samplesF . size ( ) / format . channelCount ( ) ) ;
2021-08-14 11:08:50 +00:00
2022-04-11 10:44:53 +00:00
QByteArray outPacket ( outFrames * format . channelCount ( ) * sizeof ( float ) , ( char ) 0xff ) ; // Preset the output buffer size.
const float * in = ( float * ) samplesF . data ( ) ;
float * out = ( float * ) outPacket . data ( ) ;
2022-04-06 18:40:14 +00:00
2022-04-11 10:44:53 +00:00
int err = 0 ;
if ( format . channelCount ( ) = = 1 ) {
err = wf_resampler_process_float ( resampler , 0 , in , & inFrames , out , & outFrames ) ;
}
else {
err = wf_resampler_process_interleaved_float ( resampler , in , & inFrames , out , & outFrames ) ;
}
if ( err ) {
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Resampler error " < < err < < " inFrames: " < < inFrames < < " outFrames: " < < outFrames ;
}
samplesF = Eigen : : Map < Eigen : : VectorXf > ( reinterpret_cast < float * > ( outPacket . data ( ) ) , outPacket . size ( ) / int ( sizeof ( float ) ) ) ;
2022-04-10 23:05:54 +00:00
}
2022-04-05 15:47:43 +00:00
2022-04-11 10:44:53 +00:00
// If we need to drop one of the audio channels, do it now
if ( format . channelCount ( ) = = 2 & & setup . format . channelCount ( ) = = 1 ) {
Eigen : : VectorXf samplesTemp ( samplesF . size ( ) / 2 ) ;
samplesTemp = Eigen : : Map < Eigen : : VectorXf , 0 , Eigen : : InnerStride < 2 > > ( samplesF . data ( ) , samplesF . size ( ) / 2 ) ;
samplesF = samplesTemp ;
}
2022-04-20 12:35:23 +00:00
else if ( format . channelCount ( ) = = 1 & & setup . format . channelCount ( ) = = 2 ) {
// Convert mono to stereo if required
Eigen : : VectorXf samplesTemp ( samplesF . size ( ) * 2 ) ;
Eigen : : Map < Eigen : : VectorXf , 0 , Eigen : : InnerStride < 2 > > ( samplesTemp . data ( ) , samplesF . size ( ) ) = samplesF ;
Eigen : : Map < Eigen : : VectorXf , 0 , Eigen : : InnerStride < 2 > > ( samplesTemp . data ( ) + 1 , samplesF . size ( ) ) = samplesF ;
samplesF = samplesTemp ;
}
2022-04-07 16:35:58 +00:00
2022-04-11 11:13:48 +00:00
//qInfo(logAudio()) << "Sending audio len" << livePacket.data.length() << "remaining" << tempBuf.data.length() << "resampled" << samplesF.size();
2022-04-07 16:35:58 +00:00
2022-04-11 10:44:53 +00:00
if ( setup . codec = = 0x40 | | setup . codec = = 0x80 )
{
//Are we using the opus codec?
float * in = ( float * ) samplesF . data ( ) ;
/* Encode the frame. */
QByteArray outPacket ( 1275 , ( char ) 0xff ) ; // Preset the output buffer size to MAXIMUM possible Opus frame size
unsigned char * out = ( unsigned char * ) outPacket . data ( ) ;
int nbBytes = opus_encode_float ( encoder , in , ( samplesF . size ( ) / setup . format . channelCount ( ) ) , out , outPacket . length ( ) ) ;
if ( nbBytes < 0 )
{
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Opus encode failed: " < < opus_strerror ( nbBytes ) < < " Num Samples: " < < samplesF . size ( ) ;
return ;
}
else {
outPacket . resize ( nbBytes ) ;
samplesF = Eigen : : Map < Eigen : : VectorXf > ( reinterpret_cast < float * > ( outPacket . data ( ) ) , outPacket . size ( ) / int ( sizeof ( float ) ) ) ;
}
}
2022-04-07 16:35:58 +00:00
2022-04-10 23:05:54 +00:00
2022-04-11 10:44:53 +00:00
if ( setup . format . sampleType ( ) = = QAudioFormat : : SignedInt & & setup . format . sampleSize ( ) = = 8 )
{
Eigen : : VectorXf samplesITemp = samplesF * float ( std : : numeric_limits < qint8 > : : max ( ) ) ;
VectorXint8 samplesI = samplesITemp . cast < qint8 > ( ) ;
livePacket . data = QByteArray ( reinterpret_cast < char * > ( samplesI . data ( ) ) , int ( samplesI . size ( ) ) * int ( sizeof ( qint8 ) ) ) ;
}
else if ( setup . format . sampleType ( ) = = QAudioFormat : : UnSignedInt & & setup . format . sampleSize ( ) = = 8 )
{
Eigen : : VectorXf samplesITemp = samplesF * float ( std : : numeric_limits < quint8 > : : max ( ) ) ;
VectorXuint8 samplesI = samplesITemp . cast < quint8 > ( ) ;
livePacket . data = QByteArray ( reinterpret_cast < char * > ( samplesI . data ( ) ) , int ( samplesI . size ( ) ) * int ( sizeof ( quint8 ) ) ) ;
}
else if ( setup . format . sampleType ( ) = = QAudioFormat : : SignedInt & & setup . format . sampleSize ( ) = = 16 )
{
Eigen : : VectorXf samplesITemp = samplesF * float ( std : : numeric_limits < qint16 > : : max ( ) ) ;
VectorXint16 samplesI = samplesITemp . cast < qint16 > ( ) ;
livePacket . data = QByteArray ( reinterpret_cast < char * > ( samplesI . data ( ) ) , int ( samplesI . size ( ) ) * int ( sizeof ( qint16 ) ) ) ;
}
else if ( setup . format . sampleType ( ) = = QAudioFormat : : SignedInt & & setup . format . sampleSize ( ) = = 32 )
{
Eigen : : VectorXf samplesITemp = samplesF * float ( std : : numeric_limits < qint32 > : : max ( ) ) ;
VectorXint32 samplesI = samplesITemp . cast < qint32 > ( ) ;
livePacket . data = QByteArray ( reinterpret_cast < char * > ( samplesI . data ( ) ) , int ( samplesI . size ( ) ) * int ( sizeof ( qint32 ) ) ) ;
}
else if ( setup . format . sampleType ( ) = = QAudioFormat : : Float )
2022-04-06 18:40:14 +00:00
{
2022-04-11 10:44:53 +00:00
livePacket . data = QByteArray ( reinterpret_cast < char * > ( samplesF . data ( ) ) , int ( samplesF . size ( ) ) * int ( sizeof ( float ) ) ) ;
2021-08-13 19:41:42 +00:00
}
else {
2022-04-11 10:44:53 +00:00
qInfo ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Unsupported Sample Type: " < < format . sampleType ( ) ;
2022-04-06 18:40:14 +00:00
}
2022-04-11 10:44:53 +00:00
/* Need to find a floating point uLaw encoder!*/
if ( setup . ulaw )
2022-04-06 18:40:14 +00:00
{
2022-04-11 10:44:53 +00:00
QByteArray outPacket ( ( int ) livePacket . data . length ( ) / 2 , ( char ) 0xff ) ;
qint16 * in = ( qint16 * ) livePacket . data . data ( ) ;
for ( int f = 0 ; f < outPacket . length ( ) ; f + + )
{
qint16 sample = * in + + ;
if ( setup . ulaw ) {
int sign = ( sample > > 8 ) & 0x80 ;
if ( sign )
sample = ( short ) - sample ;
if ( sample > cClip )
sample = cClip ;
sample = ( short ) ( sample + cBias ) ;
int exponent = ( int ) MuLawCompressTable [ ( sample > > 7 ) & 0xFF ] ;
int mantissa = ( sample > > ( exponent + 3 ) ) & 0x0F ;
int compressedByte = ~ ( sign | ( exponent < < 4 ) | mantissa ) ;
outPacket [ f ] = ( quint8 ) compressedByte ;
}
2022-04-06 18:40:14 +00:00
}
2022-04-11 10:44:53 +00:00
livePacket . data . clear ( ) ;
livePacket . data = outPacket ; // Copy output packet back to input buffer.
2022-04-06 18:40:14 +00:00
}
2022-04-11 10:44:53 +00:00
emit haveAudioData ( livePacket ) ;
2022-05-02 12:08:42 +00:00
if ( lastReceived . msecsTo ( QTime : : currentTime ( ) ) > 100 ) {
2022-05-02 10:56:40 +00:00
qDebug ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Time since last audio packet " < < lastReceived . msecsTo ( QTime : : currentTime ( ) ) < < " Expected around " < < setup . blockSize < < " Processing time " < < startProcessing . msecsTo ( QTime : : currentTime ( ) ) ;
}
2022-05-02 14:58:41 +00:00
lastReceived = QTime : : currentTime ( ) ;
2022-04-11 10:44:53 +00:00
//ret = livePacket.data;
2021-08-13 19:41:42 +00:00
}
2022-04-05 15:47:43 +00:00
}
2022-04-11 10:44:53 +00:00
emit haveLevels ( getAmplitude ( ) , setup . latency , currentLatency , isUnderrun ) ;
2021-02-27 09:34:56 +00:00
}
2021-05-23 15:09:41 +00:00
return ;
2021-05-27 12:54:52 +00:00
2021-02-12 20:42:56 +00:00
}
2021-05-23 15:09:41 +00:00
2022-04-05 15:47:43 +00:00
void audioHandler : : changeLatency ( const quint16 newSize )
{
setup . latency = newSize ;
if ( ! setup . isinput ) {
stop ( ) ;
start ( ) ;
}
2022-05-02 11:55:58 +00:00
qDebug ( logAudio ( ) ) < < ( setup . isinput ? " Input " : " Output " ) < < " Configured latency: " < < setup . latency < < " Buffer Duration: " < < format . durationForBytes ( audioOutput - > bufferSize ( ) ) / 1000 < < " ms " ;
2022-04-05 15:47:43 +00:00
}
int audioHandler : : getLatency ( )
{
return currentLatency ;
}
2021-06-04 07:24:26 +00:00
2022-01-22 15:12:36 +00:00
quint16 audioHandler : : getAmplitude ( )
{
2022-04-03 23:01:08 +00:00
return static_cast < quint16 > ( amplitude * 255.0 ) ;
2022-01-22 15:12:36 +00:00
}
2021-02-11 19:18:35 +00:00
2022-04-06 20:52:22 +00:00
void audioHandler : : stateChanged ( QAudio : : State state )
{
// Process the state
switch ( state )
{
case QAudio : : IdleState :
{
isUnderrun = true ;
2022-05-02 10:52:23 +00:00
if ( underTimer - > isActive ( ) ) {
underTimer - > stop ( ) ;
2022-04-06 21:02:43 +00:00
}
2022-04-06 20:52:22 +00:00
break ;
}
case QAudio : : ActiveState :
{
2022-05-02 10:52:23 +00:00
//qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Audio started!";
if ( ! underTimer - > isActive ( ) ) {
underTimer - > start ( 500 ) ;
}
2022-04-06 20:52:22 +00:00
break ;
}
case QAudio : : SuspendedState :
{
break ;
}
case QAudio : : StoppedState :
{
break ;
}
default : {
}
break ;
}
}
void audioHandler : : clearUnderrun ( )
{
isUnderrun = false ;
2022-05-04 21:29:05 +00:00
}