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-08 04:46:09 +00:00
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2008-12-08 04:46:09 +00:00
|
|
|
|
2014-08-14 05:14:35 +00:00
|
|
|
#include <thread>
|
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "AudioCommon/SoundStream.h"
|
2014-04-13 23:15:23 +00:00
|
|
|
#include "Common/Event.h"
|
2009-01-29 00:57:55 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2013-10-19 09:27:57 +00:00
|
|
|
#include <Windows.h>
|
2009-01-29 00:57:55 +00:00
|
|
|
#include <mmsystem.h>
|
|
|
|
#include <dsound.h>
|
|
|
|
|
2014-05-31 20:35:46 +00:00
|
|
|
#define BUFSIZE (1024 * 8 * 4)
|
2009-01-29 00:57:55 +00:00
|
|
|
#endif
|
|
|
|
|
2014-03-18 14:37:45 +00:00
|
|
|
class DSound final : public SoundStream
|
2008-12-08 04:46:09 +00:00
|
|
|
{
|
2009-03-28 16:23:06 +00:00
|
|
|
#ifdef _WIN32
|
2013-03-20 01:51:12 +00:00
|
|
|
std::thread thread;
|
2014-05-31 20:35:46 +00:00
|
|
|
Common::Event soundSyncEvent;
|
2013-03-20 01:51:12 +00:00
|
|
|
void *hWnd;
|
|
|
|
|
|
|
|
IDirectSound8* ds;
|
|
|
|
IDirectSoundBuffer* dsBuffer;
|
|
|
|
|
|
|
|
int bufferSize; //i bytes
|
2009-05-18 19:24:46 +00:00
|
|
|
int m_volume;
|
2013-03-20 01:51:12 +00:00
|
|
|
|
|
|
|
// playback position
|
|
|
|
int currentPos;
|
|
|
|
int lastPos;
|
|
|
|
short realtimeBuffer[BUFSIZE / sizeof(short)];
|
|
|
|
|
|
|
|
inline int FIX128(int x)
|
2009-12-23 15:34:14 +00:00
|
|
|
{
|
2009-02-20 22:04:52 +00:00
|
|
|
return x & (~127);
|
2013-03-20 01:51:12 +00:00
|
|
|
}
|
2009-01-29 00:57:55 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
inline int ModBufferSize(int x)
|
2009-12-23 15:34:14 +00:00
|
|
|
{
|
2009-02-20 22:04:52 +00:00
|
|
|
return (x + bufferSize) % bufferSize;
|
2013-03-20 01:51:12 +00:00
|
|
|
}
|
2009-01-29 00:57:55 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
bool CreateBuffer();
|
|
|
|
bool WriteDataToBuffer(DWORD dwOffset, char* soundData, DWORD dwSoundBytes);
|
2009-01-29 00:57:55 +00:00
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
public:
|
2013-11-07 17:24:56 +00:00
|
|
|
DSound(CMixer *mixer, void *_hWnd)
|
2009-03-28 16:23:06 +00:00
|
|
|
: SoundStream(mixer)
|
|
|
|
, bufferSize(0)
|
|
|
|
, currentPos(0)
|
|
|
|
, lastPos(0)
|
2009-06-03 20:09:48 +00:00
|
|
|
, dsBuffer(0)
|
|
|
|
, ds(0)
|
2011-01-28 18:39:30 +00:00
|
|
|
, hWnd(_hWnd)
|
2009-03-28 16:23:06 +00:00
|
|
|
{}
|
2009-03-26 09:29:14 +00:00
|
|
|
|
2013-03-20 01:51:12 +00:00
|
|
|
virtual ~DSound() {}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2009-02-20 22:04:52 +00:00
|
|
|
virtual bool Start();
|
2013-03-20 01:51:12 +00:00
|
|
|
virtual void SoundLoop();
|
2009-05-18 19:24:46 +00:00
|
|
|
virtual void SetVolume(int volume);
|
2013-03-20 01:51:12 +00:00
|
|
|
virtual void Stop();
|
2009-12-13 11:51:29 +00:00
|
|
|
virtual void Clear(bool mute);
|
2013-03-20 01:51:12 +00:00
|
|
|
static bool isValid() { return true; }
|
2014-05-31 20:35:46 +00:00
|
|
|
virtual void Update();
|
2009-03-28 16:23:06 +00:00
|
|
|
|
|
|
|
#else
|
2009-03-28 16:27:38 +00:00
|
|
|
public:
|
2013-11-07 17:24:56 +00:00
|
|
|
DSound(CMixer *mixer, void *_hWnd)
|
2009-03-28 16:27:38 +00:00
|
|
|
: SoundStream(mixer)
|
|
|
|
{}
|
2009-03-28 16:23:06 +00:00
|
|
|
#endif
|
2009-01-29 00:57:55 +00:00
|
|
|
};
|