summaryrefslogtreecommitdiff
path: root/Source/Core/AudioCommon/DSoundStream.h
blob: 331c4581d3d1dc4442c73699b21ffe17c8d5421c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2013 Dolphin Emulator Project
// Licensed under GPLv2
// Refer to the license.txt file included.

#pragma once

#include "AudioCommon/SoundStream.h"
#include "Common/Thread.h"

#ifdef _WIN32
#include <Windows.h>
#include <mmsystem.h>
#include <dsound.h>

#define BUFSIZE (1024 * 8 * 4)
#endif

class DSound final : public SoundStream
{
#ifdef _WIN32
	std::thread thread;
	Common::Event soundSyncEvent;
	void  *hWnd;

	IDirectSound8* ds;
	IDirectSoundBuffer* dsBuffer;

	int bufferSize;     //i bytes
	int m_volume;

	// playback position
	int currentPos;
	int lastPos;
	short realtimeBuffer[BUFSIZE / sizeof(short)];

	inline int FIX128(int x)
	{
		return x & (~127);
	}

	inline int ModBufferSize(int x)
	{
		return (x + bufferSize) % bufferSize;
	}

	bool CreateBuffer();
	bool WriteDataToBuffer(DWORD dwOffset, char* soundData, DWORD dwSoundBytes);

public:
	DSound(CMixer *mixer, void *_hWnd)
		: SoundStream(mixer)
		, bufferSize(0)
		, currentPos(0)
		, lastPos(0)
		, dsBuffer(0)
		, ds(0)
		, hWnd(_hWnd)
	{}

	virtual ~DSound() {}

	virtual bool Start();
	virtual void SoundLoop();
	virtual void SetVolume(int volume);
	virtual void Stop();
	virtual void Clear(bool mute);
	static bool isValid() { return true; }
	virtual void Update();

#else
public:
	DSound(CMixer *mixer, void *_hWnd)
		: SoundStream(mixer)
	{}
#endif
};