Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/AudioCommon.cpp
5659 views
1
// Copyright (c) 2012- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
#include "Common/System/System.h"
19
#include "Core/Config.h"
20
#include "Core/HW/StereoResampler.h" // TODO: doesn't belong in Core/HW...
21
#include "Core/HW/GranularMixer.h"
22
#include "UI/AudioCommon.h"
23
#include "UI/BackgroundAudio.h"
24
#include "Core/HW/Display.h"
25
26
StereoResampler g_resampler;
27
GranularMixer g_granular;
28
29
// numFrames is number of stereo frames.
30
// This is called from *outside* the emulator thread.
31
void NativeMix(int16_t *outStereo, int numFrames, int sampleRateHz, void *userdata) {
32
// Mix UI sound effects on top.
33
if (g_Config.iAudioPlaybackMode == (int)AudioSyncMode::GRANULAR) {
34
// We use the FPS estimate, because to maintain smooth audio even though our
35
// frame execution is very front (or back) heavy (as we can't count on "real time clock sync"
36
// to be enabled), we need at least one whole frame buffered, plus a bit of extra.
37
float fpsEstimate, vps, actualFps;
38
__DisplayGetFPS(&vps, &fpsEstimate, &actualFps);
39
40
g_granular.Mix(outStereo, numFrames, sampleRateHz, fpsEstimate);
41
} else {
42
g_resampler.Mix(outStereo, numFrames, false, sampleRateHz);
43
}
44
g_BackgroundAudio.SFX().Mix(outStereo, numFrames, sampleRateHz);
45
}
46
47
void System_AudioGetDebugStats(char *buf, size_t bufSize) {
48
if (buf) {
49
if (g_Config.iAudioPlaybackMode == (int)AudioSyncMode::GRANULAR) {
50
snprintf(buf, bufSize, "(No stats available for granular yet)");
51
} else {
52
g_resampler.GetAudioDebugStats(buf, bufSize);
53
}
54
} else {
55
g_resampler.ResetStatCounters();
56
}
57
}
58
59
void System_AudioClear() {
60
g_resampler.Clear();
61
}
62
63
void System_AudioPushSamples(const int32_t *audio, int numSamples, float volume) {
64
if (audio) {
65
if (g_Config.iAudioPlaybackMode == (int)AudioSyncMode::GRANULAR) {
66
g_granular.PushSamples(audio, numSamples, volume);
67
} else {
68
g_resampler.PushSamples(audio, numSamples, volume);
69
}
70
} else {
71
g_resampler.Clear();
72
}
73
}
74
75