Exemplo n.º 1
0
// Called in loading thread
// Essentially a second ctor, doesn't need locks (?)
void QSample::load()
{
    Q_ASSERT(QThread::currentThread()->objectName() == "QSampleCache::LoadingThread");
#ifdef QT_SAMPLECACHE_DEBUG
    qDebug() << "QSample: load [" << m_url << "]";
#endif
    m_stream = m_parent->networkAccessManager().get(QNetworkRequest(m_url));
    connect(m_stream, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(decoderError()));
    m_waveDecoder = new QWaveDecoder(m_stream);
    connect(m_waveDecoder, SIGNAL(formatKnown()), SLOT(decoderReady()));
    connect(m_waveDecoder, SIGNAL(invalidFormat()), SLOT(decoderError()));
    connect(m_waveDecoder, SIGNAL(readyRead()), SLOT(readSample()));
}
Exemplo n.º 2
0
void QSoundEffectPrivate::setSource(const QUrl &url)
{
#ifdef QT_QAUDIO_DEBUG
    qDebug() << this << "setSource current=" << d->m_url << ", to=" << url;
#endif
    Q_ASSERT(d->m_url != url);

    stop();

    d->m_url = url;

    d->m_sampleReady = false;

    if (url.isEmpty()) {
        setStatus(QSoundEffect::Null);
        return;
    }

    if (!url.isValid()) {
        setStatus(QSoundEffect::Error);
        return;
    }

    if (d->m_sample) {
        if (!d->m_sampleReady) {
            disconnect(d->m_sample, SIGNAL(error()), d, SLOT(decoderError()));
            disconnect(d->m_sample, SIGNAL(ready()), d, SLOT(sampleReady()));
        }
        d->m_sample->release();
        d->m_sample = 0;
    }

    setStatus(QSoundEffect::Loading);
    d->m_sample = sampleCache()->requestSample(url);
    connect(d->m_sample, SIGNAL(error()), d, SLOT(decoderError()));
    connect(d->m_sample, SIGNAL(ready()), d, SLOT(sampleReady()));

    switch (d->m_sample->state()) {
    case QSample::Ready:
        d->sampleReady();
        break;
    case QSample::Error:
        d->decoderError();
        break;
    default:
        break;
    }
}
Exemplo n.º 3
0
void QSoundEffectPrivate::loadSample()
{
    m_sampleLoaded = false;
    m_dataUploaded = 0;
    m_waveDecoder = new WaveDecoder(m_stream);
    connect(m_waveDecoder, SIGNAL(formatKnown()), SLOT(decoderReady()));
    connect(m_waveDecoder, SIGNAL(invalidFormat()), SLOT(decoderError()));
}
Exemplo n.º 4
0
void PrivateSoundSource::decoderError()
{
    qWarning("QSoundEffect(qaudio): Error decoding source");
    disconnect(m_sample, SIGNAL(ready()), this, SLOT(sampleReady()));
    disconnect(m_sample, SIGNAL(error()), this, SLOT(decoderError()));
    m_playing = false;
    soundeffect->setStatus(QSoundEffect::Error);
}
Exemplo n.º 5
0
void PrivateSoundSource::sampleReady()
{
    if (m_status == QSoundEffect::Error)
        return;

#ifdef QT_QAUDIO_DEBUG
    qDebug() << this << "sampleReady "<<m_playing;
#endif
    disconnect(m_sample, SIGNAL(error()), this, SLOT(decoderError()));
    disconnect(m_sample, SIGNAL(ready()), this, SLOT(sampleReady()));
    if (!m_audioOutput) {
        m_audioOutput = new QAudioOutput(m_sample->format());
        connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)), this, SLOT(stateChanged(QAudio::State)));
        if (!m_muted)
            m_audioOutput->setVolume(m_volume/100.0f);
        else
            m_audioOutput->setVolume(0);
    }
    m_sampleReady = true;
    soundeffect->setStatus(QSoundEffect::Ready);

    if (m_playing)
        m_audioOutput->start(this);
}