Beispiel #1
0
void SoundManager::poll()
{
    static ticks_t lastUpdate = 0;
    ticks_t now = g_clock.millis();

    if(now - lastUpdate < POLL_DELAY)
        return;

    lastUpdate = now;

    ensureContext();
    for(auto it = m_sources.begin(); it != m_sources.end();) {
        SoundSourcePtr source = *it;

        source->update();

        if(!source->isPlaying())
            it = m_sources.erase(it);
        else
            ++it;
    }

    for(auto it : m_channels) {
        it.second->update();
    }

    if(m_context) {
        alcProcessContext(m_context);
    }
}
Beispiel #2
0
GAudio::~GAudio() 
{
  // clean the device
  Clean();

  // push any pending data to the hardware
  if(mContext) alcProcessContext(mContext);

  // free all of the channels
  if(mChannels){GDELETE([]mChannels), mChannels = NULL;}

  // destroy the context
  if(mContext)
  {	
    alcDestroyContext(mContext);
    mContext = NULL;
  }

  // close the device
  if(mDevice)
  {	
    alcCloseDevice(mDevice);
    mDevice = NULL;
  }
}
Beispiel #3
0
void AudioDevice::resume()
{
	if (audioContext) {
		alcMakeContextCurrent(audioContext);
		alcProcessContext(audioContext);
	}
}
void
SoundManager::update()
{
  if (!sound_enabled)
    return;

  // check for finished sound sources
  for(SoundSources::iterator i = sources.begin(); i != sources.end(); ) {
    SoundSource* source = *i;
    if(!source->playing()) {
      delete source;
      i = sources.erase(i);
    } else {
      ++i;
    }
  }
  // check streaming sounds
  if(music_source) {
    music_source->update();
  }
  
  if(next_music_source && (!music_source || !music_source->playing())) {
    delete music_source;
    music_source = next_music_source;
    //music_source->setFading(StreamSoundSource::FadingOn, 1.0f);
    music_source->play();
    next_music_source = 0;
  }
  
  alcProcessContext(context);
  check_alc_error("Error while processing audio context: ");
}
Beispiel #5
0
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);
}
Beispiel #6
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);
}
Beispiel #7
0
value lime_alc_process_context (value context) {

    ALCcontext* alcContext = (ALCcontext*)(intptr_t)val_float (context);
    alcProcessContext (alcContext);
    return alloc_null ();

}
Beispiel #8
0
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);
}
Beispiel #9
0
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);
}
void
SoundManager::update()
{
  static float lasttime = real_time;

  if(real_time - lasttime < 0.3)
    return;
  lasttime = real_time;

  // update and check for finished sound sources
  for(SoundSources::iterator i = sources.begin(); i != sources.end(); ) {
    SoundSource* source = *i;

    source->update();
    
    if(!source->playing()) {
      delete source;
      i = sources.erase(i);
    } else {
      ++i;
    }
  }
  // check streaming sounds
  if(music_source) {
    music_source->update();
  }
  
  alcProcessContext(context);
  check_alc_error("Error while processing audio context: ");
}
//------------------------------------------------------------
void ofOpenALSoundPlayer::update(ofEventArgs & args){
    if(bMultiPlay){
        for(int i=1; i<int(sources.size())/channels; ){
            ALint state;
            alGetSourcei(sources[i*channels],AL_SOURCE_STATE,&state);
            if(state != AL_PLAYING){
                alDeleteSources(channels,&sources[i*channels]);
                for(int j=0;j<channels;j++){
                    sources.erase(sources.begin()+i*channels);
                }
            }else{
                i++;
            }
        }
    }
    
    
    if(alContext != NULL){
        alcProcessContext(alContext);
    }
    
    checkErrors("ofOpenALSoundPlayer::update");
                
    timeSet = false;
}
Beispiel #12
0
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 SoundManager::poll()
{
    static ticks_t lastUpdate = 0;
    ticks_t now = g_clock.millis();

    if(now - lastUpdate < POLL_DELAY)
        return;

    lastUpdate = now;

    for(auto it = m_sources.begin(); it != m_sources.end();) {
        SoundSourcePtr source = *it;

        source->update();

        if(!source->isPlaying())
            it = m_sources.erase(it);
        else
            ++it;
    }

    if(m_musicSource) {
        m_musicSource->update();
        if(!m_musicSource->isPlaying())
            m_musicSource = nullptr;
    }

    if(m_context) {
        alcProcessContext(m_context);
    }
}
Beispiel #14
0
AUD_OpenALDevice::~AUD_OpenALDevice()
{
	lock();
	alcSuspendContext(m_context);

	while(!m_playingSounds.empty())
		m_playingSounds.front()->stop();

	while(!m_pausedSounds.empty())
		m_pausedSounds.front()->stop();


	// delete all buffered factories
	/*while(!m_bufferedFactories->empty())
	{
		alDeleteBuffers(1, &(*(m_bufferedFactories->begin()))->buffer);
		delete *m_bufferedFactories->begin();
		m_bufferedFactories->erase(m_bufferedFactories->begin());
	}*/

	alcProcessContext(m_context);

	// wait for the thread to stop
	unlock();
	pthread_join(m_thread, NULL);

	//delete m_bufferedFactories;

	// quit OpenAL
	alcMakeContextCurrent(NULL);
	alcDestroyContext(m_context);
	alcCloseDevice(m_device);

	pthread_mutex_destroy(&m_mutex);
}
 int ChannelStream::Init()
 {
     ALCcontext *context;
     ALCdevice *device;
     
     if ((device = alcOpenDevice(NULL)) == NULL) {
         fprintf(stderr, "failed to open sound device\n");
         return -1;
     }
     
     s_device = device;
     
     context = alcCreateContext(device, NULL);
     alcMakeContextCurrent(context);
     alcProcessContext(context);
     
     s_context = context;
     
     atexit(__alexit);
     
     /* allocate buffers and sources here using alGenBuffers() and alGenSources() */
     /* ... */
     
     alGetError();    /* clear any AL errors beforehand */
     return 0;	
 }
Beispiel #16
0
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;
}
Beispiel #17
0
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);
}
Beispiel #18
0
void AudioHandlerAl::OnInterruptEnd()
{
  if (context_)
  {
    alcMakeContextCurrent(context_);
    alcProcessContext(context_);
  }
}
Beispiel #19
0
void CALL HGE_Impl::Channel_ResumeAll()
{
	if(hOpenAL)
	{
		ALCcontext *ctx = alcGetCurrentContext();
		alcProcessContext(ctx);
	}
}
Beispiel #20
0
void csSndSysRendererOpenAL::Open()
{
  ScopedRendererLock lock (*this);

  // First assume we have both a config and a device, but no context.
  CS_ASSERT (m_Config != 0);
  CS_ASSERT (m_Device != 0);
  CS_ASSERT (m_Context == 0);

  Report (CS_REPORTER_SEVERITY_DEBUG, "Opening OpenAL sound system");

  // Clear any error condition
  alcGetError (m_Device);

  // Setup the attribute list for the OpenAL context
  const ALCint attr[] =
  {
    ALC_REFRESH,   m_Config->GetInt ("SndSys.OpenALRefresh", 10),    // How often do we update the mixahead buffer (hz).
    ALC_SYNC,      AL_FALSE,                                         // We want an asynchronous context.
    ALC_STEREO_SOURCES, 12,
    ALC_MONO_SOURCES, 120,
    0
  };
  // Note: If the sound is choppy, it may be because your OpenAL
  //       implementation does not implement async (threaded) contexts and
  //       your framerate is below SndSys.OpenALRefresh. If this is the case,
  //       please try to decrease SndSys.OpenALRefresh to below your
  //       framerate. This however will increase sound latency. Alternatively
  //       you may attempt to implement the async operation in CS.

  // Get an OpenAL context
  m_Context = alcCreateContext (m_Device, attr);
  if (m_Context == 0)
  {
    Report (CS_REPORTER_SEVERITY_ERROR, "Unable to get OpenAL context");
    CS_ASSERT (m_Context != 0);
  }

  // Make our new context current
  alcMakeContextCurrent (m_Context);

  // Set the context processing
  alcProcessContext (m_Context);

  // Check for any errors
  ALCenum err = alcGetError (m_Device);
  if (err != ALC_NO_ERROR)
  {
    Report (CS_REPORTER_SEVERITY_ERROR, "An OpenAL error occured: %s", alcGetString (m_Device, err));
    CS_ASSERT (err == ALC_NO_ERROR);
  }

  // Query available extensions
  QueryExtensions ();

  // Create a listener
  m_Listener.AttachNew(new SndSysListenerOpenAL());
}
 void ChannelStream::InterruptEnd()
 {
     // Restore open al context
     alcMakeContextCurrent(s_context);
     // 'unpause' my context
     alcProcessContext(s_context);
     
     Check("InterruptEnd()");
 }
void FALAudioDevice::TeardownHardware( void )
{
	// Push any pending data to the hardware
	if( &alcProcessContext )
	{
		alcProcessContext( SoundContext );
	}

	// Destroy all sound sources
	for( int32 i = 0; i < Sources.Num(); i++ )
	{
		delete Sources[ i ];
	}
	Sources.Empty();
	FreeSources.Empty();

	// Destroy OpenAL buffers associated with this audio device
	FAudioDeviceManager* AudioDeviceManager = GEngine->GetAudioDeviceManager();
	check(AudioDeviceManager != nullptr);
	for( int32 i = 0; i < AudioDeviceManager->Buffers.Num(); i++ )
	{
		FALSoundBuffer* Buffer = static_cast<FALSoundBuffer*>(AudioDeviceManager->Buffers[i]);
		if( Buffer->AudioDevice == this )
		{
			alDeleteBuffers(1, &Buffer->BufferId);
			Buffer->AudioDevice = nullptr;
			Buffer->BufferId = 0;
		}
	}

	// Disable the context
	if( &alcMakeContextCurrent )
	{
		alcMakeContextCurrent(nullptr);
	}

	// Destroy the context
	if( &alcDestroyContext )
	{
		alcDestroyContext( SoundContext );
		SoundContext = NULL;
	}

	// Close the hardware device
	if( &alcCloseDevice )
	{
		if (HardwareDevice)
		{
			const ALCchar* DeviceName = alcGetString(HardwareDevice, ALC_DEVICE_SPECIFIER);
			UE_LOG(LogALAudio, Log, TEXT("Closing ALAudio device : %s"), StringCast<TCHAR>(static_cast<const ANSICHAR*>(DeviceName)).Get());

			alcCloseDevice(HardwareDevice);
			HardwareDevice = nullptr;
		}
	}

}
Beispiel #23
0
AUD_Reference<AUD_IHandle> AUD_OpenALDevice::play(AUD_Reference<AUD_IReader> reader, bool keep)
{
	AUD_Specs specs = reader->getSpecs();

	// check format
	if(specs.channels == AUD_CHANNELS_INVALID)
		return AUD_Reference<AUD_IHandle>();

	if(m_specs.format != AUD_FORMAT_FLOAT32)
		reader = new AUD_ConverterReader(reader, m_specs);

	ALenum format;

	if(!getFormat(format, specs))
		return AUD_Reference<AUD_IHandle>();

	lock();
	alcSuspendContext(m_context);

	AUD_Reference<AUD_OpenALDevice::AUD_OpenALHandle> sound;

	try
	{
		// create the handle
		sound = new AUD_OpenALDevice::AUD_OpenALHandle(this, format, reader, keep);
	}
	catch(AUD_Exception&)
	{
		alcProcessContext(m_context);
		unlock();
		throw;
	}

	alcProcessContext(m_context);

	// play sound
	m_playingSounds.push_back(sound);

	start();

	unlock();

	return AUD_Reference<AUD_IHandle>(sound);
}
Beispiel #24
0
std::shared_ptr<IHandle> OpenALDevice::play(std::shared_ptr<IReader> reader, bool keep)
{
	Specs specs = reader->getSpecs();

	// check format
	if(specs.channels == CHANNELS_INVALID)
		return std::shared_ptr<IHandle>();

	if(m_specs.format != FORMAT_FLOAT32)
		reader = std::shared_ptr<IReader>(new ConverterReader(reader, m_specs));

	ALenum format;

	if(!getFormat(format, specs))
		return std::shared_ptr<IHandle>();

	std::lock_guard<std::recursive_mutex> lock(m_mutex);

	alcSuspendContext(m_context);

	std::shared_ptr<OpenALDevice::OpenALHandle> sound;

	try
	{
		// create the handle
		sound = std::shared_ptr<OpenALDevice::OpenALHandle>(new OpenALDevice::OpenALHandle(this, format, reader, keep));
	}
	catch(Exception&)
	{
		alcProcessContext(m_context);
		throw;
	}

	alcProcessContext(m_context);

	// play sound
	m_playingSounds.push_back(sound);

	start();

	return std::shared_ptr<IHandle>(sound);
}
Beispiel #25
0
static PyObject*
_context_process (PyObject *self)
{
    PyContext *ctxt = (PyContext*) self;

    CLEAR_ALCERROR_STATE ();
    alcProcessContext (ctxt->context);
    if (SetALCErrorException (alcGetError
        (PyDevice_AsDevice (ctxt->device)), 0))
        return NULL;
    Py_RETURN_NONE;
}
Beispiel #26
0
void InitSound()
{
	device = alcOpenDevice(NULL);
	if(!device)
		return;
	context = alcCreateContext(device, NULL);
	if(!context)
		return;
	alcMakeContextCurrent(context);
	alcProcessContext(context);
	source_mixed.Init();
}
Beispiel #27
0
ALAPI ALvoid ALAPIENTRY alGetSourcei(ALuint source,ALenum pname,ALint *value)
{
	ALCcontext *Context;
	ALsource *Source;

	Context=alcGetCurrentContext();
	alcSuspendContext(Context);
	if (alIsSource(source))
	{
		Source=((ALsource *)source);
		switch(pname) 
		{
			case AL_SOURCE_RELATIVE:
				*value=Source->relative;
				break;
			case AL_CONE_INNER_ANGLE:
			case AL_CONE_OUTER_ANGLE:
				if (Source->param[pname-AL_CONE_INNER_ANGLE].valid)
					*value=(ALint)Source->param[pname-AL_CONE_INNER_ANGLE].data.f;
				break;
			case AL_LOOPING:
				if (Source->param[pname-AL_CONE_INNER_ANGLE].valid)
					*value = Source->param[pname-AL_CONE_INNER_ANGLE].data.i;
				else
					*value = 0;
				break;
			case AL_BUFFER:
				// Call UpdateContext to retrieve up-to-date information about the current buffer
				Source->update1 |= SUPDATEBUFFERS;
				alcUpdateContext(Context, ALSOURCE, source);

				if (Source->param[pname-AL_CONE_INNER_ANGLE].valid)
					*value=Source->param[pname-AL_CONE_INNER_ANGLE].data.i;
				else
					*value=0;
				break;
			case AL_SOURCE_STATE:
				*value=Source->state;
				break;
			case AL_BUFFERS_QUEUED:
				*value=Source->BuffersInQueue;
				break;
			case AL_BUFFERS_PROCESSED:
				*value=Source->BuffersProcessed;
				break;
			default:
				alSetError(AL_INVALID_ENUM);
				break;
		}
	} 
	else alSetError(AL_INVALID_NAME);
	alcProcessContext(Context);
}
Beispiel #28
0
void AUD_OpenALDevice::stopAll()
{
	lock();
	alcSuspendContext(m_context);

	while(!m_playingSounds.empty())
		m_playingSounds.front()->stop();

	while(!m_pausedSounds.empty())
		m_pausedSounds.front()->stop();

	alcProcessContext(m_context);
	unlock();
}
Beispiel #29
0
ALAPI ALvoid ALAPIENTRY alDisable(ALenum capability)
{
	ALCcontext *Context;

	Context=alcGetCurrentContext();
	alcSuspendContext(Context);
	switch (capability)
	{
		default:
			alSetError(AL_INVALID_ENUM);
			break;
	}
	alcProcessContext(Context);
}
Beispiel #30
0
AL_API signed char OPENAL_Init(int mixrate, int maxsoftwarechannels, unsigned int flags)
{
    if (initialized) return false;
    if (maxsoftwarechannels == 0) return false;

    if (flags != 0)  // unsupported.
        return false;

    if (!lookup_all_alsyms("./openal.so"))  // !!! FIXME: linux specific lib name
    {
        if (!lookup_all_alsyms("openal.so.1"))  // !!! FIXME: linux specific lib name
        {
            if (!lookup_all_alsyms("openal.so"))  // !!! FIXME: linux specific lib name
                return false;
        }
    }

    ALCdevice *dev = alcOpenDevice(NULL);
    if (!dev)
        return false;

    ALint caps[] = { ALC_FREQUENCY, mixrate, 0 };
    ALCcontext *ctx = alcCreateContext(dev, caps);
    if (!ctx)
    {
        alcCloseDevice(dev);
        return false;
    }

    alcMakeContextCurrent(ctx);
    alcProcessContext(ctx);

    bool cmdline(const char *cmd);
    if (cmdline("openalinfo"))
    {
        printf("AL_VENDOR: %s\n", (char *) alGetString(AL_VENDOR));
        printf("AL_RENDERER: %s\n", (char *) alGetString(AL_RENDERER));
        printf("AL_VERSION: %s\n", (char *) alGetString(AL_VERSION));
        printf("AL_EXTENSIONS: %s\n", (char *) alGetString(AL_EXTENSIONS));
    }

    num_channels = maxsoftwarechannels;
    channels = new OPENAL_Channels[maxsoftwarechannels];
    memset(channels, '\0', sizeof (OPENAL_Channels) * num_channels);
    for (int i = 0; i < num_channels; i++)
        alGenSources(1, &channels[i].sid);  // !!! FIXME: verify this didn't fail!

    initialized = true;
    return true;
}