void C4SoundModifier::ApplyTo(ALuint source) { // apply slot to source if valid #if defined(HAVE_ALEXT) if (slot) alSource3i(source, AL_AUXILIARY_SEND_FILTER, slot, 0, AL_FILTER_NULL); #endif }
void CSoundSource::PlayStream(IAudioChannel* channel, const std::string& file, float volume) { //! stop any current playback Stop(); if (!curStream.Valid()) curStream = COggStream(id); //! setup OpenAL params curChannel = channel; curVolume = volume; in3D = false; if (efxEnabled) { alSource3i(id, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0, AL_FILTER_NULL); alSourcei(id, AL_DIRECT_FILTER, AL_FILTER_NULL); efxEnabled = false; } alSource3f(id, AL_POSITION, 0.0f, 0.0f, 0.0f); alSourcef(id, AL_GAIN, volume); alSourcef(id, AL_PITCH, globalPitch); alSource3f(id, AL_VELOCITY, 0.0f, 0.0f, 0.0f); alSource3f(id, AL_DIRECTION, 0.0f, 0.0f, 0.0f); alSourcef(id, AL_ROLLOFF_FACTOR, 0.0f); alSourcei(id, AL_SOURCE_RELATIVE, AL_TRUE); // COggStreams only appends buffers, giving errors when a buffer of another format is still assigned alSourcei(id, AL_BUFFER, AL_NONE); curStream.Play(file, volume); curStream.Update(); CheckError("CSoundSource::Update"); }
/* Creates a new player object, and allocates the needed OpenAL source and * buffer objects. Error checking is simplified for the purposes of this * example, and will cause an abort if needed. */ static StreamPlayer *NewPlayer(void) { StreamPlayer *player; player = malloc(sizeof(*player)); assert(player != NULL); memset(player, 0, sizeof(*player)); /* Generate the buffers and source */ alGenBuffers(NUM_BUFFERS, player->buffers); assert(alGetError() == AL_NO_ERROR && "Could not create buffers"); alGenSources(1, &player->source); assert(alGetError() == AL_NO_ERROR && "Could not create source"); /* Set parameters so mono sources play out the front-center speaker and * won't distance attenuate. */ alSource3i(player->source, AL_POSITION, 0, 0, -1); alSourcei(player->source, AL_SOURCE_RELATIVE, AL_TRUE); alSourcei(player->source, AL_ROLLOFF_FACTOR, 0); assert(alGetError() == AL_NO_ERROR && "Could not set source parameters"); return player; }
void StreamTrack::unsetFX() { // Remove any audio sends and direct filters from channel. alSourcei(m_source, AL_DIRECT_FILTER, AL_FILTER_NULL); DEBUG_CHECK_AL_ERROR(); alSource3i(m_source, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0, AL_FILTER_NULL); DEBUG_CHECK_AL_ERROR(); }
/** * @brief Creates a group. */ int sound_al_createGroup( int size ) { int i, j, id; alGroup_t *g; /* Get new ID. */ id = ++al_groupidgen; /* Grow group list. */ al_ngroups++; al_groups = realloc( al_groups, sizeof(alGroup_t) * al_ngroups ); g = &al_groups[ al_ngroups-1 ]; memset( g, 0, sizeof(alGroup_t) ); g->id = id; g->state = VOICE_PLAYING; g->speed = 1; g->volume = 1.; /* Allocate sources. */ g->sources = calloc( size, sizeof(ALuint) ); g->nsources = size; /* Add some sources. */ for (i=0; i<size; i++) { /* Make sure there's enough. */ if (source_nstack <= 0) goto group_err; /* Pull one off the stack. */ source_nstack--; g->sources[i] = source_stack[source_nstack]; /* Disable EFX, they don't affect groups. */ if (al_info.efx_reverb == AL_TRUE) { alSourcef( g->sources[i], AL_AIR_ABSORPTION_FACTOR, 0. ); alSource3i( g->sources[i], AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0, AL_FILTER_NULL ); } /* Remove from total too. */ for (j=0; j<source_ntotal; j++) { if (g->sources[i] == source_total[j]) { source_ntotal--; memmove( &source_total[j], &source_total[j+1], sizeof(ALuint) * (source_ntotal - j) ); break; } } } return id; group_err: free(g->sources); al_ngroups--; return 0; }
void al_source3i( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { if (NULL == alSource3i) mogl_glunsupported("alSource3i"); alSource3i((ALuint)mxGetScalar(prhs[0]), (ALenum)mxGetScalar(prhs[1]), (ALint)mxGetScalar(prhs[2]), (ALint)mxGetScalar(prhs[3]), (ALint)mxGetScalar(prhs[4])); }
void COALExtProvider::SetEaxReverb(ALuint effect, ALuint slot, ALuint source, EFXEAXREVERBPROPERTIES& output) { if(!m_initialized) return; if(!SetEFXEAXReverbProperties(&output, effect)) return; alAuxiliaryEffectSloti(slot, AL_EFFECTSLOT_EFFECT, effect); alSource3i(source, AL_AUXILIARY_SEND_FILTER, slot, 0, AL_FILTER_NULL); }
CSoundSource::~CSoundSource() { if (efxEnabled) { alSource3i(id, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0, AL_FILTER_NULL); alSourcei(id, AL_DIRECT_FILTER, AL_FILTER_NULL); } Stop(); alDeleteSources(1, &id); CheckError("CSoundSource::~CSoundSource"); }
void StreamTrack::setFX() { // Reverb FX is applied globally through audio send. Since player can // jump between adjacent rooms with different reverb info, we assign // several (2 by default) interchangeable audio sends, which are switched // every time current room reverb is changed. ALuint slot = m_audioEngine->getFxManager().allocateSlot(); // Assign global reverb FX to channel. alSource3i(m_source, AL_AUXILIARY_SEND_FILTER, slot, 0, AL_FILTER_NULL); DEBUG_CHECK_AL_ERROR(); }
static int lua_alSource(lua_State* lua_state) { ALuint source_id; ALenum enum_parameter; int openal_primitive_type; source_id = lua_tointeger(lua_state, 1); enum_parameter = lua_tointeger(lua_state, 2); openal_primitive_type = lua_getTypeForEnum(enum_parameter); switch(openal_primitive_type) { case LUAOPENAL_BOOL_TYPE: case LUAOPENAL_INT_TYPE: { alSourcei(source_id, enum_parameter, lua_tointeger(lua_state, 3)); break; } case LUAOPENAL_FLOAT_TYPE: { alSourcef(source_id, enum_parameter, lua_tonumber(lua_state, 3)); break; } case LUAOPENAL_INT_3_TYPE: { alSource3i(source_id, enum_parameter, lua_tointeger(lua_state, 3), lua_tointeger(lua_state, 4), lua_tointeger(lua_state, 5)); break; } case LUAOPENAL_FLOAT_3_TYPE: { alSource3f(source_id, enum_parameter, lua_tonumber(lua_state, 3), lua_tonumber(lua_state, 4), lua_tonumber(lua_state, 5)); break; } default: { /* TODO: Figure out how to handle OpenAL extensions. */ luaL_error(lua_state, "Unhandled parameter type for alSource*"); } } return 0; }
void CSoundSource::Update() { if (asyncPlay.buffer != nullptr) { Play(asyncPlay.channel, asyncPlay.buffer, asyncPlay.pos, asyncPlay.velocity, asyncPlay.volume, asyncPlay.relative); asyncPlay = AsyncSoundItemData(); } if (curPlaying != nullptr) { if (in3D && (efxEnabled != efx->enabled)) { alSourcef(id, AL_AIR_ABSORPTION_FACTOR, (efx->enabled) ? efx->GetAirAbsorptionFactor() : 0); alSource3i(id, AL_AUXILIARY_SEND_FILTER, (efx->enabled) ? efx->sfxSlot : AL_EFFECTSLOT_NULL, 0, AL_FILTER_NULL); alSourcei(id, AL_DIRECT_FILTER, (efx->enabled) ? efx->sfxFilter : AL_FILTER_NULL); efxEnabled = efx->enabled; efxUpdates = efx->updates; } if (heightRolloffModifier != curHeightRolloffModifier) { curHeightRolloffModifier = heightRolloffModifier; alSourcef(id, AL_ROLLOFF_FACTOR, ROLLOFF_FACTOR * curPlaying->rolloff * heightRolloffModifier); } if (!IsPlaying(true) || ((curPlaying->loopTime > 0) && (spring_gettime() > loopStop))) Stop(); } if (curStream.Valid()) { if (curStream.IsFinished()) { Stop(); } else { curStream.Update(); CheckError("CSoundSource::Update"); } } if (efxEnabled && (efxUpdates != efx->updates)) { //! airAbsorption & LowPass aren't auto updated by OpenAL on change, so we need to do it per source alSourcef(id, AL_AIR_ABSORPTION_FACTOR, efx->GetAirAbsorptionFactor()); alSourcei(id, AL_DIRECT_FILTER, efx->sfxFilter); efxUpdates = efx->updates; } }
void QOpenALEngine::openEFX() { if (ALFWIsEFXSupported()) { if (CreateAuxEffectSlot(&uiEffectSlot)) { if (CreateEffect(&uiEffect, AL_EFFECT_EAXREVERB)) { // ConvertReverbParameters(&eaxBathroom, &efxReverb); efxReverb=eaxBathroom; // Set the Effect parameters if (!SetEFXEAXReverbProperties(&efxReverb, uiEffect)) return; // Load Effect into Auxiliary Effect Slot alAuxiliaryEffectSloti(uiEffectSlot, AL_EFFECTSLOT_EFFECT, uiEffect); // Enable (non-filtered) Send from Source to Auxiliary Effect Slot alSource3i(uiSource, AL_AUXILIARY_SEND_FILTER, uiEffectSlot, 0, AL_FILTER_NULL); } } } }
void Audio::effects(int source) { #ifdef WIN32 ALenum al_err; alAuxiliaryEffectSloti(slot, AL_EFFECTSLOT_EFFECT, effect); al_err = alGetError(); if (al_err != AL_NO_ERROR) { debugf("Unable to associate effect: %s\n", GetALErrorString(al_err)); return; } alSource3i(source, AL_AUXILIARY_SEND_FILTER, slot, 0, AL_FILTER_NULL); al_err = alGetError(); if (al_err != AL_NO_ERROR) { debugf("Unable to associate slot: %s\n", GetALErrorString(al_err)); } #endif }
value lime_al_source3i (value source, value param, value value1, value value2, value value3) { alSource3i (val_int (source), val_int (param), val_int (value1), val_int (value2), val_int (value3)); return alloc_null (); }
//***************************************************************************** // alSource3i //***************************************************************************** // ALAPI ALvoid ALAPIENTRY alSource3i(ALuint sourceName, ALenum param, ALint v1, ALint v2, ALint v3) { AL_VOID_FXN(alSource3i(sourceName, param, v1, v2, v3)); }
void Sound::reverb(bool enable) { if(enable) alSource3i(source,AL_AUXILIARY_SEND_FILTER,uiEffectSlot,0,0); else alSource3i(source,AL_AUXILIARY_SEND_FILTER,AL_EFFECTSLOT_NULL,0,0); }
void QALSource::setPosition(int px, int py, int pz) { alSource3i(d->source, AL_POSITION, px, py, pz); }
void CSoundSource::Play(IAudioChannel* channel, SoundItem* item, float3 pos, float3 velocity, float volume, bool relative) { assert(!curStream.Valid()); assert(channel); if (!item->PlayNow()) return; Stop(); curVolume = volume; curPlaying = item; curChannel = channel; alSourcei(id, AL_BUFFER, item->buffer->GetId()); alSourcef(id, AL_GAIN, volume * item->GetGain() * channel->volume); alSourcef(id, AL_PITCH, item->GetPitch() * globalPitch); velocity *= item->dopplerScale * ELMOS_TO_METERS; alSource3f(id, AL_VELOCITY, velocity.x, velocity.y, velocity.z); alSourcei(id, AL_LOOPING, (item->loopTime > 0) ? AL_TRUE : AL_FALSE); loopStop = spring_gettime() + spring_msecs(item->loopTime); if (relative || !item->in3D) { in3D = false; if (efxEnabled) { alSource3i(id, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0, AL_FILTER_NULL); alSourcei(id, AL_DIRECT_FILTER, AL_FILTER_NULL); efxEnabled = false; } alSourcei(id, AL_SOURCE_RELATIVE, AL_TRUE); alSourcef(id, AL_ROLLOFF_FACTOR, 0.f); alSource3f(id, AL_POSITION, 0.0f, 0.0f, -1.0f * ELMOS_TO_METERS); #ifdef __APPLE__ alSourcef(id, AL_REFERENCE_DISTANCE, referenceDistance * ELMOS_TO_METERS); #endif } else { if (item->buffer->GetChannels() > 1) { LOG_L(L_WARNING, "Can not play non-mono \"%s\" in 3d.", item->buffer->GetFilename().c_str()); } in3D = true; if (efx->enabled) { efxEnabled = true; alSourcef(id, AL_AIR_ABSORPTION_FACTOR, efx->GetAirAbsorptionFactor()); alSource3i(id, AL_AUXILIARY_SEND_FILTER, efx->sfxSlot, 0, AL_FILTER_NULL); alSourcei(id, AL_DIRECT_FILTER, efx->sfxFilter); efxUpdates = efx->updates; } alSourcei(id, AL_SOURCE_RELATIVE, AL_FALSE); pos *= ELMOS_TO_METERS; alSource3f(id, AL_POSITION, pos.x, pos.y, pos.z); curHeightRolloffModifier = heightRolloffModifier; alSourcef(id, AL_ROLLOFF_FACTOR, ROLLOFF_FACTOR * item->rolloff * heightRolloffModifier); #ifdef __APPLE__ alSourcef(id, AL_MAX_DISTANCE, 1000000.0f); //! Max distance is too small by default on my Mac... ALfloat gain = channel->volume * item->GetGain() * volume; if (gain > 1.0f) { //! OpenAL on Mac cannot handle AL_GAIN > 1 well, so we will adjust settings to get the same output with AL_GAIN = 1. ALint model = alGetInteger(AL_DISTANCE_MODEL); ALfloat rolloff = ROLLOFF_FACTOR * item->rolloff * heightRolloffModifier; ALfloat ref = referenceDistance * ELMOS_TO_METERS; if ((model == AL_INVERSE_DISTANCE_CLAMPED) || (model == AL_INVERSE_DISTANCE)) { alSourcef(id, AL_REFERENCE_DISTANCE, ((gain - 1.0f) * ref / rolloff) + ref); alSourcef(id, AL_ROLLOFF_FACTOR, (gain + rolloff - 1.0f) / gain); alSourcef(id, AL_GAIN, 1.0f); } } else { alSourcef(id, AL_REFERENCE_DISTANCE, referenceDistance * ELMOS_TO_METERS); } #endif } alSourcePlay(id); if (item->buffer->GetId() == 0) LOG_L(L_WARNING, "CSoundSource::Play: Empty buffer for item %s (file %s)", item->name.c_str(), item->buffer->GetFilename().c_str()); CheckError("CSoundSource::Play"); }
void QALSource::setVelocity(int vx, int vy, int vz) { alSource3i(d->source, AL_VELOCITY, vx, vy, vz); }
ALvoid CDECL wine_alSource3i(ALuint sid, ALenum param, ALint value1, ALint value2, ALint value3) { alSource3i(sid, param, value1, value2, value3); }
/* Sources methods */ static PyObject* _sources_setprop (PyObject *self, PyObject *args) { long bufnum; ALenum param; PyObject *values; char *type; PropType ptype = INVALID; if (!CONTEXT_IS_CURRENT (((PySources*)self)->context)) { PyErr_SetString (PyExc_PyGameError, "source context is not current"); return NULL; } if (!PyArg_ParseTuple (args, "llO|s:set_prop", &bufnum, ¶m, &values, &type)) return NULL; if (type) { ptype = GetPropTypeFromStr (type); if (ptype == INVALID) { PyErr_SetString (PyExc_RuntimeError, "passing a sequence requires passing a type specifier"); return NULL; } } if (PySequence_Check (values)) { Py_ssize_t size, cnt; if (!type) { PyErr_SetString (PyExc_RuntimeError, "passing a sequence requires passing a type specifier"); return NULL; } if (ptype == INT || ptype == FLOAT) { PyErr_SetString (PyExc_TypeError, "cannot use single value type and sequence together"); return NULL; } size = PySequence_Size (values); switch (ptype) { case INT3: case INTARRAY: { ALint *vals; int tmp; if (ptype == INT3 && size < 3) { PyErr_SetString (PyExc_ValueError, "sequence too small for 'i3'"); return NULL; } vals = PyMem_New (ALint, size); if (!vals) return NULL; for (cnt = 0; cnt < size; cnt++) { if (!IntFromSeqIndex (values, cnt, &tmp)) { PyMem_Free (vals); return NULL; } vals[cnt] = (ALint) tmp; } CLEAR_ALERROR_STATE (); if (ptype == INT3) alSource3i ((ALuint)bufnum, param, vals[0], vals[1], vals[2]); else alSourceiv ((ALuint)bufnum, param, vals); PyMem_Free (vals); /* Error will be set at the end */ break; } case FLOAT3: case FLOATARRAY: { ALfloat *vals; double tmp; if (ptype == FLOAT3 && size < 3) { PyErr_SetString (PyExc_ValueError, "sequence too small for 'f3'"); return NULL; } vals = PyMem_New (ALfloat, size); if (!vals) return NULL; for (cnt = 0; cnt < size; cnt++) { if (!DoubleFromSeqIndex (values, cnt, &tmp)) { PyMem_Free (vals); return NULL; } vals[cnt] = (ALfloat) tmp; } CLEAR_ALERROR_STATE (); if (ptype == FLOAT3) alSource3f ((ALuint)bufnum, param, vals[0], vals[1], vals[2]); else alSourcefv ((ALuint)bufnum, param, vals); PyMem_Free (vals); /* Error will be set at the end */ break; } default: PyErr_SetString (PyExc_TypeError, "unsupported value"); return NULL; } } else { int ival = 0; double fval = 0; if (!type) { if (IntFromObj (values, &ival)) ptype = INT; else PyErr_Clear (); if (DoubleFromObj (values, &fval)) ptype = FLOAT; else { PyErr_Clear (); PyErr_SetString (PyExc_TypeError, "unsupported value"); return NULL; } } switch (ptype) { case INT: if (!IntFromObj (values, &ival)) return NULL; CLEAR_ALERROR_STATE (); alSourcei ((ALuint)bufnum, param, (ALint) ival); break; case FLOAT: if (!DoubleFromObj (values, &fval)) return NULL; CLEAR_ALERROR_STATE (); alSourcef ((ALuint)bufnum, param, (ALfloat) fval); break; default: PyErr_SetString (PyExc_TypeError, "value type mismatch"); return NULL; } } if (SetALErrorException (alGetError (), 0)) return NULL; Py_RETURN_NONE; }
void TestEffect::basicTest() { /*! - create a source and try reverb and filter on it */ Sound::init() ; ALuint source; alGenSources(1,&source) ; Implementation::OpenAL::Reader* reader = new Implementation::OpenAL::WavReader(source, "hit.wav", false, 1.1) ; reader->onInit(0,0) ; alSourcePlay(source); Kernel::Timer timer ; Kernel::Timer bip ; //build effect slot ALuint auxEffectSlot; Implementation::OpenAL::alGenAuxiliaryEffectSlots(1, &auxEffectSlot); CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; /* can't build more than 1 slot without sound card ALuint auxEffectSlot2; Implementation::OpenAL::alGenAuxiliaryEffectSlots(1, &auxEffectSlot2); CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; */ //build effect ALuint effect; Implementation::OpenAL::alGenEffects(1, &effect); CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; //configure effect Implementation::OpenAL::alEffecti(effect, AL_EFFECT_TYPE, AL_EFFECT_REVERB); CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; Implementation::OpenAL::alEffectf(effect, AL_REVERB_DECAY_TIME, 2.0f); //link effect to slot effect Implementation::OpenAL::alAuxiliaryEffectSloti(auxEffectSlot, AL_EFFECTSLOT_EFFECT, effect); CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; //create filter ALuint filter; Implementation::OpenAL::alGenFilters(1, &filter); CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; //Try to create more than 1 filter ALuint filters[32] = { 0 }; Implementation::OpenAL::alGenFilters(32, &filters[0]); CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; Implementation::OpenAL::alFilteri(filter,AL_FILTER_TYPE,AL_FILTER_LOWPASS); Implementation::OpenAL::alFilterf(filter, AL_LOWPASS_GAIN, 1.0f); Implementation::OpenAL::alFilterf(filter, AL_LOWPASS_GAINHF, 0.0f); CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; //Normal sound while (timer.getSecond() <= 2) { if(bip.getSecond() > 1) { reader->update(); bip.reset(); } } //link source output 0 to effect slot without more filter alSource3i(source, AL_AUXILIARY_SEND_FILTER, auxEffectSlot, 0, 0); CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; timer.reset(); //Sound with reverb effect while (timer.getSecond() <= 2) { if(bip.getSecond() > 1) { reader->update(); bip.reset(); } } //unlink effect alSource3i(source,AL_AUXILIARY_SEND_FILTER,AL_EFFECTSLOT_NULL, 0, 0); //link filter alSourcei(source, AL_DIRECT_FILTER, filter); timer.reset(); //Sound with low pass filter on main output while (timer.getSecond() <= 2) { if(bip.getSecond() > 1) { reader->update(); bip.reset(); } } alSource3i(source, AL_AUXILIARY_SEND_FILTER, auxEffectSlot, 0, 0); timer.reset(); //Sound with low pass filter and reverb effect while (timer.getSecond() <= 2) { if(bip.getSecond() > 1) { reader->update(); bip.reset(); } } CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; /// //unlink effect alSource3i(source,AL_AUXILIARY_SEND_FILTER,AL_EFFECTSLOT_NULL, 0, 0); //unlink filter alSourcei(source, AL_DIRECT_FILTER, AL_FILTER_NULL); //Filter for direct output , no pass Implementation::OpenAL::alFilteri(filters[0],AL_FILTER_TYPE,AL_FILTER_LOWPASS); Implementation::OpenAL::alFilterf(filters[0], AL_LOWPASS_GAIN, 0.0f); Implementation::OpenAL::alFilterf(filters[0], AL_LOWPASS_GAINHF, 0.0f); //Filter aux1 , all pass Implementation::OpenAL::alFilteri(filters[1],AL_FILTER_TYPE,AL_FILTER_LOWPASS); Implementation::OpenAL::alFilterf(filters[1], AL_LOWPASS_GAIN, 1.0f); Implementation::OpenAL::alFilterf(filters[1], AL_LOWPASS_GAINHF, 1.0f); alSourcei(source, AL_DIRECT_FILTER, filters[0]); alSource3i(source, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 0, filters[1]); //With just 1 auxEffectSlot there is just 1 auxiliary output for a source //alSource3i(source, AL_AUXILIARY_SEND_FILTER, AL_EFFECTSLOT_NULL, 1, filters[2]); CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; timer.reset(); //Sound with just direct output at 0 gain and aux0 output at 1.0 without effect //Without auxEffectSlot there isn't any output while (timer.getSecond() <= 2) { if(bip.getSecond() > 1) { reader->update(); bip.reset(); } } alSource3i(source, AL_AUXILIARY_SEND_FILTER, auxEffectSlot, 0, filters[1]); CPPUNIT_ASSERT(alGetError() == AL_NO_ERROR) ; timer.reset(); //Sound with just direct output at 0 gain and aux0 output at 1.0 with effect //With auxEffectSlot there is an output while (timer.getSecond() <= 2) { if(bip.getSecond() > 1) { reader->update(); bip.reset(); } } reader->onClose() ; delete reader ; Sound::close(); }
/** * @brief Initializes the sound subsystem. * * @return 0 on success. */ int sound_al_init (void) { int ret; const ALchar* dev; ALuint s; ALint freq; ALint attribs[4] = { 0, 0, 0, 0 }; /* Default values. */ ret = 0; /* we'll need a mutex */ sound_lock = SDL_CreateMutex(); soundLock(); /* Get the sound device. */ dev = alcGetString( NULL, ALC_DEFAULT_DEVICE_SPECIFIER ); /* opening the default device */ al_device = alcOpenDevice(NULL); if (al_device == NULL) { WARN("Unable to open default sound device"); ret = -1; goto snderr_dev; } /* Query EFX extension. */ if (conf.al_efx) { al_info.efx = alcIsExtensionPresent( al_device, "ALC_EXT_EFX" ); if (al_info.efx == AL_TRUE) { attribs[0] = ALC_MAX_AUXILIARY_SENDS; attribs[1] = 4; } } else al_info.efx = AL_FALSE; /* Create the OpenAL context */ al_context = alcCreateContext( al_device, attribs ); if (sound_lock == NULL) { WARN("Unable to create OpenAL context"); ret = -2; goto snderr_ctx; } /* Clear the errors */ alGetError(); /* Set active context */ if (alcMakeContextCurrent( al_context )==AL_FALSE) { WARN("Failure to set default context"); ret = -4; goto snderr_act; } /* Get context information. */ alcGetIntegerv( al_device, ALC_FREQUENCY, sizeof(freq), &freq ); /* Try to enable EFX. */ if (al_info.efx == AL_TRUE) al_enableEFX(); else { al_info.efx_reverb = AL_FALSE; al_info.efx_echo = AL_FALSE; } /* Allocate source for music. */ alGenSources( 1, &music_source ); /* Check for errors. */ al_checkErr(); /* Start allocating the sources - music has already taken his */ source_nstack = 0; source_mstack = 0; while (source_nstack < SOUND_MAX_SOURCES) { if (source_mstack < source_nstack+1) { /* allocate more memory */ source_mstack += 32; source_stack = realloc( source_stack, sizeof(ALuint) * source_mstack ); } alGenSources( 1, &s ); source_stack[source_nstack] = s; /* Distance model defaults. */ alSourcef( s, AL_MAX_DISTANCE, 5000. ); alSourcef( s, AL_ROLLOFF_FACTOR, 1. ); alSourcef( s, AL_REFERENCE_DISTANCE, 500. ); /* Set the filter. */ if (al_info.efx == AL_TRUE) alSource3i( s, AL_AUXILIARY_SEND_FILTER, efx_directSlot, 0, AL_FILTER_NULL ); /* Check for error. */ if (alGetError() == AL_NO_ERROR) source_nstack++; else break; } /* Reduce ram usage. */ source_mstack = source_nstack; source_stack = realloc( source_stack, sizeof(ALuint) * source_mstack ); /* Copy allocated sources to total stack. */ source_ntotal = source_mstack; source_total = malloc( sizeof(ALuint) * source_mstack ); memcpy( source_total, source_stack, sizeof(ALuint) * source_mstack ); /* Copy allocated sources to all stack. */ source_nall = source_mstack; source_all = malloc( sizeof(ALuint) * source_mstack ); memcpy( source_all, source_stack, sizeof(ALuint) * source_mstack ); /* Set up how sound works. */ alDistanceModel( AL_INVERSE_DISTANCE_CLAMPED ); alDopplerFactor( 1. ); sound_al_env( SOUND_ENV_NORMAL, 0. ); /* Check for errors. */ al_checkErr(); /* we can unlock now */ soundUnlock(); /* debug magic */ DEBUG("OpenAL started: %d Hz", freq); DEBUG("Renderer: %s", alGetString(AL_RENDERER)); if (al_info.efx == AL_FALSE) DEBUG("Version: %s without EFX", alGetString(AL_VERSION)); else DEBUG("Version: %s with EFX %d.%d", alGetString(AL_VERSION), al_info.efx_major, al_info.efx_minor); DEBUG(); return 0; /* * error handling */ snderr_act: alcDestroyContext( al_context ); snderr_ctx: al_context = NULL; alcCloseDevice( al_device ); snderr_dev: al_device = NULL; soundUnlock(); SDL_DestroyMutex( sound_lock ); sound_lock = NULL; return ret; }
/** * @brief Initializes the sound subsystem. * * @return 0 on success. */ int sound_al_init (void) { int ret; ALuint s; ALint freq; ALint attribs[4] = { 0, 0, 0, 0 }; /* Default values. */ ret = 0; /* we'll need a mutex */ sound_lock = SDL_CreateMutex(); soundLock(); /* opening the default device */ al_device = alcOpenDevice(NULL); if (al_device == NULL) { WARN(_("Unable to open default sound device")); ret = -1; goto snderr_dev; } /* Query EFX extension. */ if (conf.al_efx) { al_info.efx = alcIsExtensionPresent( al_device, "ALC_EXT_EFX" ); if (al_info.efx == AL_TRUE) { attribs[0] = ALC_MAX_AUXILIARY_SENDS; attribs[1] = 4; } } else al_info.efx = AL_FALSE; /* Create the OpenAL context */ al_context = alcCreateContext( al_device, attribs ); if (al_context == NULL) { WARN(_("Unable to create OpenAL context")); ret = -2; goto snderr_ctx; } /* Clear the errors */ alGetError(); /* Set active context */ if (alcMakeContextCurrent( al_context )==AL_FALSE) { WARN(_("Failure to set default context")); ret = -4; goto snderr_act; } /* Get context information. */ alcGetIntegerv( al_device, ALC_FREQUENCY, sizeof(freq), &freq ); /* Try to enable EFX. */ if (al_info.efx == AL_TRUE) al_enableEFX(); else { al_info.efx_reverb = AL_FALSE; al_info.efx_echo = AL_FALSE; } /* Allocate source for music. */ alGenSources( 1, &music_source ); /* Check for errors. */ al_checkErr(); /* Start allocating the sources - music has already taken his */ source_nstack = 0; source_mstack = 0; while (source_nstack < conf.snd_voices) { if (source_mstack < source_nstack+1) { /* allocate more memory */ if (source_mstack == 0) source_mstack = conf.snd_voices; else source_mstack *= 2; source_stack = realloc( source_stack, sizeof(ALuint) * source_mstack ); } alGenSources( 1, &s ); source_stack[source_nstack] = s; /* How OpenAL distance model works: * * Clamped: * gain = distance_function( CLAMP( AL_REFERENCE_DISTANCE, AL_MAX_DISTANCE, distance ) ); * * Distance functions: * AL_REFERENCE_DISTANCE * * Inverse = ------------------------------------------------------------------------------ * AL_REFERENCE_DISTANCE + AL_ROLLOFF_FACTOR ( distance - AL_REFERENCE_DISTANCE ) * * 1 - AL_ROLLOFF_FACTOR ( distance - AL_REFERENCE_DISTANCE ) * * Linear = ---------------------------------------------------------- * AL_MAX_DISTANCE - AL_REFERENCE_DISTANCE * * / distance \ -AL_ROLLOFF_FACTOR * * Exponential = | --------------------- | * \ AL_REFERENCE_DISTANCE / * * * Some values: * * model falloff reference 100 1000 5000 10000 * linear 1 500 1.000 0.947 0.526 0.000 * inverse 1 500 1.000 0.500 0.100 0.050 * exponent 1 500 1.000 0.500 0.100 0.050 * inverse 0.5 500 1.000 0.667 0.182 0.095 * exponent 0.5 500 1.000 0.707 0.316 0.223 * inverse 2 500 1.000 0.333 0.052 0.026 * exponent 2 500 1.000 0.250 0.010 0.003 */ alSourcef( s, AL_REFERENCE_DISTANCE, 500. ); /* Close distance to clamp at (doesn't get louder). */ alSourcef( s, AL_MAX_DISTANCE, 25000. ); /* Max distance to clamp at (doesn't get quieter). */ alSourcef( s, AL_ROLLOFF_FACTOR, 1. ); /* Determines how it drops off. */ /* Set the filter. */ if (al_info.efx == AL_TRUE) alSource3i( s, AL_AUXILIARY_SEND_FILTER, efx_directSlot, 0, AL_FILTER_NULL ); /* Check for error. */ if (alGetError() == AL_NO_ERROR) source_nstack++; else break; } /* Reduce ram usage. */ source_mstack = source_nstack; source_stack = realloc( source_stack, sizeof(ALuint) * source_mstack ); /* Copy allocated sources to total stack. */ source_ntotal = source_mstack; source_total = malloc( sizeof(ALuint) * source_mstack ); memcpy( source_total, source_stack, sizeof(ALuint) * source_mstack ); /* Copy allocated sources to all stack. */ source_nall = source_mstack; source_all = malloc( sizeof(ALuint) * source_mstack ); memcpy( source_all, source_stack, sizeof(ALuint) * source_mstack ); /* Set up how sound works. */ alDistanceModel( AL_INVERSE_DISTANCE_CLAMPED ); /* Clamping is fundamental so it doesn't sound like crap. */ alDopplerFactor( 1. ); sound_al_env( SOUND_ENV_NORMAL, 0. ); /* Check for errors. */ al_checkErr(); /* we can unlock now */ soundUnlock(); /* debug magic */ DEBUG(_("OpenAL started: %d Hz"), freq); DEBUG(_("Renderer: %s"), alGetString(AL_RENDERER)); if (al_info.efx == AL_FALSE) DEBUG(_("Version: %s without EFX"), alGetString(AL_VERSION)); else DEBUG(_("Version: %s with EFX %d.%d"), alGetString(AL_VERSION), al_info.efx_major, al_info.efx_minor); DEBUG(""); return ret; /* * error handling */ snderr_act: alcDestroyContext( al_context ); snderr_ctx: al_context = NULL; alcCloseDevice( al_device ); snderr_dev: al_device = NULL; soundUnlock(); SDL_DestroyMutex( sound_lock ); sound_lock = NULL; return ret; }
void lime_al_source3i (int source, int param, int value1, int value2, int value3) { alSource3i (source, param, value1, value2, value3); }