aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/openmpt-trunk/src/openmpt/sounddevice/SoundDeviceCallback.hpp
blob: edefe1150335ec7a2243e4a25aa7fdf9d1949b3c (plain) (blame)
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
/* SPDX-License-Identifier: BSD-3-Clause */
/* SPDX-FileCopyrightText: Olivier Lapicque */
/* SPDX-FileCopyrightText: OpenMPT Project Developers and Contributors */


#pragma once

#include "openmpt/all/BuildSettings.hpp"

#include "openmpt/base/Types.hpp"
#include "openmpt/soundbase/SampleFormat.hpp"

#include <cstddef>


OPENMPT_NAMESPACE_BEGIN


namespace SoundDevice
{


struct StreamPosition
{
	int64 Frames = 0;      // relative to Start()
	double Seconds = 0.0;  // relative to Start()
};


struct TimeInfo
{

	int64 SyncPointStreamFrames = 0;
	uint64 SyncPointSystemTimestamp = 0;
	double Speed = 1.0;

	SoundDevice::StreamPosition RenderStreamPositionBefore;
	SoundDevice::StreamPosition RenderStreamPositionAfter;
	// int64 chunkSize = After - Before

	double Latency = 0.0;  // seconds
};


struct BufferFormat
{
	uint32 Samplerate;
	uint32 Channels;
	uint8 InputChannels;
	SampleFormat sampleFormat;
	bool WantsClippedOutput;
	int32 DitherType;
};


class ICallback
{
public:
	// main thread
	virtual uint64 SoundCallbackGetReferenceClockNowNanoseconds() const = 0;  // timeGetTime()*1000000 on Windows
	virtual void SoundCallbackPreStart() = 0;
	virtual void SoundCallbackPostStop() = 0;
	virtual bool SoundCallbackIsLockedByCurrentThread() const = 0;
	// audio thread
	virtual void SoundCallbackLock() = 0;
	virtual uint64 SoundCallbackLockedGetReferenceClockNowNanoseconds() const = 0;  // timeGetTime()*1000000 on Windows
	virtual void SoundCallbackLockedProcessPrepare(SoundDevice::TimeInfo timeInfo) = 0;
	virtual void SoundCallbackLockedProcess(SoundDevice::BufferFormat bufferFormat, std::size_t numFrames, uint8 *buffer, const uint8 *inputBuffer) = 0;
	virtual void SoundCallbackLockedProcess(SoundDevice::BufferFormat bufferFormat, std::size_t numFrames, int8 *buffer, const int8 *inputBuffer) = 0;
	virtual void SoundCallbackLockedProcess(SoundDevice::BufferFormat bufferFormat, std::size_t numFrames, int16 *buffer, const int16 *inputBuffer) = 0;
	virtual void SoundCallbackLockedProcess(SoundDevice::BufferFormat bufferFormat, std::size_t numFrames, int24 *buffer, const int24 *inputBuffer) = 0;
	virtual void SoundCallbackLockedProcess(SoundDevice::BufferFormat bufferFormat, std::size_t numFrames, int32 *buffer, const int32 *inputBuffer) = 0;
	virtual void SoundCallbackLockedProcess(SoundDevice::BufferFormat bufferFormat, std::size_t numFrames, float *buffer, const float *inputBuffer) = 0;
	virtual void SoundCallbackLockedProcess(SoundDevice::BufferFormat bufferFormat, std::size_t numFrames, double *buffer, const double *inputBuffer) = 0;
	virtual void SoundCallbackLockedProcessDone(SoundDevice::TimeInfo timeInfo) = 0;
	virtual void SoundCallbackUnlock() = 0;
};


}  // namespace SoundDevice


OPENMPT_NAMESPACE_END