File: OpenALStream.h

package info (click to toggle)
dolphin-emu 5.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 29,052 kB
  • sloc: cpp: 213,146; java: 6,252; asm: 2,277; xml: 1,998; ansic: 1,514; python: 462; sh: 279; pascal: 247; makefile: 124; perl: 97
file content (88 lines) | stat: -rw-r--r-- 2,194 bytes parent folder | download
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
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2008 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <atomic>
#include <thread>

#include "AudioCommon/SoundStream.h"
#include "Common/Event.h"
#include "Core/Core.h"
#include "Core/HW/AudioInterface.h"
#include "Core/HW/SystemTimers.h"

#if defined HAVE_OPENAL && HAVE_OPENAL
#ifdef _WIN32
#include <OpenAL/include/al.h>
#include <OpenAL/include/alc.h>
#include <OpenAL/include/alext.h>
#elif defined __APPLE__
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#else
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alext.h>
#endif

#ifdef __APPLE__
// Avoid conflict with objc.h (on Windows, ST uses the system BOOL type, so this doesn't work)
#define BOOL SoundTouch_BOOL
#endif

#define ST_NO_EXCEPTION_HANDLING
#include <soundtouch/SoundTouch.h>
#include <soundtouch/STTypes.h>

#ifdef __APPLE__
#undef BOOL
#endif

// 16 bit Stereo
#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
#define FRAME_SURROUND_SHORT    SURROUND_CHANNELS * SIZE_SHORT
#endif

class OpenALStream final : public SoundStream
{
#if defined HAVE_OPENAL && HAVE_OPENAL
public:
	OpenALStream() : uiSource(0)
	{
	}

	bool Start() override;
	void SoundLoop() override;
	void SetVolume(int volume) override;
	void Stop() override;
	void Clear(bool mute) override;
	void Update() override;

	static bool isValid() { return true; }

private:
	std::thread thread;
	std::atomic<bool> m_run_thread;

	Common::Event soundSyncEvent;

	short realtimeBuffer[OAL_MAX_SAMPLES * STEREO_CHANNELS];
	soundtouch::SAMPLETYPE sampleBuffer[OAL_MAX_SAMPLES * SURROUND_CHANNELS * OAL_MAX_BUFFERS];
	ALuint uiBuffers[OAL_MAX_BUFFERS];
	ALuint uiSource;
	ALfloat fVolume;

	u8 numBuffers;
#endif // HAVE_OPENAL
};