CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/HW/StereoResampler.h
Views: 1401
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();
32
~StereoResampler();
33
34
// Called from audio threads
35
unsigned int Mix(short* 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
void PushSamples(const s32* samples, unsigned int num_samples);
40
41
void Clear();
42
43
void GetAudioDebugStats(char *buf, size_t bufSize);
44
void ResetStatCounters();
45
46
private:
47
void UpdateBufferSize();
48
49
int m_maxBufsize;
50
int m_targetBufsize;
51
52
unsigned int m_input_sample_rate = 44100;
53
int16_t *m_buffer;
54
std::atomic<u32> m_indexW;
55
std::atomic<u32> m_indexR;
56
float m_numLeftI = 0.0f;
57
58
u32 m_frac = 0;
59
float output_sample_rate_ = 0.0;
60
int lastBufSize_ = 0;
61
int lastPushSize_ = 0;
62
u32 ratio_ = 0;
63
64
int underrunCount_ = 0;
65
int overrunCount_ = 0;
66
int underrunCountTotal_ = 0;
67
int overrunCountTotal_ = 0;
68
69
int droppedSamples_ = 0;
70
71
int64_t inputSampleCount_ = 0;
72
int64_t outputSampleCount_ = 0;
73
74
double startTime_ = 0.0;
75
};
76
77