Beispiel #1
0
OpenAL::~OpenAL()
{
    audioThread->exit();
    audioThread->wait();
    cleanupInput();
    cleanupOutput();
}
Beispiel #2
0
void OpenAL::unsubscribeOutput(uint& sid)
{
    QMutexLocker locker(&audioLock);

    outSources.removeAll(sid);

    if (sid) {
        if (alIsSource(sid)) {
            // stop playing, marks all buffers as processed
            alSourceStop(sid);
            // unqueue all buffers from the source
            ALint processed = 0;
            alGetSourcei(sid, AL_BUFFERS_PROCESSED, &processed);
            ALuint* bufids = new ALuint[processed];
            alSourceUnqueueBuffers(sid, processed, bufids);
            // delete all buffers
            alDeleteBuffers(processed, bufids);
            delete[] bufids;
            alDeleteSources(1, &sid);
            qDebug() << "Audio source" << sid << "deleted. Sources active:" << outSources.size();
        } else {
            qWarning() << "Trying to delete invalid audio source" << sid;
        }

        sid = 0;
    }

    if (outSources.isEmpty())
        cleanupOutput();
}
Beispiel #3
0
Audio::~Audio()
{
    audioThread->exit();
    audioThread->wait();
    cleanupInput();
    cleanupOutput();
    delete d;
}
Beispiel #4
0
    ~AudioPrivate()
    {
        if (audioMeter)
            audioMeter->stop();

        audioThread->exit();
        audioThread->wait();
        cleanupInput();
        cleanupOutput();
    }
Beispiel #5
0
/**
@internal

Open an audio output device
*/
bool AudioPrivate::initOutput(QString outDevDescr)
{
    qDebug() << "Opening audio output" << outDevDescr;
    outSources.clear();

    outputInitialized = false;
    if (outDevDescr == "none")
        return true;

    assert(!alOutDev);

    if (outDevDescr.isEmpty()) {
        // default to the first available audio device.
        const ALchar *pDeviceList = Audio::outDeviceNames();
        if (pDeviceList)
            outDevDescr = QString::fromUtf8(pDeviceList, strlen(pDeviceList));
    }

    if (!outDevDescr.isEmpty())
        alOutDev = alcOpenDevice(outDevDescr.toUtf8().constData());

    if (alOutDev)
    {
        alContext = alcCreateContext(alOutDev, nullptr);
        if (alcMakeContextCurrent(alContext))
        {
            alGenSources(1, &alMainSource);
            alSourcef(alMainSource, AL_GAIN, outputVolume);
        }
        else
        {
            qWarning() << "Cannot create output audio context";
            cleanupOutput();
            return false;
        }

        Core* core = Core::getInstance();
        if (core)
            core->getAv()->invalidateCallSources(); // Force to regen each group call's sources

        outputInitialized = true;
        return true;
    }

    qWarning() << "Cannot open output audio device" << outDevDescr;
    return false;
}
Beispiel #6
0
void Audio::unsubscribeOutput(ALuint &sid)
{
    QMutexLocker locker(&audioLock);

    outSources.removeAll(sid);

    if (sid)
    {
        if (alIsSource(sid))
        {
            alDeleteSources(1, &sid);
            qDebug() << "Audio source" << sid << "deleted. Sources active:"
                     << outSources.size();
        } else {
            qWarning() << "Trying to delete invalid audio source" << sid;
        }

        sid = 0;
    }

    if (outSources.isEmpty())
        cleanupOutput();
}
Beispiel #7
0
bool OpenAL::reinitOutput(const QString& outDevDesc)
{
    QMutexLocker locker(&audioLock);
    cleanupOutput();
    return initOutput(outDevDesc);
}