Ejemplo n.º 1
0
AudioNotifier::AudioNotifier(QObject *parent)
{
    QAudioDeviceInfo info = QAudioDeviceInfo::defaultOutputDevice();
    // Set up the format, eg.
    format = info.preferredFormat();
    format.setCodec("audio/pcm");
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    format.setChannelCount(2);
#else
    format.setChannels(2);
#endif
    format.setSampleRate(44100);
    format.setSampleSize(16);
    format.setByteOrder(QAudioFormat::LittleEndian);
    format.setSampleType(QAudioFormat::SignedInt);

    if (!info.isFormatSupported(format)) {
        WARNING(tr("Audio format not supported by backend. Trying nearest format."));
        format = info.nearestFormat(format);
    }

    audioOutput = new QAudioOutput(format, this);
    connect(audioOutput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(audioStateChanged(QAudio::State)));
    if(audioOutput->error() != QAudio::NoError)
    {
        WARNING(tr("Error while creating audio output. Code: ") + QString::number(audioOutput->error()) + tr(" Device: ") + info.deviceName());
    }
}
Ejemplo n.º 2
0
void Engine::startRecording()
{
    if (m_audioInput) {
        if (QAudio::AudioInput == m_mode &&
            QAudio::SuspendedState == m_state) {
            m_audioInput->resume();
        } else {
            m_spectrumAnalyser.cancelCalculation();
            spectrumChanged(0, 0, FrequencySpectrum());

            m_buffer.fill(0);
            setRecordPosition(0, true);
            stopPlayback();
            m_mode = QAudio::AudioInput;
            CHECKED_CONNECT(m_audioInput, SIGNAL(stateChanged(QAudio::State)),
                            this, SLOT(audioStateChanged(QAudio::State)));
            CHECKED_CONNECT(m_audioInput, SIGNAL(notify()),
                            this, SLOT(audioNotify()));
            m_count = 0;
            m_dataLength = 0;
            emit dataLengthChanged(0);
            m_audioInputIODevice = m_audioInput->start();
            CHECKED_CONNECT(m_audioInputIODevice, SIGNAL(readyRead()),
                            this, SLOT(audioDataReady()));
        }
    }
}
Ejemplo n.º 3
0
/*!
    \internal
*/
void QBluetoothHeadsetService::scoStateChanged(QBluetoothAbstractSocket::SocketState socketState)
{
    switch (socketState) {
        case QBluetoothAbstractSocket::ConnectingState:
            break;
        case QBluetoothAbstractSocket::ConnectedState:
            // This is gonna be ugly...
            m_data->m_scofd = dup(m_data->m_scoSocket->socketDescriptor());
            ::fcntl(m_data->m_scofd, F_SETFD, FD_CLOEXEC);

            delete m_data->m_scoSocket;
            m_data->m_scoSocket = 0;

            if (m_data->m_audioDev)
                bt_sco_set_fd(m_data->m_audioDev, m_data->m_scofd);
            m_data->m_interface->setValue("AudioEnabled", true);
            emit audioStateChanged();
            break;
        case QBluetoothAbstractSocket::ClosingState:
            break;
        case QBluetoothAbstractSocket::UnconnectedState:
            // This happens on a failed connect
            if (m_data->m_scoSocket) {
                m_data->m_scoSocket->deleteLater();
                m_data->m_scoSocket = 0;
            }

            break;
        default:
            break;
    };
}
Ejemplo n.º 4
0
void Engine::startPlayback()
{
    if (m_audioOutput) {
        if (QAudio::AudioOutput == m_mode &&
                QAudio::SuspendedState == m_state) {
            m_audioOutput->resume();
        } else {
            m_spectrumAnalyser.cancelCalculation();
            spectrumChanged(0, 0, FrequencySpectrum());
            setPlayPosition(0, true);
            m_mode = QAudio::AudioOutput;
            CHECKED_CONNECT(m_audioOutput, SIGNAL(stateChanged(QAudio::State)),
                            this, SLOT(audioStateChanged(QAudio::State)));
            CHECKED_CONNECT(m_audioOutput, SIGNAL(notify()),
                            this, SLOT(audioNotify()));
            m_count = 0;
            if (m_file) {
                m_file->seek(0);
                m_bufferPosition = 0;
                m_dataLength = 0;
                m_audioOutput->start(m_file);
            } else {
                m_audioOutputIODevice.close();
                m_audioOutputIODevice.setBuffer(&m_buffer);
                m_audioOutputIODevice.open(QIODevice::ReadOnly);
                m_audioOutput->start(&m_audioOutputIODevice);
            }
        }
    }
}
Ejemplo n.º 5
0
/*!
    Constructs a new Headset Interface group.  The audio
    device to use is given by \a audioDev.  The implementation
    object is given by \a parent.
*/
QBluetoothHeadsetCommInterface::QBluetoothHeadsetCommInterface(const QByteArray &audioDev, QBluetoothHeadsetService *parent)
    : QAbstractIpcInterfaceGroup(parent->name(), parent),
      m_data(new QBluetoothHeadsetCommInterfacePrivate)
{
    m_data->m_service = parent;
    m_data->m_gatewayServer = new QBluetoothHeadsetAudioGatewayServer(this, audioDev,
            parent->name());

    QObject::connect(parent, SIGNAL(connectResult(bool,QString)),
                     SIGNAL(connectResult(bool,QString)));
    QObject::connect(parent, SIGNAL(newConnection(QBluetoothAddress)),
                     SIGNAL(newConnection(QBluetoothAddress)));
    QObject::connect(parent, SIGNAL(disconnected()),
                     SIGNAL(disconnected()));
    QObject::connect(parent, SIGNAL(speakerVolumeChanged()),
                     SIGNAL(speakerVolumeChanged()));
    QObject::connect(parent, SIGNAL(microphoneVolumeChanged()),
                     SIGNAL(microphoneVolumeChanged()));
    QObject::connect(parent, SIGNAL(audioStateChanged()),
                     SIGNAL(audioStateChanged()));
}
Ejemplo n.º 6
0
bool Lockin2::start(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format)
{
    if (_audioInput != 0) {
        qDebug() << __FUNCTION__ << ": lockin is already running, please stop is before start";
        return false;
    }

    if (!format.isValid()) {
        qDebug() << __FUNCTION__ << ": format not valid";
        return false;
    }

    if (!isFormatSupported(format)) {
        qDebug() << __FUNCTION__ << ": format not supported for lockin2";
        return false;
    }

    if (audioDevice.isFormatSupported(format)) {
        _audioInput = new QAudioInput(audioDevice, format, this);
        _audioInput->setNotifyInterval(_outputPeriod * 1000.0);

        connect(_audioInput, SIGNAL(notify()), this, SLOT(interpretInput()));
        connect(_audioInput, SIGNAL(stateChanged(QAudio::State)), this, SLOT(audioStateChanged(QAudio::State)));

        // pour être au millieu avec le temps
        _timeValue = -(_integrationTime / 2.0);

        // nombre d'échantillons pour le temps d'integration
        _sampleIntegration = format.sampleRate() * _integrationTime;

        // nombre d'échantillons pour un affichage de vumeter
        _sampleVumeter = _vumeterTime * format.sampleRate();

        // nettoyage des variables
        _fifo->readAll(); // vide le fifo
        _dataXY.clear(); // vide <x,y>

        _format = format;

        _audioInput->start(_fifo);
    } else {
        qDebug() << __FUNCTION__ << ": format not supported, can't start";
        return false;
    }


    return true;
}
Ejemplo n.º 7
0
void StreamOutputWidget::startButtonClicked()
{
    qDebug("void StreamOutputWidget::startButtonClicked()");

    //Get available output devices...
    QList<QAudioDeviceInfo>	myList = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);

    if (m_audioOutput)
    {
        delete m_audioOutput;
        m_audioOutput = NULL;
    }
    for (int i =0; i < myList.size(); i++)
    {
        if (myList[i].deviceName() == m_ui.m_comboDeviceSelection->currentText())
        {
            //QAudioFormat
            QAudioFormat format;

            //Set up the format
            format.setFrequency(48000);
            format.setChannels(1);
            format.setSampleSize(16);
            format.setCodec("audio/pcm");
            format.setByteOrder(QAudioFormat::LittleEndian);
            format.setSampleType(QAudioFormat::SignedInt);
            m_audioOutput = new QAudioOutput(myList[i],format,this);
	    //m_audioOutput = new QAudioOutput(QAudioDeviceInfo::defaultOutputDevice(),format,this);

            //We have 10ms frames, this should be enough
            m_audioOutput->setNotifyInterval(5);

        }
    }

    if (m_audioOutput)
    {
        connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)),this,SLOT(audioStateChanged(QAudio::State)));
        connect(m_audioOutput,SIGNAL(notify()),this,SLOT(notify()));
        m_audioOutput->setBufferSize(1000000);
        m_IODevice = m_audioOutput->start();
        m_ui.m_controlTextEdit->append("Starting stream... \n");
        m_ui.m_startButton->setEnabled(false);
        m_ui.m_stopButton->setEnabled(true);
    }
}
Ejemplo n.º 8
0
/*!
    This method is the concrete implementation of the
    QBluetoothAudioGateway interface method of the same name.
    It is called from the QBluetoothHandsfreeAudioGatewayServer
    class, which acts as a forwarding agent.

    \sa QBluetoothHandsfreeAudioGatewayServer
*/
void QBluetoothHeadsetService::releaseAudio()
{
    if (m_data->m_scoSocket) {
        delete m_data->m_scoSocket;
        m_data->m_scoSocket = 0;
    }

    if (m_data->m_scofd == -1)
        return;

    if (m_data->m_audioDev)
        bt_sco_set_fd(m_data->m_audioDev, -1);
    ::close(m_data->m_scofd);
    m_data->m_scofd = -1;

    m_data->m_interface->setValue("AudioEnabled", false);
    emit audioStateChanged();
}
Ejemplo n.º 9
0
void Engine::startPlayback()
{
    if (m_audioOutput) {
        if (QAudio::AudioOutput == m_mode &&
            QAudio::SuspendedState == m_state) {
#ifdef Q_OS_WIN
            // The Windows backend seems to internally go back into ActiveState
            // while still returning SuspendedState, so to ensure that it doesn't
            // ignore the resume() call, we first re-suspend
            m_audioOutput->suspend();
#endif
            m_audioOutput->resume();
        } else {
            m_spectrumAnalyser.cancelCalculation();
            spectrumChanged(0, 0, FrequencySpectrum());
            setPlayPosition(0, true);
            stopRecording();
            m_mode = QAudio::AudioOutput;
            CHECKED_CONNECT(m_audioOutput, SIGNAL(stateChanged(QAudio::State)),
                            this, SLOT(audioStateChanged(QAudio::State)));
            CHECKED_CONNECT(m_audioOutput, SIGNAL(notify()),
                            this, SLOT(audioNotify()));
            m_count = 0;
            if (m_file) {
                m_file->seek(0);
                m_bufferPosition = 0;
                m_dataLength = 0;
                m_audioOutput->start(m_file);
            } else {
                m_audioOutputIODevice.close();
                m_audioOutputIODevice.setBuffer(&m_buffer);
                m_audioOutputIODevice.open(QIODevice::ReadOnly);
                m_audioOutput->start(&m_audioOutputIODevice);
            }
        }
    }
}
Ejemplo n.º 10
0
void AudioPlayer::load(QVariantMap &d)
{
    QMap<QString, QVariant>::const_iterator i = d.constBegin();
    while (i != d.constEnd())
    {
        playerData[i.key()] = i.value();
        ++i;
    }

    update_status(Common::audioStatusFromString(playerData["status"].toString()));
    update_id(playerData["id"].toString());
    update_cover(playerData["cover_url"].toString());
    update_name(playerData["name"].toString());
    update_volume(playerData["volume"].toDouble());

    qDebug() << "New player loaded: " << get_name();

    QVariantMap currentTrack = playerData["current_track"].toMap();
    update_title(currentTrack["title"].toString());
    update_album(currentTrack["album"].toString());
    update_artist(currentTrack["artist"].toString());

    connect(connection, SIGNAL(eventAudioChange(QString)),
            this, SLOT(audioChanged(QString)));
    connect(connection, SIGNAL(eventAudioStateChange(QVariantMap)),
            this, SLOT(audioStateChanged(QVariantMap)));
    connect(connection, SIGNAL(eventAudioStatusChange(QString,QString)),
            this, SLOT(audioStatusChanged(QString,QString)));
    connect(connection, SIGNAL(eventAudioVolumeChange(QString,double)),
            this, SLOT(audioVolumeChanged(QString,double)));

    if (!loaded)
    {
        loaded = true;
        audioChanged(get_id());
    }
}
Ejemplo n.º 11
0
void AudioPlayer::slotAudioStateChanged(AudioState newState)
{
    emit audioStateChanged(newState);
    if (newState == AudioState::Stopped)
        emit stopped(audioOutput_->totalTime(), audioOutput_->currentTime());
}
Ejemplo n.º 12
0
MainWindow::MainWindow(AudioPlayer &player, QWidget *parent)
    : QMainWindow(parent),
      statusBar_(this),
      player_(player),
      cursorFollowsPlayback_(false),
      saveTabs_(false) {
    setupUi(this);
    // Not saving a pointer to this
    QActionGroup *playbackOrderGroup = new QActionGroup(this);
    playbackOrderGroup->addAction(defaultAction);
    playbackOrderGroup->addAction(randomAction);
    playbackOrderGroup->addAction(repeatTrackAction);
    playbackOrderGroup->addAction(repeatPlaylistAction);
    installEventFilter(this);

    player.setMainWindow(this);

    QObject::connect(&player_, SIGNAL(playbackOrderChanged(PlaybackOrder)), this,
                     SLOT(playbackOrderChanged(PlaybackOrder)));
    QObject::connect(&player_, SIGNAL(audioStateChanged(AudioState)), this,
                     SLOT(slotAudioStateChanged(AudioState)));
    QObject::connect(&player_, SIGNAL(trackPlaying(PTrack)), this, SLOT(updateUI(PTrack)));
    playbackOrderChanged(player.playbackOrder());

    QObject::connect(&player_, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
    seekSlider_ = new SeekSlider(player_, this);
    volumeSlider_ = new QSlider(this);
    volumeSlider_->setOrientation(Qt::Horizontal);
    volumeSlider_->setMaximum(100);
    volumeSlider_->setMinimum(0);
    volumeSlider_->setValue(player_.volume() * 100);
    volumeSlider_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
    QObject::connect(volumeSlider_, SIGNAL(valueChanged(int)), this, SLOT(volumeChanged(int)));
    mainToolBar->addWidget(seekSlider_);
    mainToolBar->addWidget(volumeSlider_);

    trayIcon_ = new QSystemTrayIcon(this);
    setTrayIcon(false);
    connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
            SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
    trayIcon_->show();

    setStatusBar(&statusBar_);
    QObject::connect(&statusBar_, SIGNAL(statusBarDoubleClicked()), this,
                     SLOT(statusBarDoubleClicked()));

    lyricsDock_ = new QDockWidget("Lyrics", this);
    // Not setting an object name because we don't want save its state
    // since Qt doesn't restore it correctly
    //     lyricsDock_->setObjectName("LyricsDock");
    lyricsWidget_ = new QPlainTextEdit(lyricsDock_);
    //     lyricsWidget_->setObjectName("LyricsWidget");
    lyricsWidget_->setReadOnly(true);
    lyricsDock_->setWidget(lyricsWidget_);
    QObject::connect(lyricsDock_, SIGNAL(visibilityChanged(bool)), this,
                     SLOT(dockVisibilityChanged(bool)));

    //     playlistTabs->setTabsClosable(true);
    QObject::connect(playlistTabs, SIGNAL(tabCloseRequested(int)), this,
                     SLOT(removePlaylistTab(int)));
    QObject::connect(playlistTabs, SIGNAL(newTabRequested()), this, SLOT(newTabRequested()));

    QObject::connect(menu_File, SIGNAL(aboutToShow()), this, SLOT(menuFileAboutToShow()));

    setWindowIcon(QIcon(":/icon/logo22.png"));

    instance = this;

    console_ = new ConsoleWindow(this);
    QObject::connect(console_, SIGNAL(visibilityChanged(bool)), this,
                     SLOT(consoleVisibilityChanged(bool)));

    readSettings();

    config_.set("mainwindow.save_tabs", QVariant(saveTabs_));
    QObject::connect(&config_, SIGNAL(keySet(QString, QVariant)), this,
                     SLOT(configChanged(QString, QVariant)));

    setShortcuts();
}