2013-04-17 21:09:55 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2009-07-05 20:10:26 -06:00
|
|
|
|
|
|
|
#ifndef _OPENALSTREAM_H_
|
|
|
|
#define _OPENALSTREAM_H_
|
|
|
|
|
|
|
|
#include "SoundStream.h"
|
|
|
|
#include "Thread.h"
|
|
|
|
|
|
|
|
#if defined HAVE_OPENAL && HAVE_OPENAL
|
|
|
|
#ifdef _WIN32
|
2013-01-09 13:43:59 -07:00
|
|
|
#include <OpenAL/include/al.h>
|
|
|
|
#include <OpenAL/include/alc.h>
|
2013-01-10 20:03:09 -07:00
|
|
|
#include <OpenAL/include/alext.h>
|
2011-02-08 05:35:43 -07:00
|
|
|
#elif defined __APPLE__
|
|
|
|
#include <OpenAL/al.h>
|
|
|
|
#include <OpenAL/alc.h>
|
2010-07-21 21:29:35 -06:00
|
|
|
#else
|
2010-01-31 16:46:50 -07:00
|
|
|
#include <AL/al.h>
|
|
|
|
#include <AL/alc.h>
|
2013-01-10 20:03:09 -07:00
|
|
|
#include <AL/alext.h>
|
2010-06-01 16:23:16 -06:00
|
|
|
#endif
|
|
|
|
|
2013-01-09 09:26:12 -07:00
|
|
|
#include "Core.h"
|
|
|
|
#include "HW/SystemTimers.h"
|
|
|
|
#include "HW/AudioInterface.h"
|
|
|
|
#include <soundtouch/SoundTouch.h>
|
|
|
|
#include <soundtouch/STTypes.h>
|
2013-01-09 04:57:32 -07:00
|
|
|
|
2009-12-23 08:34:14 -07:00
|
|
|
// 16 bit Stereo
|
2013-06-09 01:43:27 -06:00
|
|
|
#define SFX_MAX_SOURCE 1
|
|
|
|
#define OAL_MAX_BUFFERS 32
|
|
|
|
#define OAL_MAX_SAMPLES 256
|
|
|
|
#define STEREO_CHANNELS 2
|
|
|
|
#define SURROUND_CHANNELS 6 // number of channels in surround mode
|
|
|
|
#define SIZE_SHORT 2
|
|
|
|
#define SIZE_FLOAT 4 // size of a float in bytes
|
|
|
|
#define FRAME_STEREO_SHORT STEREO_CHANNELS * SIZE_SHORT
|
|
|
|
#define FRAME_STEREO_FLOAT STEREO_CHANNELS * SIZE_FLOAT
|
|
|
|
#define FRAME_SURROUND_FLOAT SURROUND_CHANNELS * SIZE_FLOAT
|
2009-07-05 20:10:26 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
class OpenALStream: public SoundStream
|
|
|
|
{
|
|
|
|
#if defined HAVE_OPENAL && HAVE_OPENAL
|
|
|
|
public:
|
2009-12-20 06:54:14 -07:00
|
|
|
OpenALStream(CMixer *mixer, void *hWnd = NULL)
|
|
|
|
: SoundStream(mixer)
|
|
|
|
, uiSource(0)
|
|
|
|
{};
|
|
|
|
|
2009-07-05 20:10:26 -06:00
|
|
|
virtual ~OpenALStream() {};
|
|
|
|
|
|
|
|
virtual bool Start();
|
|
|
|
virtual void SoundLoop();
|
2009-12-20 06:54:14 -07:00
|
|
|
virtual void SetVolume(int volume);
|
2009-07-05 20:10:26 -06:00
|
|
|
virtual void Stop();
|
2009-12-13 04:51:29 -07:00
|
|
|
virtual void Clear(bool mute);
|
2009-07-05 20:10:26 -06:00
|
|
|
static bool isValid() { return true; }
|
|
|
|
virtual bool usesMixer() const { return true; }
|
|
|
|
virtual void Update();
|
|
|
|
|
|
|
|
private:
|
2011-01-27 13:47:58 -07:00
|
|
|
std::thread thread;
|
2011-03-04 23:11:26 -07:00
|
|
|
Common::Event soundSyncEvent;
|
2013-01-09 04:57:32 -07:00
|
|
|
|
2013-06-09 01:43:27 -06:00
|
|
|
short realtimeBuffer[OAL_MAX_SAMPLES * STEREO_CHANNELS];
|
|
|
|
soundtouch::SAMPLETYPE sampleBuffer[OAL_MAX_SAMPLES * SURROUND_CHANNELS * OAL_MAX_BUFFERS];
|
2013-01-12 06:05:30 -07:00
|
|
|
ALuint uiBuffers[OAL_MAX_BUFFERS];
|
2009-12-19 19:23:26 -07:00
|
|
|
ALuint uiSource;
|
2009-12-20 06:54:14 -07:00
|
|
|
ALfloat fVolume;
|
2013-01-12 06:05:30 -07:00
|
|
|
|
|
|
|
u8 numBuffers;
|
2009-07-05 20:10:26 -06:00
|
|
|
#else
|
|
|
|
public:
|
|
|
|
OpenALStream(CMixer *mixer, void *hWnd = NULL): SoundStream(mixer) {}
|
|
|
|
#endif // HAVE_OPENAL
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // OPENALSTREAM
|