Files
dolphin/Source/Core/AudioCommon/Src/OpenALStream.cpp
T

112 lines
2.6 KiB
C++
Raw Normal View History

2009-03-27 15:24:22 +00:00
// Copyright (C) 2003-2009 Dolphin Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
2009-03-30 14:22:31 +00:00
#include "aldlist.h"
2009-03-28 17:18:34 +00:00
#include "OpenALStream.h"
2009-03-27 15:24:22 +00:00
#if defined HAVE_OPENAL && HAVE_OPENAL
2009-03-27 15:24:22 +00:00
#define AUDIO_NUMBUFFERS (4)
bool OpenALStream::Start()
{
2009-03-30 14:22:31 +00:00
ALDeviceList *pDeviceList = NULL;
ALCcontext *pContext = NULL;
ALCdevice *pDevice = NULL;
bool bReturn = false;
2009-03-30 20:25:36 +00:00
2009-03-30 14:22:31 +00:00
pDeviceList = new ALDeviceList();
if ((pDeviceList) && (pDeviceList->GetNumDevices()))
{
pDevice = alcOpenDevice(pDeviceList->GetDeviceName(pDeviceList->GetDefaultDevice()));
if (pDevice)
{
pContext = alcCreateContext(pDevice, NULL);
if (pContext)
{
alcMakeContextCurrent(pContext);
thread = new Common::Thread(OpenALStream::ThreadFunc, (void *)this);
bReturn = true;
}
else
{
alcCloseDevice(pDevice);
2009-03-30 20:25:36 +00:00
PanicAlert("OpenAL: can't create context for device %s", pDevice);
2009-03-30 14:22:31 +00:00
}
2009-03-30 20:25:36 +00:00
} else {
PanicAlert("OpenAL: can't open device %s", pDevice);
2009-03-30 14:22:31 +00:00
}
2009-03-30 20:25:36 +00:00
2009-03-30 14:22:31 +00:00
delete pDeviceList;
2009-03-30 20:25:36 +00:00
} else {
PanicAlert("OpenAL: can't find sound devices");
2009-03-30 14:22:31 +00:00
}
2009-03-30 20:25:36 +00:00
2009-03-30 14:22:31 +00:00
return bReturn;
2009-03-27 15:24:22 +00:00
}
void OpenALStream::Stop()
{
2009-03-30 14:22:31 +00:00
ALCcontext *pContext;
ALCdevice *pDevice;
2009-03-27 15:24:22 +00:00
2009-03-30 20:25:36 +00:00
soundCriticalSection.Enter();
threadData = 1;
// kick the thread if it's waiting
soundSyncEvent.Set();
soundCriticalSection.Leave();
2009-03-30 14:22:31 +00:00
delete thread;
2009-03-30 20:25:36 +00:00
2009-03-30 14:22:31 +00:00
pContext = alcGetCurrentContext();
pDevice = alcGetContextsDevice(pContext);
alcMakeContextCurrent(NULL);
alcDestroyContext(pContext);
alcCloseDevice(pDevice);
2009-03-30 20:25:36 +00:00
soundSyncEvent.Shutdown();
thread = NULL;
2009-03-27 15:24:22 +00:00
}
void OpenALStream::Update()
{
2009-03-30 20:25:36 +00:00
soundSyncEvent.Set();
2009-03-27 15:24:22 +00:00
}
THREAD_RETURN OpenALStream::ThreadFunc(void* args)
2009-03-30 14:22:31 +00:00
{
(reinterpret_cast<OpenALStream *>(args))->SoundLoop();
return 0;
}
void OpenALStream::SoundLoop()
2009-03-27 15:24:22 +00:00
{
2009-03-30 20:25:36 +00:00
while (!threadData) {
soundCriticalSection.Enter();
2009-03-27 15:24:22 +00:00
2009-03-30 20:25:36 +00:00
// Add sound playing here
// m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
soundCriticalSection.Leave();
if (!threadData)
soundSyncEvent.Wait();
}
2009-03-28 08:57:34 +00:00
}
#endif //HAVE_OPENAL