2013-04-18 03:09:55 +00:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-14 20:18:21 +00:00
|
|
|
|
2011-01-31 08:19:27 +00:00
|
|
|
#include <functional>
|
2008-12-14 20:18:21 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-08-16 21:58:07 +00:00
|
|
|
#include "AOSoundStream.h"
|
2009-03-26 09:29:14 +00:00
|
|
|
#include "Mixer.h"
|
2008-08-16 21:58:07 +00:00
|
|
|
|
2009-01-29 00:57:55 +00:00
|
|
|
#if defined(HAVE_AO) && HAVE_AO
|
2008-08-16 21:58:07 +00:00
|
|
|
|
2009-01-29 00:57:55 +00:00
|
|
|
void AOSound::SoundLoop()
|
|
|
|
{
|
2011-12-31 04:22:48 +00:00
|
|
|
Common::SetCurrentThreadName("Audio thread - ao");
|
|
|
|
|
2009-03-26 09:29:14 +00:00
|
|
|
uint_32 numBytesToRender = 256;
|
2010-06-20 05:02:26 +00:00
|
|
|
ao_initialize();
|
|
|
|
default_driver = ao_default_driver_id();
|
|
|
|
format.bits = 16;
|
|
|
|
format.channels = 2;
|
|
|
|
format.rate = m_mixer->GetSampleRate();
|
|
|
|
format.byte_format = AO_FMT_LITTLE;
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2010-06-20 05:02:26 +00:00
|
|
|
device = ao_open_live(default_driver, &format, NULL /* no options */);
|
|
|
|
if (!device)
|
2009-02-20 22:04:52 +00:00
|
|
|
{
|
2011-01-13 02:05:58 +00:00
|
|
|
PanicAlertT("AudioCommon: Error opening AO device.\n");
|
2009-02-03 22:06:18 +00:00
|
|
|
ao_shutdown();
|
|
|
|
Stop();
|
|
|
|
return;
|
2010-06-20 05:02:26 +00:00
|
|
|
}
|
2009-01-29 00:57:55 +00:00
|
|
|
|
2010-06-20 05:02:26 +00:00
|
|
|
buf_size = format.bits/8 * format.channels * format.rate;
|
2009-01-29 00:57:55 +00:00
|
|
|
|
2010-06-20 05:02:26 +00:00
|
|
|
while (!threadData)
|
2009-02-20 22:04:52 +00:00
|
|
|
{
|
2010-06-20 05:02:26 +00:00
|
|
|
m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2011-03-05 06:11:26 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lk(soundCriticalSection);
|
2009-12-13 11:51:29 +00:00
|
|
|
ao_play(device, (char*)realtimeBuffer, numBytesToRender);
|
2011-03-05 06:11:26 +00:00
|
|
|
}
|
2009-03-26 09:29:14 +00:00
|
|
|
|
2009-12-18 19:52:04 +00:00
|
|
|
soundSyncEvent.Wait();
|
2009-02-20 22:04:52 +00:00
|
|
|
}
|
2009-01-29 00:57:55 +00:00
|
|
|
}
|
2008-12-14 20:18:21 +00:00
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
bool AOSound::Start()
|
|
|
|
{
|
2010-06-20 05:02:26 +00:00
|
|
|
memset(realtimeBuffer, 0, sizeof(realtimeBuffer));
|
2013-03-20 01:51:12 +00:00
|
|
|
|
2013-01-24 04:38:49 +00:00
|
|
|
thread = std::thread(std::mem_fun(&AOSound::SoundLoop), this);
|
2010-06-20 05:02:26 +00:00
|
|
|
return true;
|
2009-01-29 00:57:55 +00:00
|
|
|
}
|
2008-12-14 20:18:21 +00:00
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
void AOSound::Update()
|
|
|
|
{
|
2010-06-20 05:02:26 +00:00
|
|
|
soundSyncEvent.Set();
|
2008-08-16 21:58:07 +00:00
|
|
|
}
|
2009-11-07 20:01:39 +00:00
|
|
|
|
2009-01-29 00:57:55 +00:00
|
|
|
void AOSound::Stop()
|
|
|
|
{
|
2010-06-20 05:02:26 +00:00
|
|
|
threadData = 1;
|
|
|
|
soundSyncEvent.Set();
|
2009-03-26 09:29:14 +00:00
|
|
|
|
2011-03-05 06:11:26 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lk(soundCriticalSection);
|
2011-01-27 20:47:58 +00:00
|
|
|
thread.join();
|
2009-12-18 19:52:04 +00:00
|
|
|
|
2010-06-20 05:02:26 +00:00
|
|
|
if (device)
|
|
|
|
ao_close(device);
|
|
|
|
|
2009-12-18 19:52:04 +00:00
|
|
|
ao_shutdown();
|
2010-06-20 05:02:26 +00:00
|
|
|
|
2009-12-18 19:52:04 +00:00
|
|
|
device = NULL;
|
2011-03-05 06:11:26 +00:00
|
|
|
}
|
2009-01-29 00:57:55 +00:00
|
|
|
}
|
|
|
|
|
2009-12-18 19:52:04 +00:00
|
|
|
AOSound::~AOSound()
|
|
|
|
{
|
2009-03-27 11:06:52 +00:00
|
|
|
}
|
2009-12-10 21:00:52 +00:00
|
|
|
|
2009-01-29 00:57:55 +00:00
|
|
|
#endif
|