void AudioSource::resume() { alSourcePlay(m_sourceID); #if NORI_DEBUG checkAL("Failed to resume source"); #endif }
void AudioSource::start() { alSourcePlay(m_sourceID); #if NORI_DEBUG checkAL("Failed to start source"); #endif }
void AudioSource::pause() { alSourcePause(m_sourceID); #if NORI_DEBUG checkAL("Failed to pause source"); #endif }
void AudioSource::stop() { alSourceStop(m_sourceID); #if NORI_DEBUG checkAL("Failed to stop source"); #endif }
bool AudioSource::init() { alGenSources(1, &m_sourceID); if (!checkAL("Error during audio buffer creation")) return false; return true; }
void Context::setListenerPosition(const vec3& newPosition) { if (listenerPosition != newPosition) { listenerPosition = newPosition; alListenerfv(AL_POSITION, value_ptr(listenerPosition)); #if WENDY_DEBUG checkAL("Failed to set listener position"); #endif } }
void AudioSource::setPosition(const vec3& newPosition) { if (m_position != newPosition) { m_position = newPosition; alSourcefv(m_sourceID, AL_POSITION, value_ptr(m_position)); #if NORI_DEBUG checkAL("Failed to set source position"); #endif } }
void AudioSource::setLooping(bool newState) { if (m_looping != newState) { m_looping = newState; alSourcei(m_sourceID, AL_LOOPING, m_looping); #if NORI_DEBUG checkAL("Failed to set source looping state"); #endif } }
void Context::setListenerVelocity(const vec3& newVelocity) { if (listenerVelocity != newVelocity) { listenerVelocity = newVelocity; alListenerfv(AL_VELOCITY, value_ptr(listenerVelocity)); #if WENDY_DEBUG checkAL("Failed to set listener velocity"); #endif } }
void AudioSource::setPitch(float newPitch) { if (m_pitch != newPitch) { m_pitch = newPitch; alSourcefv(m_sourceID, AL_PITCH, &m_pitch); #if NORI_DEBUG checkAL("Failed to set source pitch"); #endif } }
void AudioSource::setVelocity(const vec3& newVelocity) { if (m_velocity != newVelocity) { m_velocity = newVelocity; alSourcefv(m_sourceID, AL_VELOCITY, value_ptr(m_velocity)); #if NORI_DEBUG checkAL("Failed to set source velocity"); #endif } }
void Context::setListenerGain(float newGain) { if (listenerGain != newGain) { listenerGain = newGain; alListenerfv(AL_GAIN, &listenerGain); #if WENDY_DEBUG checkAL("Failed to set listener gain"); #endif } }
void AudioSource::setGain(float newGain) { if (m_gain != newGain) { m_gain = newGain; alSourcefv(m_sourceID, AL_GAIN, &m_gain); #if NORI_DEBUG checkAL("Failed to set source gain"); #endif } }
void AudioContext::setListenerGain(float newGain) { if (m_listenerGain != newGain) { m_listenerGain = newGain; alListenerfv(AL_GAIN, &m_listenerGain); #if NORI_DEBUG checkAL("Failed to set listener gain"); #endif } }
void AudioContext::setListenerPosition(const vec3& newPosition) { if (m_listenerPosition != newPosition) { m_listenerPosition = newPosition; alListenerfv(AL_POSITION, value_ptr(m_listenerPosition)); #if NORI_DEBUG checkAL("Failed to set listener position"); #endif } }
void AudioContext::setListenerVelocity(const vec3& newVelocity) { if (m_listenerVelocity != newVelocity) { m_listenerVelocity = newVelocity; alListenerfv(AL_VELOCITY, value_ptr(m_listenerVelocity)); #if NORI_DEBUG checkAL("Failed to set listener velocity"); #endif } }
void AudioSource::setBuffer(AudioBuffer* newBuffer) { if (m_buffer != newBuffer) { m_buffer = newBuffer; if (m_buffer) alSourcei(m_sourceID, AL_BUFFER, m_buffer->m_bufferID); else alSourcei(m_sourceID, AL_BUFFER, AL_NONE); #if NORI_DEBUG checkAL("Failed to set source buffer"); #endif } }
bool AudioBuffer::init(const Sample& data) { alGenBuffers(1, &m_bufferID); alBufferData(m_bufferID, convertToAL(data.format), data.data.data(), (ALsizei) data.data.size(), data.frequency); if (!checkAL("Error during OpenAL buffer creation")) return false; m_format = data.format; m_duration = Time(data.data.size()) / (getFormatSize(m_format) * data.frequency); return true; }
void Context::setListenerRotation(const quat& newRotation) { if (listenerRotation != newRotation) { listenerRotation = newRotation; const vec3 at = newRotation * vec3(0.f, 0.f, -1.f); const vec3 up = newRotation * vec3(0.f, 1.f, 0.f); const float orientation[] = { at.x, at.y, at.z, up.x, up.y, up.z }; alListenerfv(AL_ORIENTATION, orientation); #if WENDY_DEBUG checkAL("Failed to set listener rotation"); #endif } }
AudioSource::State AudioSource::state() const { ALenum state; alGetSourcei(m_sourceID, AL_SOURCE_STATE, &state); #if NORI_DEBUG checkAL("Failed to get source state"); #endif switch (state) { case AL_INITIAL: case AL_STOPPED: return STOPPED; case AL_PLAYING: return STARTED; case AL_PAUSED: return PAUSED; } panic("Unknown OpenAL source state %u", state); }