ALfloat alGetFloat( ALenum param ) { ALfloat retval = 0.0f; alGetFloatv(param, &retval); return retval; }
value lime_al_get_floatv (int param, int count) { ALfloat* values = new ALfloat[count]; alGetFloatv (param, values); value result = alloc_array (count); for (int i = 0; i < count; i++) { val_array_set_i (result, i, alloc_float (values[i])); } delete [] values; return result; }
value lime_al_get_floatv (value param, value count) { int length = val_int (count); ALfloat* values = new ALfloat[length]; alGetFloatv (val_int (param), values); value result = alloc_array (length); for (int i = 0; i < length; ++i) { val_array_set_i (result, i, alloc_float (values[i])); } return result; }
ALvoid CDECL wine_alGetFloatv(ALenum param, ALfloat* data) { alGetFloatv(param, data); }
ALUAPI ALvoid ALUAPIENTRY aluCalculateSourceParameters(ALuint source,ALuint freqOutput,ALuint numOutputChannels,ALfloat *drysend,ALfloat *wetsend,ALfloat *pitch) { ALfloat ListenerOrientation[6],ListenerPosition[3],ListenerVelocity[3]; ALfloat InnerAngle,OuterAngle,OuterGain,Angle,Distance,DryMix,WetMix; ALfloat Direction[3],Position[3],Velocity[3],SourceToListener[3]; ALfloat MinVolume,MaxVolume,MinDist,MaxDist,Rolloff; ALfloat Pitch,ConeVolume,SourceVolume,PanningFB,PanningLR,ListenerGain; ALuint NumBufferChannels; ALfloat U[3],V[3],N[3]; ALfloat DopplerFactor, DopplerVelocity, flSpeedOfSound, flMaxVelocity; ALfloat flVSS, flVLS; ALuint DistanceModel; ALfloat Matrix[3][3]; ALint HeadRelative; ALuint Buffer; ALenum Error; ALfloat flAttenuation; if (alIsSource(source)) { //Get global properties alGetFloatv(AL_DOPPLER_FACTOR,&DopplerFactor); alGetIntegerv(AL_DISTANCE_MODEL,&DistanceModel); alGetFloatv(AL_DOPPLER_VELOCITY,&DopplerVelocity); alGetFloatv(AL_SPEED_OF_SOUND,&flSpeedOfSound); //Get listener properties alGetListenerfv(AL_GAIN,&ListenerGain); alGetListenerfv(AL_POSITION,ListenerPosition); alGetListenerfv(AL_VELOCITY,ListenerVelocity); alGetListenerfv(AL_ORIENTATION,ListenerOrientation); //Get source properties alGetSourcef(source,AL_PITCH,&Pitch); alGetSourcef(source,AL_GAIN,&SourceVolume); alGetSourcei(source,AL_BUFFER,&Buffer); alGetSourcefv(source,AL_POSITION,Position); alGetSourcefv(source,AL_VELOCITY,Velocity); alGetSourcefv(source,AL_DIRECTION,Direction); alGetSourcef(source,AL_MIN_GAIN,&MinVolume); alGetSourcef(source,AL_MAX_GAIN,&MaxVolume); alGetSourcef(source,AL_REFERENCE_DISTANCE,&MinDist); alGetSourcef(source,AL_MAX_DISTANCE,&MaxDist); alGetSourcef(source,AL_ROLLOFF_FACTOR,&Rolloff); alGetSourcef(source,AL_CONE_OUTER_GAIN,&OuterGain); alGetSourcef(source,AL_CONE_INNER_ANGLE,&InnerAngle); alGetSourcef(source,AL_CONE_OUTER_ANGLE,&OuterAngle); alGetSourcei(source,AL_SOURCE_RELATIVE,&HeadRelative); //Set working variables DryMix=(ALfloat)(1.0f); WetMix=(ALfloat)(0.0f); //Get buffer properties alGetBufferi(Buffer,AL_CHANNELS,&NumBufferChannels); //Only apply 3D calculations for mono buffers if (NumBufferChannels==1) { //1. Translate Listener to origin (convert to head relative) if (HeadRelative==AL_FALSE) { Position[0]-=ListenerPosition[0]; Position[1]-=ListenerPosition[1]; Position[2]-=ListenerPosition[2]; } //2. Calculate distance attenuation Distance=(ALfloat)sqrt(aluDotproduct(Position,Position)); // Clamp to MinDist and MaxDist if appropriate if ((DistanceModel == AL_INVERSE_DISTANCE_CLAMPED) || (DistanceModel == AL_LINEAR_DISTANCE_CLAMPED) || (DistanceModel == AL_EXPONENT_DISTANCE_CLAMPED)) { Distance=(Distance<MinDist?MinDist:Distance); Distance=(Distance>MaxDist?MaxDist:Distance); } flAttenuation = 1.0f; switch (DistanceModel) { case AL_INVERSE_DISTANCE: if (MinDist > 0.0f) { if ((MinDist + (Rolloff * (Distance - MinDist))) > 0.0f) flAttenuation = MinDist / (MinDist + (Rolloff * (Distance - MinDist))); else flAttenuation = 1000000; } break; case AL_INVERSE_DISTANCE_CLAMPED: if ((MaxDist >= MinDist) && (MinDist > 0.0f)) { if ((MinDist + (Rolloff * (Distance - MinDist))) > 0.0f) flAttenuation = MinDist / (MinDist + (Rolloff * (Distance - MinDist))); else flAttenuation = 1000000; } break; case AL_LINEAR_DISTANCE: if (MaxDist != MinDist) flAttenuation = 1.0f - (Rolloff*(Distance-MinDist)/(MaxDist - MinDist)); break; case AL_LINEAR_DISTANCE_CLAMPED: if (MaxDist > MinDist) flAttenuation = 1.0f - (Rolloff*(Distance-MinDist)/(MaxDist - MinDist)); break; case AL_EXPONENT_DISTANCE: if ((Distance > 0.0f) && (MinDist > 0.0f)) flAttenuation = (ALfloat)pow(Distance/MinDist, -Rolloff); break; case AL_EXPONENT_DISTANCE_CLAMPED: if ((MaxDist >= MinDist) && (Distance > 0.0f) && (MinDist > 0.0f)) flAttenuation = (ALfloat)pow(Distance/MinDist, -Rolloff); break; case AL_NONE: default: flAttenuation = 1.0f; break; } // Source Gain + Attenuation DryMix = SourceVolume * flAttenuation; // Clamp to Min/Max Gain DryMix=__min(DryMix,MaxVolume); DryMix=__max(DryMix,MinVolume); WetMix=__min(WetMix,MaxVolume); WetMix=__max(WetMix,MinVolume); //3. Apply directional soundcones SourceToListener[0]=-Position[0]; SourceToListener[1]=-Position[1]; SourceToListener[2]=-Position[2]; aluNormalize(Direction); aluNormalize(SourceToListener); Angle=(ALfloat)(180.0*acos(aluDotproduct(Direction,SourceToListener))/3.141592654f); if ((Angle>=InnerAngle)&&(Angle<=OuterAngle)) ConeVolume=(1.0f+(OuterGain-1.0f)*(Angle-InnerAngle)/(OuterAngle-InnerAngle)); else if (Angle>OuterAngle) ConeVolume=(1.0f+(OuterGain-1.0f) ); else ConeVolume=1.0f; //4. Calculate Velocity if (DopplerFactor != 0.0f) { flVLS = aluDotproduct(ListenerVelocity, SourceToListener); flVSS = aluDotproduct(Velocity, SourceToListener); flMaxVelocity = (DopplerVelocity * flSpeedOfSound) / DopplerFactor; if (flVSS >= flMaxVelocity) flVSS = (flMaxVelocity - 1.0f); else if (flVSS <= -flMaxVelocity) flVSS = -flMaxVelocity + 1.0f; if (flVLS >= flMaxVelocity) flVLS = (flMaxVelocity - 1.0f); else if (flVLS <= -flMaxVelocity) flVLS = -flMaxVelocity + 1.0f; pitch[0] = Pitch * ((flSpeedOfSound * DopplerVelocity) - (DopplerFactor * flVLS)) / ((flSpeedOfSound * DopplerVelocity) - (DopplerFactor * flVSS)); } else { pitch[0] = Pitch; } //5. Align coordinate system axes aluCrossproduct(&ListenerOrientation[0],&ListenerOrientation[3],U); // Right-vector aluNormalize(U); // Normalized Right-vector memcpy(V,&ListenerOrientation[3],sizeof(V)); // Up-vector aluNormalize(V); // Normalized Up-vector memcpy(N,&ListenerOrientation[0],sizeof(N)); // At-vector aluNormalize(N); // Normalized At-vector Matrix[0][0]=U[0]; Matrix[0][1]=V[0]; Matrix[0][2]=-N[0]; Matrix[1][0]=U[1]; Matrix[1][1]=V[1]; Matrix[1][2]=-N[1]; Matrix[2][0]=U[2]; Matrix[2][1]=V[2]; Matrix[2][2]=-N[2]; aluMatrixVector(Position,Matrix); //6. Convert normalized position into font/back panning if (Distance != 0.0f) { aluNormalize(Position); PanningLR=(0.5f+0.5f*Position[0]); PanningFB=(0.5f+0.5f*Position[2]); } else { PanningLR=0.5f; PanningFB=0.5f; } //7. Convert front/back panning into channel volumes switch (numOutputChannels) { case 1: drysend[0]=(ConeVolume*ListenerGain*DryMix*(ALfloat)1.0f ); //Direct wetsend[0]=(ListenerGain*WetMix*(ALfloat)1.0f ); //Room break; case 2: drysend[0]=(ConeVolume*ListenerGain*DryMix*(ALfloat)sqrt((1.0f-PanningLR))); //FL Direct drysend[1]=(ConeVolume*ListenerGain*DryMix*(ALfloat)sqrt(( PanningLR))); //FR Direct wetsend[0]=( ListenerGain*WetMix*(ALfloat)sqrt((1.0f-PanningLR))); //FL Room wetsend[1]=( ListenerGain*WetMix*(ALfloat)sqrt(( PanningLR))); //FR Room break; default: break; } } else { //1. Stereo buffers always play from front left/front right switch (numOutputChannels) { case 1: drysend[0]=(SourceVolume*1.0f*ListenerGain); wetsend[0]=(SourceVolume*0.0f*ListenerGain); break; case 2: drysend[0]=(SourceVolume*1.0f*ListenerGain); drysend[1]=(SourceVolume*1.0f*ListenerGain); wetsend[0]=(SourceVolume*0.0f*ListenerGain); wetsend[1]=(SourceVolume*0.0f*ListenerGain); break; default: break; } pitch[0]=(ALfloat)(Pitch); } Error=alGetError(); } }
static int lua_alGet(lua_State* lua_state) { ALenum enum_parameter; int openal_primitive_type; enum_parameter = lua_tointeger(lua_state, 1); openal_primitive_type = lua_getTypeForEnum(enum_parameter); switch(openal_primitive_type) { case LUAOPENAL_BOOL_TYPE: { ALboolean ret_val; ret_val = alGetBoolean(enum_parameter); lua_pushboolean(lua_state, ret_val); return 1; break; } case LUAOPENAL_INT_TYPE: { ALint ret_val; ret_val = alGetInteger(enum_parameter); lua_pushinteger(lua_state, ret_val); return 1; break; } case LUAOPENAL_FLOAT_TYPE: { ALfloat ret_val; ret_val = alGetFloat(enum_parameter); lua_pushnumber(lua_state, ret_val); return 1; break; } case LUAOPENAL_INT_3_TYPE: { ALint ret_val[3]; alGetIntegerv(enum_parameter, ret_val); lua_pushinteger(lua_state, ret_val[0]); lua_pushinteger(lua_state, ret_val[1]); lua_pushinteger(lua_state, ret_val[2]); return 3; break; } case LUAOPENAL_FLOAT_3_TYPE: { ALfloat ret_val[3]; alGetFloatv(enum_parameter, ret_val); lua_pushnumber(lua_state, ret_val[0]); lua_pushnumber(lua_state, ret_val[1]); lua_pushnumber(lua_state, ret_val[2]); return 3; break; } case LUAOPENAL_FLOAT_6_TYPE: { ALfloat ret_val[6]; alGetFloatv(enum_parameter, ret_val); lua_pushnumber(lua_state, ret_val[0]); lua_pushnumber(lua_state, ret_val[1]); lua_pushnumber(lua_state, ret_val[2]); lua_pushnumber(lua_state, ret_val[3]); lua_pushnumber(lua_state, ret_val[4]); lua_pushnumber(lua_state, ret_val[5]); return 6; break; } case LUAOPENAL_STRING_TYPE: { const ALchar* ret_val; ret_val = alGetString(enum_parameter); lua_pushstring(lua_state, ret_val); return 1; break; } default: { /* TODO: Figure out how to handle OpenAL extensions. */ luaL_error(lua_state, "Unhandled parameter type for alGetSource*"); } } return 0; }
ALfloat emu_alGetFloat(ALenum param) { ALfloat alfloat; alGetFloatv(param, &alfloat); return alfloat; }
JNIEXPORT void JNICALL Java_org_lwjgl_openal_AL10_nalGetFloatv(JNIEnv *__env, jclass clazz, jint paramName, jlong destAddress, jlong __functionAddress) { ALfloat *dest = (ALfloat *)(intptr_t)destAddress; alGetFloatvPROC alGetFloatv = (alGetFloatvPROC)(intptr_t)__functionAddress; UNUSED_PARAMS(__env, clazz) alGetFloatv(paramName, dest); }
//***************************************************************************** // alGetFloatv //***************************************************************************** // ALAPI ALvoid ALAPIENTRY alGetFloatv(ALenum param, ALfloat* data) { AL_VOID_FXN(alGetFloatv(param, data)); }