void ALSources::init() { bool zerocheck; for(ALuint i=0;i<MAX_ENGINE_SOURCES;i++) { zerocheck = alIsSource(0); // Apparently 0 can be a valid source name alGenSources(1, sources + i); if((zerocheck && !sources[i]) || (!alIsSource(sources[i]))) { alGetError(); break; } NUM_SOURCES++; } }
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); }
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 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 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 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 OpenAL::unsubscribeOutput(uint& sid) { QMutexLocker locker(&audioLock); outSources.removeAll(sid); if (sid) { if (alIsSource(sid)) { // stop playing, marks all buffers as processed alSourceStop(sid); // unqueue all buffers from the source ALint processed = 0; alGetSourcei(sid, AL_BUFFERS_PROCESSED, &processed); ALuint* bufids = new ALuint[processed]; alSourceUnqueueBuffers(sid, processed, bufids); // delete all buffers alDeleteBuffers(processed, bufids); delete[] bufids; alDeleteSources(1, &sid); qDebug() << "Audio source" << sid << "deleted. Sources active:" << outSources.size(); } else { qWarning() << "Trying to delete invalid audio source" << sid; } sid = 0; } if (outSources.isEmpty()) cleanupOutput(); }
void OpenALBackend::Pause() { AUDIT(alIsSource(m_source)); alSourcePause(m_source); checkForAlError("Pause->alSourcePause"); }
bool OpenALBackend::AddData(const void* src, u32 num_samples) { AUDIT(alIsSource(m_source)); // Unqueue processed buffers, if any unqueue_processed(); // Fail if there are no free buffers remaining if (m_num_unqueued == 0) { LOG_WARNING(GENERAL, "XAudio2Backend : no unqueued buffers remaining"); return false; } // Copy data to the next available buffer alBufferData(m_buffers[m_next_buffer], m_format, src, num_samples * m_sample_size, m_sampling_rate); checkForAlError("AddData->alBufferData"); // Enqueue buffer alSourceQueueBuffers(m_source, 1, &m_buffers[m_next_buffer]); checkForAlError("AddData->alSourceQueueBuffers"); m_num_unqueued--; m_next_buffer = (m_next_buffer + 1) % m_num_buffers; return true; }
void audioFinish() { if (voicemsgs) { delete voicemsgs; } alSourceStop(notifySource); if (alIsBuffer(notifyBuffer)) { alDeleteBuffers(1, ¬ifyBuffer); notifyBuffer = 0; } if (alIsSource(notifySource)) { alDeleteSources(1, ¬ifySource); notifySource = 0; } if (audioContext) { alcMakeContextCurrent(NULL); alcDestroyContext(audioContext); audioContext = 0; } if (audioDevice) { alcCloseDevice(audioDevice); audioDevice = 0; } }
source(EASYRPG_SHARED_PTR<ALCcontext> const& c, ALuint const s) : ctx_(c), src_(s), loop_count_(0), fade_milli_(0) , volume_(1.0f), is_fade_in_(false) { SET_CONTEXT(c); BOOST_ASSERT(alIsSource(s) == AL_TRUE); }
void CSoundRender_TargetA::_destroy () { // clean up target if (alIsSource(pSource)) alDeleteSources (1, &pSource); A_CHK(alDeleteBuffers (sdef_target_count, pBuffers)); }
StreamTrack::StreamTrack(audio::Engine* engine) : m_audioEngine(engine) { alGenBuffers(m_buffers.size(), m_buffers.data()); // Generate all buffers at once. DEBUG_CHECK_AL_ERROR(); alGenSources(1, &m_source); DEBUG_CHECK_AL_ERROR(); if(!alIsSource(m_source)) { BOOST_LOG_TRIVIAL(error) << BOOST_CURRENT_FUNCTION << ": Could not create source"; return; } alSource3f(m_source, AL_POSITION, 0.0f, 0.0f, -1.0f); // OpenAL tut says this. DEBUG_CHECK_AL_ERROR(); alSource3f(m_source, AL_VELOCITY, 0.0f, 0.0f, 0.0f); DEBUG_CHECK_AL_ERROR(); alSource3f(m_source, AL_DIRECTION, 0.0f, 0.0f, 0.0f); DEBUG_CHECK_AL_ERROR(); alSourcef(m_source, AL_ROLLOFF_FACTOR, 0.0f); DEBUG_CHECK_AL_ERROR(); alSourcei(m_source, AL_SOURCE_RELATIVE, AL_TRUE); DEBUG_CHECK_AL_ERROR(); alSourcei(m_source, AL_LOOPING, AL_FALSE); // No effect, but just in case... DEBUG_CHECK_AL_ERROR(); }
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); }
// can be called at any moment when audio error void CloseAudioPlaybackDevice() { if (!AudioDevice) return; LOG(("Audio Info: closing audio playback device")); if (alIsSource(DefaultNotify.source)) { alSourceStop(DefaultNotify.source); alSourcei(DefaultNotify.source, AL_BUFFER, AL_NONE); alDeleteBuffers(1, &DefaultNotify.buffer); alDeleteSources(1, &DefaultNotify.source); } DefaultNotify.buffer = 0; DefaultNotify.source = 0; if (mixer()) { mixer()->detachTracks(); } if (AudioContext) { alcMakeContextCurrent(nullptr); alcDestroyContext(AudioContext); AudioContext = nullptr; } if (AudioDevice) { alcCloseDevice(AudioDevice); AudioDevice = nullptr; } }
ALAPI ALvoid ALAPIENTRY alQueuef (ALuint source, ALenum param, ALfloat value) { if (alIsSource(source)) { switch(param) { case AL_PITCH: if ((value>=0.5f)&&(value<=2.0f)) { // ***** gSource[source].pitch = value; } else alSetError(AL_INVALID_VALUE); break; case AL_GAIN: if (value <= 1.0f) { // ***** smSetSourceVolume (source, (value * kFullVolume), (value * kFullVolume)); } break; default: alSetError(AL_INVALID_OPERATION); break; } } else { alSetError(AL_INVALID_NAME); } }
bool StreamTrack::unload() { bool result = false; if(alIsSource(m_source)) // Stop and unlink all associated buffers. { int queued; alGetSourcei(m_source, AL_BUFFERS_QUEUED, &queued); DEBUG_CHECK_AL_ERROR(); while(queued--) { ALuint buffer; alSourceUnqueueBuffers(m_source, 1, &buffer); DEBUG_CHECK_AL_ERROR(); } } if(m_sndFile) { sf_close(m_sndFile); m_sndFile = nullptr; result = true; } if(m_wadFile) { fclose(m_wadFile); m_wadFile = nullptr; result = true; } return result; }
void al_issource( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { if (NULL == alIsSource) mogl_glunsupported("alIsSource"); plhs[0]=mxCreateDoubleMatrix(1,1,mxREAL); *mxGetPr(plhs[0])=(double)alIsSource((ALuint)mxGetScalar(prhs[0])); }
ALAPI ALvoid ALAPIENTRY alGetSourcef (ALuint source, ALenum pname, ALfloat *value) { if (alIsSource(source)) { switch(pname) { case AL_PITCH: *value = gSource[source].pitch; break; case AL_GAIN: *value = gSource[source].gain; break; case AL_MAX_DISTANCE: *value = gSource[source].maxDistance; break; case AL_MIN_GAIN: *value = gSource[source].minGain; break; case AL_MAX_GAIN: *value = gSource[source].maxGain; break; case AL_ROLLOFF_FACTOR: *value = gSource[source].rolloffFactor; break; case AL_REFERENCE_DISTANCE: *value = gSource[source].referenceDistance; break; default: alSetError(AL_INVALID_ENUM); break; } } }
ALAPI ALvoid ALAPIENTRY alGetSourcefv (ALuint source, ALenum pname, ALfloat *values) { if (alIsSource(source)) { switch(pname) { case AL_POSITION: values[0] = gSource[source].Position[0]; values[1] = gSource[source].Position[1]; values[2] = gSource[source].Position[2]; break; case AL_VELOCITY: values[0] = gSource[source].Velocity[0]; values[1] = gSource[source].Velocity[1]; values[2] = gSource[source].Velocity[2]; break; case AL_DIRECTION: alSetError(AL_INVALID_ENUM); break; default: alSetError(AL_INVALID_ENUM); break; } } }
/* ======================== idSoundVoice_OpenAL::FlushSourceBuffers ======================== */ void idSoundVoice_OpenAL::FlushSourceBuffers() { if( alIsSource( openalSource ) ) { //pSourceVoice->FlushSourceBuffers(); } }
/* =================== idSoundChannel::ALStop =================== */ void idSoundChannel::ALStop( void ) { if ( idSoundSystemLocal::useOpenAL ) { if ( alIsSource( openalSource ) ) { alSourceStop( openalSource ); alSourcei( openalSource, AL_BUFFER, 0 ); soundSystemLocal.FreeOpenALSource( openalSource ); } if ( openalStreamingBuffer[0] && openalStreamingBuffer[1] && openalStreamingBuffer[2] ) { alGetError(); alDeleteBuffers( 3, &openalStreamingBuffer[0] ); if ( alGetError() == AL_NO_ERROR ) { openalStreamingBuffer[0] = openalStreamingBuffer[1] = openalStreamingBuffer[2] = 0; } } if ( lastopenalStreamingBuffer[0] && lastopenalStreamingBuffer[1] && lastopenalStreamingBuffer[2] ) { alGetError(); alDeleteBuffers( 3, &lastopenalStreamingBuffer[0] ); if ( alGetError() == AL_NO_ERROR ) { lastopenalStreamingBuffer[0] = lastopenalStreamingBuffer[1] = lastopenalStreamingBuffer[2] = 0; } } } }
bool OpenAL::IsSource(ALuint source) { if(!IsInitialized()) return false; return alIsSource(source) == AL_TRUE; }
void oggLoad( SOggSound* o, const char* name ) { // file opening o->file = fopen( name, "rb"); if( !o->file ) { printf( "Sound error : %s !!!\n", name ); return; } // with file, we open a ogg-vorbis stream if( ov_open( o->file, &o->stream, NULL, 0) ) { printf( "Sound error : ogg stream error !!!\n" ); return; } o->format = o->stream.vi->channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; if( !alIsSource( o->source ) ) { alGenSources( 1, &o->source ); //printf( "create source.\n" ); } soundCheckErrorAL( "load ogg" ); soundCheckErrorALC( "load ogg" ); }
const i32 audio_vorbisStop(MemoryArena_ *arena, AudioManager *audioManager, AudioRenderer *audioRenderer) { i32 result = 0; u32 alSourceId = getSourceId(audioManager, audioRenderer); if (alIsSource(alSourceId) == AL_TRUE) { alSourceStop(alSourceId); AL_CHECK_ERROR(); result = rendererRelease(arena, audioManager, audioRenderer); audioRenderer->state = audiostate_stopped; } else { #ifdef DENGINE_DEBUG if (audioRenderer->audio) { DEBUG_LOG( "audio_streamStopVorbis(): Tried to stop invalid source, but " "renderer has valid audio ptr"); } #endif result = -1; } return result; }
KgPlaybackEvent::~KgPlaybackEvent() { if(alIsSource(m_source) == AL_TRUE) { alSourceStop(m_source); alDeleteSources(1, &m_source); } }
void StreamTrack::stop() // Immediately stop track. { if(alIsSource(m_source) && isPlaying()) { alSourceStop(m_source); DEBUG_CHECK_AL_ERROR(); } }
void sound::close() { alSourceStop(m_source_id); if(alIsSource(m_source_id)) { ALuint source_id = m_source_id; alDeleteSources(1, &source_id); m_source_id = source_id; } }
bool SimpleAudioEngine::willPlayBackgroundMusic() { // We are able to play background music // if we have a valid background source if (s_backgroundSource == AL_NONE) return false; return (alIsSource(s_backgroundSource) == AL_TRUE ? true : false); }
void OpenALThread::Close() { alSourceStop(m_source); checkForAlError("alSourceStop"); if (alIsSource(m_source)) alDeleteSources(1, &m_source); alDeleteBuffers(g_al_buffers_count, m_buffers); checkForAlError("alDeleteBuffers"); }