void alSourcef(ALuint source, ALenum param, ALfloat value) { DEBUGLOGCALL(LCF_OPENAL); AudioSource* as = audiocontext.getSource(source); if (as == nullptr) { ALSETERROR(AL_INVALID_NAME); return; } AudioBuffer* ab; switch(param) { case AL_GAIN: as->volume = value; debuglog(LCF_OPENAL, " Set 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]; debuglog(LCF_OPENAL, " Set position of ", value, " seconds"); value *= (ALfloat) ab->frequency; as->setPosition((int)value); } break; case AL_SAMPLE_OFFSET: /* We fetch the buffer format of the source. * Normally, all buffers from a queue share the exact same format. */ debuglog(LCF_OPENAL, " Set position of ", value, " samples"); as->setPosition((int)value); break; case AL_BYTE_OFFSET: if (! as->buffer_queue.empty()) { ab = as->buffer_queue[0]; value /= (ALfloat) ab->alignSize; debuglog(LCF_OPENAL, " Set position of ", value, " bytes"); as->setPosition((int)value); } break; default: ALSETERROR(AL_INVALID_OPERATION); return; } }
void alSourcePlay(ALuint source) { DEBUGLOGCALL(LCF_OPENAL); AudioSource* as = audiocontext.getSource(source); if (as == nullptr) return; if (as->state == SOURCE_PLAYING) { /* Restart the play from the beginning */ as->setPosition(0); } as->state = SOURCE_PLAYING; }
void alSourceRewind(ALuint source) { DEBUGLOGCALL(LCF_OPENAL); AudioSource* as = audiocontext.getSource(source); if (as == nullptr) return; if (as->state == SOURCE_INITIAL) { /* Illegal operation. */ return; } as->setPosition(0); as->state = SOURCE_INITIAL; }