Skip to content
Snippets Groups Projects
tqtaudioin.cpp 9.26 KiB
/***************************************************************************
 *   Copyright (C) 2015-2021 by Tomasz Bojczuk                             *
 *   seelook@gmail.com                                                     *
 *                                                                         *
 *   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; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   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 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 "tqtaudioin.h"
#include "taudiobuffer.h"
#include "tpitchfinder.h"
#include <taudioparams.h>
#include <tglobals.h>

#include <QtCore/qiodevice.h>
#include <QtCore/qthread.h>
#include <QtGui/qevent.h>
#include <QtMultimedia/qaudioinput.h>
#include <QtWidgets/qapplication.h>

#include <QtCore/qdebug.h>

#define TOUCH_PAUSE (1000)

/*static */
QStringList TaudioIN::getAudioDevicesList()
{
    QStringList devNamesList;
    QList<QAudioDeviceInfo> devList = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
    for (int i = 0; i < devList.size(); ++i)
        devNamesList << devList[i].deviceName();
    return devNamesList;
}

TaudioIN *TaudioIN::m_instance = nullptr;
QString TaudioIN::m_deviceName = QStringLiteral("anything");

TaudioIN::TaudioIN(TaudioParams *params, QObject *parent)
    : TcommonListener(params, parent)
    , m_audioParams(params)
    , m_audioIN(nullptr)
    , m_inBuffer(nullptr)
{
    if (m_instance) {
        qDebug() << "Nothing of this kind... TaudioIN already exist!";
        return;
    }
    m_instance = this;
    m_inBuffer = new TaudioBuffer(this);

    m_touchHandler = new TtouchHandler(this);

    createInputDevice();
}

TaudioIN::~TaudioIN()
{
    stopListening();
    delete m_touchHandler;
    if (m_audioIN) {