コード例 #1
0
ファイル: openal.cpp プロジェクト: SebastienBenazet/libTAS
void alGetSourcef(ALuint source, ALenum param, ALfloat *value)
{
    DEBUGLOGCALL(LCF_OPENAL);

    if (value == nullptr) {
        return;
    }
        
    AudioSource* as = audiocontext.getSource(source);
    if (as == nullptr)
        return;

    AudioBuffer* ab;
    switch(param) {
        case AL_GAIN:
            *value = as->volume;
            debuglog(LCF_OPENAL, "  Get gain of ", *value);
            break;
        case AL_PITCH:
        case AL_MIN_GAIN:
        case AL_MAX_GAIN:
        case AL_MAX_DISTANCE:
        case AL_ROLLOFF_FACTOR:
        case AL_CONE_OUTER_GAIN:
        case AL_CONE_INNER_ANGLE:
        case AL_CONE_OUTER_ANGLE:
        case AL_REFERENCE_DISTANCE:
            debuglog(LCF_OPENAL, "Operation not supported");
            break;
        case AL_SEC_OFFSET:
            /* We fetch the buffer format of the source.
             * Normally, all buffers from a queue share the exact same format.
             */
            if (! as->buffer_queue.empty()) {
                ab = as->buffer_queue[0];
                ALfloat pos = (ALfloat) as->getPosition();
                pos /= (ALfloat) ab->frequency;
                *value = pos;
                debuglog(LCF_OPENAL, "  Get position of ", *value, " seconds");
            }
            break;
        case AL_SAMPLE_OFFSET:
            *value = (ALfloat) as->getPosition();
            debuglog(LCF_OPENAL, "  Get position of ", *value, " samples");
            break;
        case AL_BYTE_OFFSET:
            /* We fetch the buffer format of the source.
             * Normally, all buffers from a queue share the exact same format.
             */
            if (! as->buffer_queue.empty()) {
                ab = as->buffer_queue[0];
                ALfloat pos = (ALfloat) as->getPosition();
                pos *= (ALfloat) ab->alignSize;
                *value = pos;
                debuglog(LCF_OPENAL, "  Get position of ", *value, " bytes");
            }
            break;
        default:
            ALSETERROR(AL_INVALID_OPERATION);
            return;
    }
}