Пример #1
0
void Sound::replyFinished(QNetworkReply* reply) {

    // replace our byte array with the downloaded data
    QByteArray rawAudioByteArray = reply->readAll();

    // foreach(QByteArray b, reply->rawHeaderList())
    //     qDebug() << b.constData() << ": " << reply->rawHeader(b).constData();

    if (reply->hasRawHeader("Content-Type")) {

        QByteArray headerContentType = reply->rawHeader("Content-Type");

        // WAV audio file encountered
        if (headerContentType == "audio/x-wav"
            || headerContentType == "audio/wav"
            || headerContentType == "audio/wave") {

            QByteArray outputAudioByteArray;

            interpretAsWav(rawAudioByteArray, outputAudioByteArray);
            downSample(outputAudioByteArray);
        } else {
            //  Process as RAW file
            downSample(rawAudioByteArray);
        }
    } else {
        qDebug() << "Network reply without 'Content-Type'.";
    }
}
Пример #2
0
void Sound::downloadFinished(const QByteArray& data) {
    // replace our byte array with the downloaded data
    QByteArray rawAudioByteArray = QByteArray(data);
    QString fileName = getURL().fileName().toLower();

    static const QString WAV_EXTENSION = ".wav";
    static const QString RAW_EXTENSION = ".raw";
    if (fileName.endsWith(WAV_EXTENSION)) {

        QByteArray outputAudioByteArray;

        interpretAsWav(rawAudioByteArray, outputAudioByteArray);
        downSample(outputAudioByteArray);
    } else if (fileName.endsWith(RAW_EXTENSION)) {
        // check if this was a stereo raw file
        // since it's raw the only way for us to know that is if the file was called .stereo.raw
        if (fileName.toLower().endsWith("stereo.raw")) {
            _isStereo = true;
            qCDebug(audio) << "Processing sound of" << rawAudioByteArray.size() << "bytes from" << getURL() << "as stereo audio file.";
        }

        // Process as RAW file
        downSample(rawAudioByteArray);
    } else {
        qCDebug(audio) << "Unknown sound file type";
    }

    finishedLoading(true);

    _isReady = true;
    emit ready();
}
Пример #3
0
void SoundProcessor::run() {

    qCDebug(audio) << "Processing sound file" << _url.toDisplayString();

    // replace our byte array with the downloaded data
    QByteArray rawAudioByteArray = QByteArray(_data);
    QString fileName = _url.fileName().toLower();

    static const QString WAV_EXTENSION = ".wav";
    static const QString RAW_EXTENSION = ".raw";
    if (fileName.endsWith(WAV_EXTENSION)) {

        QByteArray outputAudioByteArray;

        int sampleRate = interpretAsWav(rawAudioByteArray, outputAudioByteArray);
        if (sampleRate == 0) {
            qCDebug(audio) << "Unsupported WAV file type";
            emit onError(300, "Failed to load sound file, reason: unsupported WAV file type");
            return;
        }

        downSample(outputAudioByteArray, sampleRate);
    } else if (fileName.endsWith(RAW_EXTENSION)) {
        // check if this was a stereo raw file
        // since it's raw the only way for us to know that is if the file was called .stereo.raw
        if (fileName.toLower().endsWith("stereo.raw")) {
            _isStereo = true;
            qCDebug(audio) << "Processing sound of" << rawAudioByteArray.size() << "bytes from" << _url << "as stereo audio file.";
        }

        // Process as 48khz RAW file
        downSample(rawAudioByteArray, 48000);
    } else {
        qCDebug(audio) << "Unknown sound file type";
        emit onError(300, "Failed to load sound file, reason: unknown sound file type");
        return;
    }

    emit onSuccess(_data, _isStereo, _isAmbisonic, _duration);
}
Пример #4
0
void Sound::downloadFinished(QNetworkReply* reply) {
    // replace our byte array with the downloaded data
    QByteArray rawAudioByteArray = reply->readAll();

    if (reply->hasRawHeader("Content-Type")) {

        QByteArray headerContentType = reply->rawHeader("Content-Type");

        // WAV audio file encountered
        if (headerContentType == "audio/x-wav"
            || headerContentType == "audio/wav"
            || headerContentType == "audio/wave") {

            QByteArray outputAudioByteArray;

            interpretAsWav(rawAudioByteArray, outputAudioByteArray);
            downSample(outputAudioByteArray);
        } else {
            // check if this was a stereo raw file
            // since it's raw the only way for us to know that is if the file was called .stereo.raw
            if (reply->url().fileName().toLower().endsWith("stereo.raw")) {
                _isStereo = true;
                qCDebug(audio) << "Processing sound of" << rawAudioByteArray.size() << "bytes from" << reply->url() << "as stereo audio file.";
            }
            
            // Process as RAW file
            downSample(rawAudioByteArray);
        }
        trimFrames();
    } else {
        qCDebug(audio) << "Network reply without 'Content-Type'.";
    }
    
    _isReady = true;
    reply->deleteLater();
}