2009-07-28 15:32:10 -06:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-14 13:18:21 -07:00
|
|
|
|
|
|
|
// 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/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-08-16 15:58:07 -06:00
|
|
|
#include "AOSoundStream.h"
|
2009-03-26 03:29:14 -06:00
|
|
|
#include "Mixer.h"
|
2008-08-16 15:58:07 -06:00
|
|
|
|
2009-01-28 17:57:55 -07:00
|
|
|
#if defined(HAVE_AO) && HAVE_AO
|
2008-08-16 15:58:07 -06:00
|
|
|
|
2009-01-28 17:57:55 -07:00
|
|
|
void AOSound::SoundLoop()
|
|
|
|
{
|
2009-03-26 03:29:14 -06:00
|
|
|
uint_32 numBytesToRender = 256;
|
2010-06-19 23:02:26 -06: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;
|
|
|
|
|
|
|
|
device = ao_open_live(default_driver, &format, NULL /* no options */);
|
|
|
|
if (!device)
|
2009-02-20 15:04:52 -07:00
|
|
|
{
|
2011-01-12 19:05:58 -07:00
|
|
|
PanicAlertT("AudioCommon: Error opening AO device.\n");
|
2009-02-03 15:06:18 -07:00
|
|
|
ao_shutdown();
|
|
|
|
Stop();
|
|
|
|
return;
|
2010-06-19 23:02:26 -06:00
|
|
|
}
|
2009-01-28 17:57:55 -07:00
|
|
|
|
2010-06-19 23:02:26 -06:00
|
|
|
buf_size = format.bits/8 * format.channels * format.rate;
|
2009-01-28 17:57:55 -07:00
|
|
|
|
2010-06-19 23:02:26 -06:00
|
|
|
while (!threadData)
|
2009-02-20 15:04:52 -07:00
|
|
|
{
|
2010-06-19 23:02:26 -06:00
|
|
|
m_mixer->Mix(realtimeBuffer, numBytesToRender >> 2);
|
|
|
|
soundCriticalSection.Enter();
|
2009-12-13 04:51:29 -07:00
|
|
|
ao_play(device, (char*)realtimeBuffer, numBytesToRender);
|
2010-06-19 23:02:26 -06:00
|
|
|
soundCriticalSection.Leave();
|
2009-03-26 03:29:14 -06:00
|
|
|
|
2009-12-18 12:52:04 -07:00
|
|
|
soundSyncEvent.Wait();
|
2009-02-20 15:04:52 -07:00
|
|
|
}
|
2009-01-28 17:57:55 -07:00
|
|
|
}
|
2008-12-14 13:18:21 -07:00
|
|
|
|
2011-01-27 13:47:58 -07:00
|
|
|
void soundThread(AOSound *aosound)
|
2009-02-20 15:04:52 -07:00
|
|
|
{
|
2011-01-27 13:47:58 -07:00
|
|
|
aosound->SoundLoop();
|
2009-01-28 17:57:55 -07:00
|
|
|
}
|
2008-12-14 13:18:21 -07:00
|
|
|
|
2009-02-20 15:04:52 -07:00
|
|
|
bool AOSound::Start()
|
|
|
|
{
|
2010-06-19 23:02:26 -06:00
|
|
|
memset(realtimeBuffer, 0, sizeof(realtimeBuffer));
|
2009-02-03 15:06:18 -07:00
|
|
|
|
2010-06-19 23:02:26 -06:00
|
|
|
soundSyncEvent.Init();
|
2009-03-26 03:29:14 -06:00
|
|
|
|
2011-01-27 13:47:58 -07:00
|
|
|
thread = std::thread(soundThread, this);
|
2010-06-19 23:02:26 -06:00
|
|
|
return true;
|
2009-01-28 17:57:55 -07:00
|
|
|
}
|
2008-12-14 13:18:21 -07:00
|
|
|
|
2009-02-20 15:04:52 -07:00
|
|
|
void AOSound::Update()
|
|
|
|
{
|
2010-06-19 23:02:26 -06:00
|
|
|
soundSyncEvent.Set();
|
2008-08-16 15:58:07 -06:00
|
|
|
}
|
2009-11-07 13:01:39 -07:00
|
|
|
|
2009-01-28 17:57:55 -07:00
|
|
|
void AOSound::Stop()
|
|
|
|
{
|
2010-06-19 23:02:26 -06:00
|
|
|
threadData = 1;
|
|
|
|
soundSyncEvent.Set();
|
2009-03-26 03:29:14 -06:00
|
|
|
|
2010-06-19 23:02:26 -06:00
|
|
|
soundCriticalSection.Enter();
|
2011-01-27 13:47:58 -07:00
|
|
|
thread.join();
|
2009-12-18 12:52:04 -07:00
|
|
|
|
2010-06-19 23:02:26 -06:00
|
|
|
if (device)
|
|
|
|
ao_close(device);
|
|
|
|
|
2009-12-18 12:52:04 -07:00
|
|
|
ao_shutdown();
|
2010-06-19 23:02:26 -06:00
|
|
|
|
2009-12-18 12:52:04 -07:00
|
|
|
device = NULL;
|
|
|
|
soundCriticalSection.Leave();
|
|
|
|
|
2010-06-19 23:02:26 -06:00
|
|
|
soundSyncEvent.Shutdown();
|
2009-01-28 17:57:55 -07:00
|
|
|
}
|
|
|
|
|
2009-12-18 12:52:04 -07:00
|
|
|
AOSound::~AOSound()
|
|
|
|
{
|
2009-03-27 05:06:52 -06:00
|
|
|
}
|
2009-12-10 14:00:52 -07:00
|
|
|
|
2009-01-28 17:57:55 -07:00
|
|
|
#endif
|