AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum param, ALfloat *pflValues) { ALCcontext *Context; Context = alcGetCurrentContext(); if(!Context) { alSetError(AL_INVALID_OPERATION); return; } SuspendContext(Context); if (alIsAuxiliaryEffectSlot(effectslot)) { switch(param) { case AL_EFFECTSLOT_GAIN: alGetAuxiliaryEffectSlotf(effectslot, param, pflValues); break; default: alSetError(AL_INVALID_ENUM); break; } } else alSetError(AL_INVALID_NAME); ProcessContext(Context); }
ALvoid AL_APIENTRY alFilteri(ALuint filter, ALenum param, ALint iValue) { ALCcontext *Context; Context = alcGetCurrentContext(); SuspendContext(Context); if (filter && alIsFilter(filter)) { ALfilter *ALFilter = (ALfilter*)ALTHUNK_LOOKUPENTRY(filter); switch(param) { case AL_FILTER_TYPE: if(iValue == AL_FILTER_NULL || iValue == AL_FILTER_LOWPASS) InitFilterParams(ALFilter, iValue); else alSetError(AL_INVALID_VALUE); break; default: alSetError(AL_INVALID_ENUM); break; } } else alSetError(AL_INVALID_NAME); ProcessContext(Context); }
ALvoid AL_APIENTRY alGetFilteriv(ALuint filter, ALenum param, ALint *piValues) { ALCcontext *Context; Context = alcGetCurrentContext(); SuspendContext(Context); if (filter && alIsFilter(filter)) { switch(param) { case AL_FILTER_TYPE: alGetFilteri(filter, param, piValues); break; default: alSetError(AL_INVALID_ENUM); break; } } else alSetError(AL_INVALID_NAME); ProcessContext(Context); }
// virtual std::string LLAudioEngine_OpenAL::getDriverName(bool verbose) { ALCdevice *device = alcGetContextsDevice(alcGetCurrentContext()); std::ostringstream version; version << "OpenAL"; if (verbose) { version << ", version " << ll_safe_string(alGetString(AL_VERSION)) << " / " << ll_safe_string(alGetString(AL_VENDOR)) << " / " << ll_safe_string(alGetString(AL_RENDERER)); if (device) version << ": " << ll_safe_string(alcGetString(device, ALC_DEFAULT_DEVICE_SPECIFIER)); } return version.str(); }
COpenALSound::~COpenALSound() { if (noSound) { delete[] Sources; return; } LoadedFiles.clear(); for (int i = 0; i < maxSounds; i++) { alSourceStop(Sources[i]); alDeleteSources(1,&Sources[i]); } delete[] Sources; while (!Buffers.empty()) { alDeleteBuffers(1,&Buffers.back()); Buffers.pop_back(); } ALCcontext *curcontext = alcGetCurrentContext(); ALCdevice *curdevice = alcGetContextsDevice(curcontext); alcSuspendContext(curcontext); /* * FIXME * Technically you're supposed to detach and destroy the * current context with these two lines, but it deadlocks. * As a not-quite-as-clean shortcut, if we skip this step * and just close the device, OpenAL theoretically * destroys the context associated with that device. * * alcMakeContextCurrent(NULL); * alcDestroyContext(curcontext); */ alcCloseDevice(curdevice); }
void CaptureThread::initializeSound() { _pContext = NULL; _pDevice = NULL; // Check for Capture Extension support _pContext = alcGetCurrentContext(); _pDevice = alcGetContextsDevice( _pContext ); if( alcIsExtensionPresent( _pDevice, "ALC_EXT_CAPTURE") == AL_FALSE ) { return; } // Get list of available Capture Devices const ALchar *pDeviceList = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER); if ( pDeviceList ) { while (*pDeviceList) { pDeviceList += strlen(pDeviceList) + 1; } } // Get the name of the 'default' capture device _szDefaultCaptureDevice = alcGetString( NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER ); //pCaptureDevice = alcCaptureOpenDevice( szDefaultCaptureDevice, 44100, AL_FORMAT_MONO16, BUFFERSIZE ); this->changeDevice( QString( _szDefaultCaptureDevice ) ); }
ALAPI void ALAPIENTRY alBufferiv(ALuint buffer, ALenum eParam, const ALint* plValues) { ALCcontext *pContext; (void)plValues; pContext = alcGetCurrentContext(); SuspendContext(pContext); if (alIsBuffer(buffer) && (buffer != 0)) { switch(eParam) { default: alSetError(AL_INVALID_ENUM); break; } } else { alSetError(AL_INVALID_NAME); } ProcessContext(pContext); }
static void checkForErrors (void) { { ALenum error = alutGetError (); if (error != ALUT_ERROR_NO_ERROR) { die ("ALUT", alutGetErrorString (error)); } } { ALCdevice *device = alcGetContextsDevice (alcGetCurrentContext ()); ALCenum error = alcGetError (device); if (error != ALC_NO_ERROR) { die ("ALC", (const char *) alcGetString (device, error)); } } { ALenum error = alGetError (); if (error != AL_NO_ERROR) { die ("AL", (const char *) alGetString (error)); } } }
ALAPI ALvoid ALAPIENTRY alGetSourcef(ALuint source,ALenum pname,ALfloat *value) { ALCcontext *Context; ALsource *Source; Context=alcGetCurrentContext(); alcSuspendContext(Context); if (alIsSource(source)) { Source=((ALsource *)source); switch(pname) { case AL_PITCH: case AL_GAIN: 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: if (Source->param[pname-AL_CONE_INNER_ANGLE].valid) *value=Source->param[pname-AL_CONE_INNER_ANGLE].data.f; break; default: alSetError(AL_INVALID_ENUM); break; } } else alSetError(AL_INVALID_NAME); alcProcessContext(Context); }
void OpenALStream::Stop() { m_run_thread.Clear(); // kick the thread if it's waiting soundSyncEvent.Set(); soundTouch.clear(); thread.join(); alSourceStop(uiSource); alSourcei(uiSource, AL_BUFFER, 0); // Clean up buffers and sources alDeleteSources(1, &uiSource); uiSource = 0; alDeleteBuffers(numBuffers, uiBuffers); ALCcontext* pContext = alcGetCurrentContext(); ALCdevice* pDevice = alcGetContextsDevice(pContext); alcMakeContextCurrent(nullptr); alcDestroyContext(pContext); alcCloseDevice(pDevice); }
static void printALCInfo (void) { ALCint major, minor; ALCdevice *device; if (alcIsExtensionPresent (NULL, (const ALCchar *) "ALC_ENUMERATION_EXT") == AL_TRUE) { printDevices (ALC_DEVICE_SPECIFIER, ""); printDevices (ALC_CAPTURE_DEVICE_SPECIFIER, "capture "); } else { printf ("no device enumeration available\n"); } device = alcGetContextsDevice (alcGetCurrentContext ()); checkForErrors (); printf ("default device: %s\n", getStringALC (device, ALC_DEFAULT_DEVICE_SPECIFIER)); printf ("default capture device: %s\n", getStringALC (device, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)); alcGetIntegerv (device, ALC_MAJOR_VERSION, 1, &major); alcGetIntegerv (device, ALC_MAJOR_VERSION, 1, &minor); checkForErrors (); printf ("ALC version: %d.%d\n", (int) major, (int) minor); printExtensions ("ALC extensions", ' ', getStringALC (device, ALC_EXTENSIONS)); }
/* alcMakeContextCurrent Makes the given Context the active Context */ ALCAPI ALCboolean ALCAPIENTRY alcMakeContextCurrent(ALCcontext *context) { ALCcontext *ALContext; ALboolean bReturn = AL_TRUE; SuspendContext(NULL); // context must be a valid Context or NULL if ((IsContext(context)) || (context == NULL)) { if ((ALContext=alcGetCurrentContext())) { SuspendContext(ALContext); ALContext->InUse=AL_FALSE; ProcessContext(ALContext); } if ((ALContext=context) && (ALContext->Device)) { SuspendContext(ALContext); ALContext->InUse=AL_TRUE; ProcessContext(ALContext); } } else { SetALCError(ALC_INVALID_CONTEXT); bReturn = AL_FALSE; } ProcessContext(NULL); return bReturn; }
//-----------------------------------------------------------------// void audio_io::alc_info() const { if(alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATION_EXT") == AL_TRUE) { if(alcIsExtensionPresent(NULL, (const ALCchar*)"ALC_ENUMERATE_ALL_EXT") == AL_TRUE) { printDevices(ALC_ALL_DEVICES_SPECIFIER, "playback "); } else { printDevices(ALC_DEVICE_SPECIFIER, "playback "); printDevices(ALC_CAPTURE_DEVICE_SPECIFIER, "capture "); } } else { std::cout << boost::format("No device enumeration available\n"); } ALCdevice* device = alcGetContextsDevice(alcGetCurrentContext()); checkForErrors(); std::cout << boost::format("Default device: %s\n") % alcGetString(device, ALC_DEFAULT_DEVICE_SPECIFIER); std::cout << boost::format("Default capture device: %s\n") % alcGetString(device, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER); ALCint major, minor; alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major); alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor); checkForErrors(); std::cout << boost::format("ALC version: %d.%d\n") % static_cast<int>(major) % static_cast<int>(minor); printExtensions("ALC extensions", ' ', alcGetString(device, ALC_EXTENSIONS)); checkForErrors(); }
//Cleanup of OPENAL system void SoundManager::_releaseAL() { bool success = true; SingletonLogMgr::Instance()->AddNewLine("SoundManager::releaseAL","Releasing sound system..",LOGNORMAL); //Clear all data _releaseALData(); ALCcontext* pCurContext; ALCdevice* pCurDevice; // Get the current context. pCurContext = alcGetCurrentContext(); // Get the device used by that context. pCurDevice = alcGetContextsDevice(pCurContext); // Reset the current context to NULL. if(!alcMakeContextCurrent(NULL)) success = false; // Release the context and the device. alcDestroyContext(pCurContext); if(!alcCloseDevice(pCurDevice)) success = false; if(!success) SingletonLogMgr::Instance()->AddNewLine("SoundManager::releaseAL","Sound system released INCORRECLY",LOGEXCEPTION); else SingletonLogMgr::Instance()->AddNewLine("SoundManager::releaseAL","Sound system released correctly",LOGNORMAL); }
COpenALSound::~COpenALSound() { for (int i = 0; i < maxSounds; i++) { alSourceStop(Sources[i]); alDeleteSources(1,&Sources[i]); } delete[] Sources; map<string, ALuint>::iterator it; for (it = soundMap.begin(); it != soundMap.end(); ++it) { alDeleteBuffers(1, &it->second); } ALCcontext *curcontext = alcGetCurrentContext(); ALCdevice *curdevice = alcGetContextsDevice(curcontext); alcSuspendContext(curcontext); /* * FIXME * Technically you're supposed to detach and destroy the * current context with these two lines, but it deadlocks. * As a not-quite-as-clean shortcut, if we skip this step * and just close the device, OpenAL theoretically * destroys the context associated with that device. * * alcMakeContextCurrent(NULL); * alcDestroyContext(curcontext); */ /* * FIXME * Technically you're supposed to close the device, but * the OpenAL sound thread crashes if we do this manually. * The device seems to be closed automagically anyway. * * alcCloseDevice(curdevice); */ }
ALAPI ALvoid ALAPIENTRY alGetSourcefv(ALuint source,ALenum pname,ALfloat *values) { ALCcontext *Context; ALsource *Source; Context=alcGetCurrentContext(); alcSuspendContext(Context); if (alIsSource(source)) { Source=((ALsource *)source); switch(pname) { case AL_POSITION: case AL_VELOCITY: case AL_DIRECTION: if (Source->param[pname-AL_CONE_INNER_ANGLE].valid) { values[0]=Source->param[pname-AL_CONE_INNER_ANGLE].data.fv3[0]; values[1]=Source->param[pname-AL_CONE_INNER_ANGLE].data.fv3[1]; values[2]=Source->param[pname-AL_CONE_INNER_ANGLE].data.fv3[2]; } break; default: alSetError(AL_INVALID_ENUM); break; } } else alSetError(AL_INVALID_NAME); alcProcessContext(Context); }
ALAPI ALubyte * ALAPIENTRY alGetString(ALenum pname) { ALCcontext *Context; ALubyte *value; Context=alcGetCurrentContext(); alcSuspendContext(Context); switch(pname) { case AL_VENDOR: value=alVendor; break; case AL_VERSION: value=alVersion; break; case AL_RENDERER: value=alRenderer; break; case AL_EXTENSIONS: value=alExtensions; break; default: alSetError(AL_INVALID_VALUE); break; } alcProcessContext(Context); return value; }
ALAPI ALvoid ALAPIENTRY alSourcePlay(ALuint source) { ALCcontext *Context; ALsource *Source; Context=alcGetCurrentContext(); alcSuspendContext(Context); if (alIsSource(source)) { Source=((ALsource *)source); if (Source->state!=AL_PAUSED) { Source->state=AL_PLAYING; Source->inuse=AL_TRUE; Source->play=AL_TRUE; Source->position=0; Source->position_fraction=0; Source->BuffersProcessed = 0; Source->BuffersAddedToDSBuffer = 0; } else { Source->state=AL_PLAYING; Source->inuse=AL_TRUE; Source->play=AL_TRUE; } Source->update1 |= STATE; alcUpdateContext(Context, ALSOURCE, (ALuint)Source); } else alSetError(AL_INVALID_OPERATION); alcProcessContext(Context); }
ALAPI void ALAPIENTRY alBuffer3f(ALuint buffer, ALenum eParam, ALfloat flValue1, ALfloat flValue2, ALfloat flValue3) { ALCcontext *pContext; (void)flValue1; (void)flValue2; (void)flValue3; pContext = alcGetCurrentContext(); SuspendContext(pContext); if (alIsBuffer(buffer) && (buffer != 0)) { switch(eParam) { default: alSetError(AL_INVALID_ENUM); break; } } else { alSetError(AL_INVALID_NAME); } ProcessContext(pContext); }
ALAPI ALvoid ALAPIENTRY alSourcePausev(ALsizei n,ALuint *sources) { ALCcontext *Context; ALsource *Source; ALsizei i; Context=alcGetCurrentContext(); alcSuspendContext(Context); for (i=0;i<n;i++) { if (alIsSource(sources[i])) { Source=((ALsource *)sources[i]); if (Source->state==AL_PLAYING) { Source->state=AL_PAUSED; Source->inuse=AL_FALSE; } Source->update1 |= STATE; alcUpdateContext(Context, ALSOURCE, (ALuint)Source); } else alSetError(AL_INVALID_OPERATION); } alcProcessContext(Context); }
ALAPI void ALAPIENTRY alGetBuffer3i(ALuint buffer, ALenum eParam, ALint* plValue1, ALint* plValue2, ALint* plValue3) { ALCcontext *pContext; pContext = alcGetCurrentContext(); SuspendContext(pContext); if ((plValue1) && (plValue2) && (plValue3)) { if (alIsBuffer(buffer) && (buffer != 0)) { switch(eParam) { default: alSetError(AL_INVALID_ENUM); break; } } else { alSetError(AL_INVALID_NAME); } } else { alSetError(AL_INVALID_VALUE); } ProcessContext(pContext); }
ALAPI ALvoid ALAPIENTRY alSourceStop(ALuint source) { ALCcontext *Context; ALsource *Source; ALbufferlistitem *ALBufferListItem; Context=alcGetCurrentContext(); alcSuspendContext(Context); if (alIsSource(source)) { Source=((ALsource *)source); if (Source->state!=AL_INITIAL) { Source->state=AL_STOPPED; Source->inuse=AL_FALSE; Source->BuffersProcessed = Source->BuffersInQueue; ALBufferListItem= Source->queue; while (ALBufferListItem != NULL) { ALBufferListItem->bufferstate = PROCESSED; ALBufferListItem = ALBufferListItem->next; } } Source->update1 |= STATE; alcUpdateContext(Context, ALSOURCE, (ALuint)Source); } else alSetError(AL_INVALID_OPERATION); alcProcessContext(Context); }
void HGE_Impl::_SoundDone() { CStreamList *stmItem=streams, *stmNext; if(hOpenAL) { for (int i = 0; i < sidcount; i++) alSourceStop(sids[i]); alDeleteSources(sidcount, sids); sidcount = 0; memset(sids, '\0', sizeof (sids)); ALCcontext *ctx = alcGetCurrentContext(); ALCdevice *dev = alcGetContextsDevice(ctx); alcMakeContextCurrent(NULL); alcSuspendContext(ctx); alcDestroyContext(ctx); alcCloseDevice(dev); hOpenAL=0; while(stmItem) { stmNext=stmItem->next; Resource_Free(stmItem->data); delete stmItem; stmItem=stmNext; } streams=0; } }
ALAPI ALvoid ALAPIENTRY alSourceRewindv(ALsizei n,ALuint *sources) { ALCcontext *Context; ALsource *Source; ALsizei i; ALbufferlistitem *ALBufferListItem; Context=alcGetCurrentContext(); alcSuspendContext(Context); for (i=0;i<n;i++) { if (alIsSource(sources[i])) { Source=((ALsource *)sources[i]); if (Source->state!=AL_INITIAL) { Source->state=AL_INITIAL; Source->inuse=AL_FALSE; Source->position=0; Source->position_fraction=0; Source->BuffersProcessed = 0; ALBufferListItem= Source->queue; while (ALBufferListItem != NULL) { ALBufferListItem->bufferstate = PROCESSED; ALBufferListItem = ALBufferListItem->next; } } Source->update1 |= STATE; alcUpdateContext(Context, ALSOURCE, (ALuint)Source); } else alSetError(AL_INVALID_OPERATION); } alcProcessContext(Context); }
AL_API void OPENAL_Close() { if (!initialized) return; ALCcontext *ctx = alcGetCurrentContext(); if (ctx) { for (int i = 0; i < num_channels; i++) { alSourceStop(channels[i].sid); alSourcei(channels[i].sid, AL_BUFFER, 0); alDeleteSources(1, &channels[i].sid); } ALCdevice *dev = alcGetContextsDevice(ctx); alcMakeContextCurrent(NULL); alcSuspendContext(ctx); alcDestroyContext(ctx); alcCloseDevice(dev); } num_channels = 0; delete[] channels; channels = NULL; unload_alsyms(); initialized = false; }
ALboolean _alutSanityCheck (void) { ALCcontext *context; if (initialisationState == Unintialized) { _alutSetError (ALUT_ERROR_INVALID_OPERATION); return AL_FALSE; } context = alcGetCurrentContext (); if (context == NULL) { _alutSetError (ALUT_ERROR_NO_CURRENT_CONTEXT); return AL_FALSE; } if (alGetError () != AL_NO_ERROR) { _alutSetError (ALUT_ERROR_AL_ERROR_ON_ENTRY); return AL_FALSE; } if (alcGetError (alcGetContextsDevice (context)) != ALC_NO_ERROR) { _alutSetError (ALUT_ERROR_ALC_ERROR_ON_ENTRY); return AL_FALSE; } return AL_TRUE; }
ALvoid AL_APIENTRY alGetFilteri(ALuint filter, ALenum param, ALint *piValue) { ALCcontext *Context; Context = alcGetCurrentContext(); SuspendContext(Context); if (filter && alIsFilter(filter)) { ALfilter *ALFilter = (ALfilter*)ALTHUNK_LOOKUPENTRY(filter); switch(param) { case AL_FILTER_TYPE: *piValue = ALFilter->type; break; default: alSetError(AL_INVALID_ENUM); break; } } else alSetError(AL_INVALID_NAME); ProcessContext(Context); }
//Function to clean and delete sound files void Openal::clean_al() { //clear source alDeleteSources(1, &alSource[0]); alDeleteSources(1, &alSource[1]); alDeleteSources(1, &alSource[2]); alDeleteSources(1, &alSource[3]); alDeleteSources(1, &alSource[4]); alDeleteSources(1, &alSource[5]); //clear buffer alDeleteBuffers(1, &alBuffer0); alDeleteBuffers(1, &alBuffer1); alDeleteBuffers(1, &alBuffer2); alDeleteBuffers(1, &alBuffer3); alDeleteBuffers(1, &alBuffer4); alDeleteBuffers(1, &alBuffer5); for (int i = 0; i < 5; i++) { alDeleteSources(1, &dinoSour[i]); alDeleteBuffers(1, &dinoBuff[i]); } ALCcontext *Context = alcGetCurrentContext(); ALCdevice *Device = alcGetContextsDevice(Context); alcMakeContextCurrent(NULL); alcDestroyContext(Context); alcCloseDevice(Device); }
void Sound::Impl::DoFrame() { if (!m_initialized) return; ALint state; int num_buffers_processed; if (alcGetCurrentContext() && (m_music_name.size() > 0)) { alGetSourcei(m_sources[0], AL_BUFFERS_PROCESSED, &num_buffers_processed); while (num_buffers_processed > 0) { ALuint buffer_name_yay; alSourceUnqueueBuffers (m_sources[0], 1, &buffer_name_yay); if (RefillBuffer(&m_ogg_file, m_ogg_format, m_ogg_freq, buffer_name_yay, BUFFER_SIZE, m_music_loops)) { m_music_name.clear(); // m_music_name.clear() must always be called before ov_clear. Otherwise break; /// this happens if RefillBuffer returns 1, meaning it encountered EOF and the file shouldn't be repeated } alSourceQueueBuffers(m_sources[0], 1, &buffer_name_yay); num_buffers_processed--; } alGetSourcei(m_sources[0], AL_SOURCE_STATE, &state); if (state == AL_STOPPED) /// this may happen if the source plays all its buffers before we manage to refill them alSourcePlay(m_sources[0]); } }
AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param, ALfloat flValue) { ALCcontext *Context; Context = alcGetCurrentContext(); if(!Context) { alSetError(AL_INVALID_OPERATION); return; } SuspendContext(Context); if (alIsAuxiliaryEffectSlot(effectslot)) { ALeffectslot *ALEffectSlot = (ALeffectslot*)ALTHUNK_LOOKUPENTRY(effectslot); switch(param) { case AL_EFFECTSLOT_GAIN: if(flValue >= 0.0f && flValue <= 1.0f) ALEffectSlot->Gain = flValue; else alSetError(AL_INVALID_VALUE); break; default: alSetError(AL_INVALID_ENUM); break; } } else alSetError(AL_INVALID_NAME); ProcessContext(Context); }