Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/HW/StereoResampler.h
3187 views
1
// Copyright (c) 2015- PPSSPP Project and Dolphin 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
// Adapted from Dolphin.
19
20
#pragma once
21
22
#include <cstdint>
23
#include <atomic>
24
25
#include "Common/CommonTypes.h"
26
27
struct AudioDebugStats;
28
29
class StereoResampler {
30
public:
31
StereoResampler() noexcept;
32
~StereoResampler();
33
34
// Called from audio threads
35
void Mix(s16 *samples, unsigned int numSamples, bool consider_framelimit, int sampleRate);
36
37
// Called from main thread
38
// This clamps the samples to 16-bit before starting to work on them.
39
// Volume is a multiplier from 0.0f to 1.0f.
40
void PushSamples(const s32* samples, unsigned int num_samples, float volume);
41
42
void Clear();
43
44
void GetAudioDebugStats(char *buf, size_t bufSize);
45
void ResetStatCounters();
46
47
private:
48
void UpdateBufferSize();
49
50
int maxBufsize_;
51
int targetBufsize_;
52
53
// This can be adjusted, for the case of non-60hz output (a few hz off).
54
int inputSampleRateHz_ = 44100;
55
56
int16_t *buffer_;
57
std::atomic<u32> indexW_;
58
std::atomic<u32> indexR_;
59
float numLeftI_ = 0.0f;
60
61
u32 frac_ = 0;
62
float outputSampleRateHz_ = 0.0;
63
int lastBufSize_ = 0;
64
int lastPushSize_ = 0;
65
u32 ratio_ = 0;
66
67
int underrunCount_ = 0;
68
int overrunCount_ = 0;
69
int underrunCountTotal_ = 0;
70
int overrunCountTotal_ = 0;
71
72
int droppedSamples_ = 0;
73
74
int64_t inputSampleCount_ = 0;
75
int64_t outputSampleCount_ = 0;
76
77
double startTime_ = 0.0;
78
};
79
80