void RtpAudioStream::startPlaying()
{
    if (audio_output_) return;

    QAudioFormat format;
    format.setSampleRate(audio_out_rate_);
    format.setSampleSize(sample_bytes_ * 8); // bits
    format.setSampleType(QAudioFormat::SignedInt);
    format.setChannelCount(1);
    format.setCodec("audio/pcm");

    // RTP_STREAM_DEBUG("playing %s %d samples @ %u Hz",
    //                 tempfile_->fileName().toUtf8().constData(),
    //                 (int) tempfile_->size(), audio_out_rate_);

    audio_output_ = new QAudioOutput(format, this);
    audio_output_->setNotifyInterval(65); // ~15 fps
    connect(audio_output_, SIGNAL(stateChanged(QAudio::State)), this, SLOT(outputStateChanged()));
    connect(audio_output_, SIGNAL(notify()), this, SLOT(outputNotify()));
    tempfile_->seek(0);
    audio_output_->start(tempfile_);
    emit startedPlaying();
    // QTBUG-6548 StoppedState is not always emitted on error, force a cleanup
    // in case playback fails immediately.
    if (audio_output_ && audio_output_->state() == QAudio::StoppedState) {
        outputStateChanged();
    }
}
Beispiel #2
0
void GuitarTuner::initAudioOutput()
 {
     m_format_output.setSampleRate(DataFrequencyHzOutput);
     m_format_output.setCodec("audio/pcm");
     m_format_output.setSampleSize(16);
     m_format_output.setChannelCount(1);
     m_format_output.setByteOrder(QAudioFormat::LittleEndian);
     m_format_output.setSampleType(QAudioFormat::SignedInt);

     QAudioDeviceInfo outputDeviceInfo(
                 QAudioDeviceInfo::defaultOutputDevice());
     if (!outputDeviceInfo.isFormatSupported(m_format_output)) {
         m_format_output = outputDeviceInfo.nearestFormat(m_format_output);
     }

     m_audioOutput = new QAudioOutput(outputDeviceInfo,
                                      m_format_output, this);
     m_voicegenerator = new VoiceGenerator(m_format_output,
                                           getFrequency(),
                                           getVolume(),
                                           this);

     connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)),
             SLOT(outputStateChanged(QAudio::State)));
 }
Beispiel #3
0
/**
  * Inits audio output.
  */
void GuitarTuner::initAudioOutput()
{
    // Set up the output format.
    m_format_output.setFrequency(DataFrequencyHzOutput);
    m_format_output.setCodec("audio/pcm");
    m_format_output.setSampleSize(16);
    m_format_output.setChannels(1);
    m_format_output.setByteOrder(QAudioFormat::LittleEndian);
    m_format_output.setSampleType(QAudioFormat::SignedInt);

    // Obtain a default output device, and if the format is not
    // supported, find the nearest format available.
    QAudioDeviceInfo outputDeviceInfo(
                QAudioDeviceInfo::defaultOutputDevice());
    if (!outputDeviceInfo.isFormatSupported(m_format_output)) {
        m_format_output = outputDeviceInfo.nearestFormat(m_format_output);
    }

    // Create new QAudioOutput and VoiceGenerator instances, and store
    // them in m_audioOutput and m_voicegenerator, respectively.
    m_audioOutput = new QAudioOutput(outputDeviceInfo,
                                     m_format_output, this);
    m_voicegenerator = new VoiceGenerator(m_format_output,
                                          qmlObject->property("frequency").toReal(),
                                          qmlObject->property("volume").toReal(),
                                          this);

    // Connect m_audioOutput stateChanged signal to outputStateChanged.
    connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)),
            SLOT(outputStateChanged(QAudio::State)));
}
Beispiel #4
0
void AudioPlayer::play()
{
    if (!m_audio)
        return;

    if (m_state == Playing)
        stop();

    if (m_state == Stopped || m_state == Done || m_state == Playing) {
        delete m_codec;
        m_codec = 0;

        QByteArray mime = MediaLibrary::instance()->mimeType(m_filename);
        if (mime.isEmpty())
            return;

        m_artwork = QImage();
        MediaLibrary::instance()->requestArtwork(m_filename);

        Codec* codec = Codecs::instance()->createCodec(mime);
        if (!codec)
            return;

        AudioReader* reader = MediaLibrary::instance()->readerForFilename(m_filename);
        if (!reader->open(FileReader::ReadOnly)) {
            delete codec;
            delete reader;

            return;
        }

        m_audio->createOutput();
        connect(m_audio->output(), SIGNAL(stateChanged(QAudio::State)),
                this, SLOT(outputStateChanged(QAudio::State)));

        codec->init(m_audio->output()->format());

        m_codec = new CodecDevice(this);
        m_codec->setCodec(codec);
        m_codec->setInputReader(reader);

        if (!m_codec->open(CodecDevice::ReadOnly)) {
            delete m_codec;
            m_codec = 0;

            return;
        }

        m_audio->output()->setNotifyInterval(100);
        connect(m_audio->output(), SIGNAL(notify()), this, SLOT(intervalNotified()));

        m_audio->output()->start(m_codec);
    } else if (m_state == Paused) {
        m_codec->resumeReader();
        m_audio->output()->resume();
    }
}
Beispiel #5
0
AudioLayer::AudioLayer(QQmlApplicationEngine *engine, QObject *parent):
    QObject(parent),
    m_engine(nullptr)
{
    this->m_inputState = AkElement::ElementStateNull;
    this->setQmlEngine(engine);
    this->m_pipeline = AkElement::create("Bin", "pipeline");

    if (this->m_pipeline) {
        QFile jsonFile(":/Webcamoid/share/audiopipeline.json");
        jsonFile.open(QFile::ReadOnly);
        QString description(jsonFile.readAll());
        jsonFile.close();

        this->m_pipeline->setProperty("description", description);

        QMetaObject::invokeMethod(this->m_pipeline.data(),
                                  "element",
                                  Q_RETURN_ARG(AkElementPtr, this->m_audioOut),
                                  Q_ARG(QString, "audioOut"));
        QMetaObject::invokeMethod(this->m_pipeline.data(),
                                  "element",
                                  Q_RETURN_ARG(AkElementPtr, this->m_audioIn),
                                  Q_ARG(QString, "audioIn"));
        QMetaObject::invokeMethod(this->m_pipeline.data(),
                                  "element",
                                  Q_RETURN_ARG(AkElementPtr, this->m_audioGenerator),
                                  Q_ARG(QString, "audioGenerator"));
        QMetaObject::invokeMethod(this->m_pipeline.data(),
                                  "element",
                                  Q_RETURN_ARG(AkElementPtr, this->m_audioSwitch),
                                  Q_ARG(QString, "audioSwitch"));
    }

    if (this->m_audioOut) {
        QString device = this->m_audioOut->property("defaultOutput").toString();
        this->m_audioOut->setProperty("device", device);
        this->m_outputDeviceCaps = this->m_audioOut->property("caps").value<AkCaps>();

        QObject::connect(this->m_audioOut.data(),
                         SIGNAL(deviceChanged(const QString &)),
                         this,
                         SIGNAL(audioOutputChanged(const QString &)));
        QObject::connect(this->m_audioOut.data(),
                         SIGNAL(capsChanged(const AkCaps &)),
                         this,
                         SLOT(setOutputDeviceCaps(const AkCaps &)));
        QObject::connect(this->m_audioOut.data(),
                         SIGNAL(outputsChanged(const QStringList &)),
                         this,
                         SIGNAL(outputsChanged(const QStringList &)));
        QObject::connect(this->m_audioOut.data(),
                         SIGNAL(stateChanged(AkElement::ElementState)),
                         this,
                         SIGNAL(outputStateChanged(AkElement::ElementState)));
    }