Beispiel #1
0
AudioManager::~AudioManager()
{
    MusicStop();

    if(m_Initialized)
    {
        m_ThreadContinue = false;
        m_UpdateThread->join();
        delete m_UpdateThread;
        delete[] m_Buffer;

        alcMakeContextCurrent(nullptr);
        alcDestroyContext(m_ALContext);
        alcCloseDevice(m_ALDevice);
        LOG_TRIVIAL("AudioManager destroyed.");
    }
}
Beispiel #2
0
void audio_output::deinit()
{
    if (_initialized)
    {
        do
        {
            alGetSourcei(_source, AL_SOURCE_STATE, &_state);
        }
        while (alGetError() == AL_NO_ERROR && _state == AL_PLAYING);
        alDeleteSources(1, &_source);
        alDeleteBuffers(_num_buffers, &(_buffers[0]));
        alcMakeContextCurrent(NULL);
        alcDestroyContext(_context);
        alcCloseDevice(_device);
        _initialized = false;
    }
}
Beispiel #3
0
void audio_close()
{
    
    ALCdevice *device = NULL;
    ALCcontext *context = NULL;
    // Exit
    context=alcGetCurrentContext();
    if (context)
    {
        device=alcGetContextsDevice(context);
        alcMakeContextCurrent(NULL);
        alcDestroyContext(context);
        if (device)
            alcCloseDevice(device);
    }

}
// close audio device
static void uninit(int immed) {
  ALCcontext *ctx = alcGetCurrentContext();
  ALCdevice *dev = alcGetContextsDevice(ctx);
  free(tmpbuf);
  if (!immed) {
    ALint state;
    alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
    while (state == AL_PLAYING) {
      usec_sleep(10000);
      alGetSourcei(sources[0], AL_SOURCE_STATE, &state);
    }
  }
  reset();
  alcMakeContextCurrent(NULL);
  alcDestroyContext(ctx);
  alcCloseDevice(dev);
}
Beispiel #5
0
ALboolean
alutExit (void)
{
  ALCdevice *device;

  if (initialisationState == Unintialized)
    {
      _alutSetError (ALUT_ERROR_INVALID_OPERATION);
      return AL_FALSE;
    }

  if (initialisationState == ExternalDeviceAndContext)
    {
      initialisationState = Unintialized;
      return AL_TRUE;
    }

  if (!_alutSanityCheck ())
    {
      return AL_FALSE;
    }

  if (!alcMakeContextCurrent (NULL))
    {
      _alutSetError (ALUT_ERROR_MAKE_CONTEXT_CURRENT);
      return AL_FALSE;
    }

  device = alcGetContextsDevice (alutContext);
  alcDestroyContext (alutContext);
  if (alcGetError (device) != ALC_NO_ERROR)
    {
      _alutSetError (ALUT_ERROR_DESTROY_CONTEXT);
      return AL_FALSE;
    }

  if (!alcCloseDevice (device))
    {
      _alutSetError (ALUT_ERROR_CLOSE_DEVICE);
      return AL_FALSE;
    }

  initialisationState = Unintialized;
  return AL_TRUE;
}
	void SoundEngineOpenAL::destroy()
	{
		// Stop thread
		running = false;
		while (!threadstopped)
			usleep(1000);
		// Delete listener
		if (listener)
			delete listener;
		// Delete recorders
		while (recorders.size() != 0)
			recorders[0]->destroy();
		// Delete sources
		std::map<std::string, SoundSource*>::iterator it = sources.begin();
		while (it != sources.end())
		{
			it->second->drop();
			it++;
		}
		// Delete sounds
		for (unsigned int i = 0; i < sounds.size(); i++)
		{
			sounds[i]->drop();
		}
		sounds.clear();
		// Destroy OpenAL context
		unsigned int error = alGetError();
		if (error != AL_NO_ERROR)
		{
			getLogger()->write(ELL_Error, "AL error on exit: %s!\n",
				getOpenALErrorString(error));
		}
		ALCcontext *context = alcGetCurrentContext();
		ALCdevice *dev = alcGetContextsDevice(context);
		error = alcGetError(dev);
		if (error != AL_NO_ERROR)
		{
			getLogger()->writeLine(ELL_Error, "ALC error on exit!\n");
		}
		alcMakeContextCurrent(0);
		alcDestroyContext(context);
		alcCloseDevice(dev);
		// Delete engine instance
		delete this;
	}
Beispiel #7
0
	void OpenAL::CloseDevice()
	{
		if (s_device)
		{
			if (s_context)
			{
				alcMakeContextCurrent(nullptr);
				alcDestroyContext(s_context);
				s_context = nullptr;
			}

			if (!alcCloseDevice(s_device))
				// We could not close the close, this means that it's still in use
				NazaraWarning("Failed to close device");

			s_device = nullptr;
		}
	}
		void shutdown()
		{
			alcMakeContextCurrent( NULL );
			alcDestroyContext( m_context );
			alcCloseDevice( m_device );

			alutExit();

			OpenALData *data;
			for( auto i = m_buffers.begin(); i != m_buffers.end(); ++i ) {
				BK_DEBUG( "releasing OpenAL Data: " << i->first );
				data = i->second;

				alSourcei( data->m_source, AL_BUFFER, 0 );
				alDeleteBuffers( 1, &(data->m_buffer) );
				alDeleteSources( 1, &(data->m_source) );
			}
		}
Beispiel #9
0
void RemoveSound()
{
    alSourceStop(source);
    checkALError();
    alDeleteSources(1, &source);
    checkALError();
    alDeleteBuffers(BUFFER_QUANTITY, buffers);
    checkALError();
    
    // Reset the current context to NULL.
    alcMakeContextCurrent(NULL);
    checkALCError();
    
    // RELEASE the context and the device.
    alcDestroyContext(pContext);
    checkALCError();
    alcCloseDevice(pDevice);
}
spp_AudioManager::~spp_AudioManager()
{
	//deleting all the stored buffers
	UnloadAllSounds();

	RemoveAllProcessingPlugIns();

	//deleting the listener
	delete mpListener;

	StopDebugMode();

	//closing OpenAL
	alcMakeContextCurrent(NULL);
	alcDestroyContext(mpContext);
	alcCloseDevice(mpDevice);
	alcCaptureCloseDevice(mpRecordingDevice);
}
Beispiel #11
0
void OpenALAudio::deinit_wav()
{
   this->wav_init_flag = false;

   this->stop_wav();

   if (this->al_context != NULL)
   {
      alcDestroyContext(this->al_context);
      this->al_context = NULL;
   }

   if (this->al_device != NULL)
   {
      alcCloseDevice(this->al_device);
      this->al_device = NULL;
   }
}
Beispiel #12
0
	void cOpenALDeviceContext::shutDown()
	{
		if(Initialized)
		{
			cAudioMutexBasicLock lock(Mutex);
			//Reset context to null
			alcMakeContextCurrent(NULL);
			//Delete the context
			alcDestroyContext(Context);
			Context = NULL;
			//Close the device
			alcCloseDevice(Device);
			checkError();

			Device = NULL;
			Initialized = false;
		}
	}
Beispiel #13
0
void exitOpenAL()
{
    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.
    alcMakeContextCurrent(NULL);

    // Release the context and the device.
    alcDestroyContext(pCurContext);
    alcCloseDevice(pCurDevice);
}
Beispiel #14
0
void DoneSound()
{
	if(device && context)
	{
		source_mixed.Done();
	}
	if(context)
	{
		alcMakeContextCurrent(NULL);
		alcDestroyContext(context);
		context = NULL;
	}
	if(device)
	{
		alcCloseDevice(device);
		device = NULL;
	}
}
Beispiel #15
0
SoundManager::~SoundManager( void )
{
  // Delete the sources and buffers
  alDeleteSources( MAX_AUDIO_SOURCES, mAudioSources );
  alDeleteBuffers( MAX_AUDIO_BUFFERS, mAudioBuffers );
  
   // Destroy the sound context and device
   mSoundContext = alcGetCurrentContext();
   mSoundDevice = alcGetContextsDevice( mSoundContext );
   alcMakeContextCurrent( NULL );
   alcDestroyContext( mSoundContext );
   if ( mSoundDevice)
       alcCloseDevice( mSoundDevice );
  
   alutExit();
  
  printf("SoudManager Destroyed.\n");
}
Beispiel #16
0
void SoundManager::deinit() {
	if (!_ready)
		return;

	if (!destroyThread())
		warning("SoundManager::deinit(): Sound thread had to be killed");

	for (uint16 i = 1; i < kChannelCount; i++)
		freeChannel(i);

	if (_hasSound) {
		alcMakeContextCurrent(0);
		alcDestroyContext(_ctx);
		alcCloseDevice(_dev);
	}

	_ready = false;
}
ALvoid  alutExit(ALvoid) 
{
	ALCcontext *Context;
	ALCdevice *Device;

	//Unregister extensions

	//Get active context
	Context=alcGetCurrentContext();
	//Get device for active context
	Device=alcGetContextsDevice(Context);
	//Disable context
	alcMakeContextCurrent(NULL);
	//Release context(s)
	alcDestroyContext(Context);
	//Close device
	alcCloseDevice(Device);
}
Beispiel #18
0
/*! Frees all memory allocated by the sound device
 *
 *  @returns        ICRESULT        Success/failure of the cleanup
**/
ICRESULT icSoundDeviceAL::Cleanup(void)
{
    if (m_bInitialized)
    {
        icSoundI* temp = icMinHeapDequeue(m_Playing, m_NumPlaying--);
        while (temp)
        {
            temp->Stop();
            icMinHeapInsert(m_Sounds,m_NumFreeSounds++,temp);
        }

        ALuint temp_buff[ICSND_MAX_SOURCE];
        ALuint temp_source[ICSND_MAX_PLAYING];

        for (int i=0; i<ICSND_MAX_SOURCE; ++i)
        {
            temp_buff[i] = m_SrcBufs[i].buffID;
            m_SrcBufs[i].buffID = 0;
        }

        for (int i=0; i<ICSND_MAX_PLAYING; ++i)
        {
            temp_source[i] = ((icSoundAL*)m_Sounds[i])->m_ALsource;
            ((icSoundAL*)m_Sounds[i])->m_ALsource = 0;
            ((icSoundAL*)m_Sounds[i])->m_bInitialized = false;

            delete ((icSoundAL*)m_Sounds[i]);
        }

        //Free buffers and source objects
        alDeleteBuffers(ICSND_MAX_SOURCE, temp_buff);
        alDeleteSources(ICSND_MAX_PLAYING, temp_source);

        //Disable context
        alcMakeContextCurrent(NULL);

        //Release context
        alcDestroyContext(m_Context);

        //Close device
        alcCloseDevice(m_Device);
    }
    return IC_OK;
}// END FUNCTION Cleanup(void)
Beispiel #19
0
void ALSound::CleanUp()
{
    if (m_enabled)
    {
        GetLogger()->Info("Unloading files and closing device...\n");
        StopAll();
        StopMusic();

        for (auto channel : m_channels)
        {
            delete channel.second;
        }

        if (m_currentMusic)
        {
            delete m_currentMusic;
        }
        
        for (auto item : m_oldMusic)
        {
            delete item.music;
        }
        
        if (m_previousMusic.music)
        {
            delete m_previousMusic.music;
        }

        for (auto item : m_sounds)
        {
            delete item.second;
        }

        for (auto item : m_music)
        {
            delete item.second;
        }

        m_enabled = false;

        alcDestroyContext(m_context);
        alcCloseDevice(m_device);
    }
}
Beispiel #20
0
Core::Core(Camera* cam, QThread *coreThread) :
    tox(nullptr), camera(cam)
{
    videobuf = new uint8_t[videobufsize];
    videoBusyness=0;

    toxTimer = new QTimer(this);
    toxTimer->setSingleShot(true);
    connect(toxTimer, &QTimer::timeout, this, &Core::process);
    //connect(fileTimer, &QTimer::timeout, this, &Core::fileHeartbeat);
    connect(&Settings::getInstance(), &Settings::dhtServerListChanged, this, &Core::process);
    connect(this, SIGNAL(fileTransferFinished(ToxFile)), this, SLOT(onFileTransferFinished(ToxFile)));

    for (int i=0; i<TOXAV_MAX_CALLS;i++)
    {
        calls[i].sendAudioTimer = new QTimer();
        calls[i].sendVideoTimer = new QTimer();
        calls[i].sendAudioTimer->moveToThread(coreThread);
        calls[i].sendVideoTimer->moveToThread(coreThread);
        connect(calls[i].sendVideoTimer, &QTimer::timeout, [this,i](){sendCallVideo(i);});
    }

    // OpenAL init
    alOutDev = alcOpenDevice(nullptr);
    if (!alOutDev)
    {
        qWarning() << "Core: Cannot open output audio device";
    }
    else
    {
        alContext=alcCreateContext(alOutDev,nullptr);
        if (!alcMakeContextCurrent(alContext))
        {
            qWarning() << "Core: Cannot create output audio context";
            alcCloseDevice(alOutDev);
        }
        else
            alGenSources(1, &alMainSource);
    }
    alInDev = alcCaptureOpenDevice(NULL,av_DefaultSettings.audio_sample_rate, AL_FORMAT_MONO16,
                                   (av_DefaultSettings.audio_frame_duration * av_DefaultSettings.audio_sample_rate * 4) / 1000);
    if (!alInDev)
        qWarning() << "Core: Cannot open input audio device";
}
Beispiel #21
0
static void al_free(void *data)
{
   al_t *al = (al_t*)data;
   if (al)
   {
      alSourceStop(al->source);
      alDeleteSources(1, &al->source);
      if (al->buffers)
      {
         alDeleteBuffers(al->num_buffers, al->buffers);
         free(al->buffers);
         free(al->res_buf);
      }
   }
   alcMakeContextCurrent(NULL);
   alcDestroyContext(al->ctx);
   alcCloseDevice(al->handle);
   free(al);
}
CSound::~CSound()
{
	if (!sources.empty())
	{
		soundThread->interrupt();
		soundThread->join();
		delete soundThread;
		soundThread = 0;

		sources.clear(); // delete all sources
		sounds.clear();
		SoundBuffer::Deinitialise();
		ALCcontext *curcontext = alcGetCurrentContext();
		ALCdevice *curdevice = alcGetContextsDevice(curcontext);
		alcMakeContextCurrent(NULL);
		alcDestroyContext(curcontext);
		alcCloseDevice(curdevice);
	}
}
Beispiel #23
0
void OpenALStream::Stop()
{
	SoundStream::Stop();

	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);
}
Beispiel #24
0
AudioManagerImpl::~AudioManagerImpl()
{
	stopMusic();

	MidiDevice::shutdown();

	ALCcontext *context = alcGetCurrentContext();
	if (!context) return;


	for (ALuint source : mFreeSources)
		alDeleteSources(1, &source);
	mFreeSources.clear();

	ALCdevice *device = alcGetContextsDevice(context);
	alcMakeContextCurrent(nullptr);
	alcDestroyContext(context);
	alcCloseDevice(device);
}
Beispiel #25
0
ALCvoid ReleaseALC(ALCvoid)
{
    ALCdevice *Dev;

#ifdef _DEBUG
    if(g_ulContextCount > 0)
        AL_PRINT("exit() %u device(s) and %u context(s) NOT deleted\n", g_ulDeviceCount, g_ulContextCount);
#endif

    while(g_pDeviceList)
    {
        Dev = g_pDeviceList;
        g_pDeviceList = g_pDeviceList->next;
        if(Dev->IsCaptureDevice)
            alcCaptureCloseDevice(Dev);
        else
            alcCloseDevice(Dev);
    }
}
Beispiel #26
0
//
// AyuanX: Spec says OpenAL1.1 is thread safe already
//
bool OpenALStream::Start()
{
	ALDeviceList pDeviceList;
	if (pDeviceList.GetNumDevices())
	{
		char *defDevName = pDeviceList.GetDeviceName(pDeviceList.GetDefaultDevice());

		WARN_LOG(AUDIO, "Found OpenAL device %s", defDevName);

		ALCdevice *pDevice = alcOpenDevice(defDevName);
		if (pDevice)
		{
			ALCcontext *pContext = alcCreateContext(pDevice, nullptr);
			if (pContext)
			{
				// Used to determine an appropriate period size (2x period = total buffer size)
				//ALCint refresh;
				//alcGetIntegerv(pDevice, ALC_REFRESH, 1, &refresh);
				//period_size_in_millisec = 1000 / refresh;

				alcMakeContextCurrent(pContext);
				return SoundStream::Start();
			}
			else
			{
				alcCloseDevice(pDevice);
				PanicAlertT("OpenAL: can't create context for device %s", defDevName);
			}
		}
		else
		{
			PanicAlertT("OpenAL: can't open device %s", defDevName);
		}
	}
	else
	{
		PanicAlertT("OpenAL: can't find sound devices");
	}

	// Initialize DPL2 parameters

	return false;
}
Beispiel #27
0
SoundManager::~SoundManager()
{
  music_source.reset();
  sources.clear();

  for(SoundBuffers::iterator i = buffers.begin(); i != buffers.end(); ++i) {
    ALuint buffer = i->second;
    alDeleteBuffers(1, &buffer);
  }

  if(context != NULL) {
    alcDestroyContext(context);
    context = NULL;
  }
  if(device != NULL) {
    alcCloseDevice(device);
    device = NULL;
  }
}
Beispiel #28
0
void sound_ShutdownLibrary(void)
{
    AUDIO_STREAM *stream;
    SAMPLE_LIST *aSample = active_samples, * tmpSample = NULL;

    if (!openal_initialized)
    {
        return;
    }
    debug(LOG_SOUND, "starting shutdown");

    // Stop all streams, sound_UpdateStreams() will deallocate all stopped streams
    for (stream = active_streams; stream != NULL; stream = stream->next)
    {
        sound_StopStream(stream);
    }
    sound_UpdateStreams();

    alcGetError(device);	// clear error codes

    /* On Linux since this caused some versions of OpenAL to hang on exit. - Per */
    debug(LOG_SOUND, "make default context NULL");
    alcMakeContextCurrent(NULL);
    sound_GetContextError(device);

    debug(LOG_SOUND, "destroy previous context");
    alcDestroyContext(context); // this gives a long delay on some impl.
    sound_GetContextError(device);

    debug(LOG_SOUND, "close device");
    if (alcCloseDevice(device) == ALC_FALSE)
    {
        debug(LOG_SOUND, "OpenAl could not close the audio device.");
    }

    while (aSample)
    {
        tmpSample = aSample->next;
        free(aSample);
        aSample = tmpSample;
    }
    active_samples = NULL;
}
Beispiel #29
0
ALboolean ALFWInitOpenAL()
{
	ALDeviceList *pDeviceList = NULL;
	ALCcontext *pContext = NULL;
	ALCdevice *pDevice = NULL;
	ALint i;
	ALboolean bReturn = AL_FALSE;

	pDeviceList = new ALDeviceList();
	if ((pDeviceList) && (pDeviceList->GetNumDevices()))
	{
		ALFWprintf("\nSelect OpenAL Device:\n");
		for (i = 0; i < pDeviceList->GetNumDevices(); i++) 
			ALFWprintf("%d. %s%s\n", i + 1, pDeviceList->GetDeviceName(i), i == pDeviceList->GetDefaultDevice() ? "(DEFAULT)" : "");
	
		do {
//			ALchar ch = _getch();
			ALchar ch = '1' ;
			i = atoi(&ch);
		} while ((i < 1) || (i > pDeviceList->GetNumDevices()));

		pDevice = alcOpenDevice(pDeviceList->GetDeviceName(i - 1));
		if (pDevice)
		{
			pContext = alcCreateContext(pDevice, NULL);
			if (pContext)
			{
				ALFWprintf("\nOpened %s Device\n", alcGetString(pDevice, ALC_DEVICE_SPECIFIER));
				alcMakeContextCurrent(pContext);
				bReturn = AL_TRUE;
			}
			else
			{
				alcCloseDevice(pDevice);
			}
		}

		delete pDeviceList;
	}

	return bReturn;
}
void clAudioSubsystem_OpenAL::Start()
{
	m_AudioThread = std::make_shared<std::thread>(
		[this]()
		{
			m_Device = alcOpenDevice( nullptr );
			m_Context = alcCreateContext( m_Device, nullptr );
			alcMakeContextCurrent( m_Context );

			if ( IsVerbose() ) DebugPrintVersion();

			m_IsInitialized = true;

			while ( !m_IsPendingExit )
			{
				std::this_thread::sleep_for(std::chrono::milliseconds(10));

				{
					auto sources = this->GetLockedSources();

					for (auto i : sources)
					{
						i->UpdateBuffers();
					}
				}
			}

			// A dirty workaround for a possible bug in OpenAL Soft
			// http://openal.org/pipermail/openal/2015-January/000312.html
#if !defined(_WIN32)
			alcDestroyContext( m_Context );
			alcCloseDevice( m_Device );
#endif

			m_IsInitialized = false;

		}
	);

	// wait
	while ( !m_IsInitialized );
}