| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-19 06:43:20 +01:00
										 |  |  | // Copyright (C) 2016-2020, 2023 Edouard Griffiths, F4EXB <f4exb06@gmail.com>    //
 | 
					
						
							|  |  |  | // Copyright (C) 2020, 2022 Jon Beniston, M7RCE <jon@beniston.com>               //
 | 
					
						
							|  |  |  | // Copyright (C) 2022 Jiří Pinkava <jiri.pinkava@rossum.ai>                      //
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 14:32:15 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | #include <QAudioFormat>
 | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  | #include <QThread>
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
 | 
					
						
							|  |  |  | #include <QAudioSource>
 | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | #include <QAudioInput>
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  | #include "audio/audioinputdevice.h"
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #include "audio/audiodeviceinfo.h"
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | #include "audio/audiofifo.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  | MESSAGE_CLASS_DEFINITION(AudioInputDevice::MsgStart, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(AudioInputDevice::MsgStop, Message) | 
					
						
							|  |  |  | MESSAGE_CLASS_DEFINITION(AudioInputDevice::MsgReportSampleRate, Message) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  | AudioInputDevice::AudioInputDevice() : | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 	m_audioInput(0), | 
					
						
							|  |  |  | 	m_audioUsageCount(0), | 
					
						
							|  |  |  | 	m_onExit(false), | 
					
						
							| 
									
										
										
										
											2017-01-06 15:28:01 +01:00
										 |  |  | 	m_volume(0.5f), | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 	m_audioFifos() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  |     connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages()), Qt::QueuedConnection); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  | AudioInputDevice::~AudioInputDevice() | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  | 	// stop();
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  | 	// QMutexLocker mutexLocker(&m_mutex);
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  | 	// for (std::list<AudioFifo*>::iterator it = m_audioFifos.begin(); it != m_audioFifos.end(); ++it)
 | 
					
						
							|  |  |  | 	// {
 | 
					
						
							|  |  |  | 	// 	delete *it;
 | 
					
						
							|  |  |  | 	// }
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  | 	// m_audioFifos.clear();
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  | bool AudioInputDevice::start(int device, int rate) | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  | 	// if (m_audioUsageCount == 0)
 | 
					
						
							|  |  |  | 	// {
 | 
					
						
							|  |  |  |         qDebug("AudioInputDevice::start: device: %d rate: %d thread: %p", device, rate, QThread::currentThread()); | 
					
						
							| 
									
										
										
										
											2018-01-06 06:12:30 +01:00
										 |  |  |         QMutexLocker mutexLocker(&m_mutex); | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |         AudioDeviceInfo devInfo; | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (device < 0) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |             devInfo = AudioDeviceInfo::defaultInputDevice(); | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |             qWarning("AudioInputDevice::start: using default device %s", qPrintable(devInfo.defaultInputDevice().deviceName())); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |             QList<AudioDeviceInfo> devicesInfo = AudioDeviceInfo::availableInputDevices(); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (device < devicesInfo.size()) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 devInfo = devicesInfo[device]; | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |                 qWarning("AudioInputDevice::start: using audio device #%d: %s", device, qPrintable(devInfo.deviceName())); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |                 devInfo = AudioDeviceInfo::defaultInputDevice(); | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |                 qWarning("AudioInputDevice::start: audio device #%d does not exist. Using default device %s", device, qPrintable(devInfo.deviceName())); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         //QAudioDeviceInfo devInfo(QAudioDeviceInfo::defaultOutputDevice());
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         m_audioFormat.setSampleRate(rate); | 
					
						
							|  |  |  |         m_audioFormat.setChannelCount(2); | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
 | 
					
						
							|  |  |  |         m_audioFormat.setSampleFormat(QAudioFormat::Int16); | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |         m_audioFormat.setSampleSize(16); | 
					
						
							|  |  |  |         m_audioFormat.setCodec("audio/pcm"); | 
					
						
							|  |  |  |         m_audioFormat.setByteOrder(QAudioFormat::LittleEndian); | 
					
						
							| 
									
										
										
										
											2018-11-19 02:33:44 +01:00
										 |  |  |         m_audioFormat.setSampleType(QAudioFormat::SignedInt); // Unknown, SignedInt, UnSignedInt, Float
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (!devInfo.isFormatSupported(m_audioFormat)) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
 | 
					
						
							| 
									
										
										
										
											2024-04-19 01:06:24 +02:00
										 |  |  |             qWarning("AudioInputDevice::start: %d Hz S16_LE audio format not supported.", rate); | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  |             m_audioFormat = devInfo.deviceInfo().nearestFormat(m_audioFormat); | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |             qWarning("AudioInputDevice::start: %d Hz S16_LE audio format not supported. Nearest is sampleRate: %d channelCount: %d sampleSize: %d sampleType: %d", | 
					
						
							| 
									
										
										
										
											2018-11-19 02:33:44 +01:00
										 |  |  |                     rate, m_audioFormat.sampleRate(), m_audioFormat.channelCount(), m_audioFormat.sampleSize(), (int) m_audioFormat.sampleType()); | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-08-06 02:26:34 +02:00
										 |  |  |         else | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |             qInfo("AudioInputDevice::start: audio format OK"); | 
					
						
							| 
									
										
										
										
											2017-08-06 02:26:34 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
 | 
					
						
							|  |  |  |         if (m_audioFormat.sampleFormat() != QAudioFormat::Int16) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             qWarning("AudioInputDevice::start: Audio device '%s' failed", qPrintable(devInfo.deviceName())); | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |         if (m_audioFormat.sampleSize() != 16) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  |             qWarning("AudioInputDevice::start: Audio device '%s' failed", qPrintable(devInfo.deviceName())); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
 | 
					
						
							|  |  |  |         m_audioInput = new QAudioSource(devInfo.deviceInfo(), m_audioFormat); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  |         m_audioInput = new QAudioInput(devInfo.deviceInfo(), m_audioFormat); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-01-06 15:28:01 +01:00
										 |  |  |         m_audioInput->setVolume(m_volume); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  |         QIODevice::open(QIODevice::ReadWrite | QIODevice::Unbuffered); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         m_audioInput->start(this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  |         if (m_audioInput->state() != QAudio::ActiveState) { | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |             qWarning("AudioInputDevice::start: cannot start"); | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2024-09-03 18:38:32 +03:00
										 |  |  |             qDebug("AudioInputDevice::start: started buffer: %d bytes", (int)m_audioInput->bufferSize()); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  | 	// }
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  | 	// m_audioUsageCount++;
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  | void AudioInputDevice::stop() | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  |     if (!m_audioInput) { | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     qDebug("AudioInputDevice::stop: thread: %p", QThread::currentThread()); | 
					
						
							|  |  |  |     QMutexLocker mutexLocker(&m_mutex); | 
					
						
							|  |  |  |     m_audioInput->stop(); | 
					
						
							|  |  |  |     QIODevice::close(); | 
					
						
							|  |  |  |     delete m_audioInput; | 
					
						
							|  |  |  |     m_audioInput = nullptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // if (m_audioUsageCount > 0)
 | 
					
						
							|  |  |  |     // {
 | 
					
						
							|  |  |  |     //     m_audioUsageCount--;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //     if (m_audioUsageCount == 0)
 | 
					
						
							|  |  |  |     //     {
 | 
					
						
							|  |  |  |     //         qDebug("AudioInputDevice::stop: effectively close QIODevice");
 | 
					
						
							|  |  |  |     //         QMutexLocker mutexLocker(&m_mutex);
 | 
					
						
							|  |  |  |     //         QIODevice::close();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //         if (!m_onExit)
 | 
					
						
							|  |  |  |     //         {
 | 
					
						
							|  |  |  |     //             delete m_audioInput;
 | 
					
						
							|  |  |  |     //             m_audioInput = nullptr;
 | 
					
						
							|  |  |  |     //         }
 | 
					
						
							|  |  |  |     //     }
 | 
					
						
							|  |  |  |     // }
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  | void AudioInputDevice::addFifo(AudioFifo* audioFifo) | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	QMutexLocker mutexLocker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_audioFifos.push_back(audioFifo); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  | void AudioInputDevice::removeFifo(AudioFifo* audioFifo) | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	QMutexLocker mutexLocker(&m_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_audioFifos.remove(audioFifo); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  | qint64 AudioInputDevice::readData(char* data, qint64 maxLen) | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	Q_UNUSED(data); | 
					
						
							|  |  |  | 	Q_UNUSED(maxLen); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  | qint64 AudioInputDevice::writeData(const char *data, qint64 len) | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     // Study this mutex on OSX, for now deadlocks possible
 | 
					
						
							|  |  |  |     // Removed as it may indeed cause lockups and is in fact useless.
 | 
					
						
							|  |  |  | //#ifndef __APPLE__
 | 
					
						
							|  |  |  | //    QMutexLocker mutexLocker(&m_mutex);
 | 
					
						
							|  |  |  | //#endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
 | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |     if ((m_audioFormat.sampleSize() != 16) | 
					
						
							|  |  |  |     		|| (m_audioFormat.sampleType() != QAudioFormat::SignedInt) | 
					
						
							|  |  |  | 			|| (m_audioFormat.byteOrder() != QAudioFormat::LittleEndian)) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |     	qCritical("AudioInputDevice::writeData: invalid format not S16LE"); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |     	return 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-11-17 14:50:16 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_audioFormat.channelCount() != 2) { | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  |     	qCritical("AudioInputDevice::writeData: invalid format not stereo"); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  |     	return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 04:18:58 +01:00
										 |  |  | 	for (std::list<AudioFifo*>::iterator it = m_audioFifos.begin(); it != m_audioFifos.end(); ++it) | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-12 15:30:53 +02:00
										 |  |  | 		(*it)->write(reinterpret_cast<const quint8*>(data), len/4); | 
					
						
							| 
									
										
										
										
											2016-12-25 20:04:19 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-12 20:30:34 +01:00
										 |  |  | void AudioInputDevice::setVolume(float volume) | 
					
						
							| 
									
										
										
										
											2020-11-09 15:52:25 +00:00
										 |  |  | { | 
					
						
							|  |  |  |     m_volume = volume; | 
					
						
							|  |  |  |     if (m_audioInput != nullptr) | 
					
						
							|  |  |  |          m_audioInput->setVolume(m_volume); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-07-10 01:06:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | bool AudioInputDevice::handleMessage(const Message& cmd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (MsgStart::match(cmd)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         MsgStart ctl = (MsgStart&) cmd; | 
					
						
							|  |  |  |         start(ctl.getDeviceIndex(), ctl.getSampleRate()); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (MsgStop::match(cmd)) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         stop(); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AudioInputDevice::handleInputMessages() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Message* message; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while ((message = m_inputMessageQueue.pop()) != nullptr) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (handleMessage(*message)) { | 
					
						
							|  |  |  | 			delete message; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |