// Copyright (c) 2015- PPSSPP Project and Dolphin Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617// Adapted from Dolphin.1819#pragma once2021#include <cstdint>22#include <atomic>2324#include "Common/CommonTypes.h"2526struct AudioDebugStats;2728class StereoResampler {29public:30StereoResampler() noexcept;31~StereoResampler();3233// Called from audio threads34void Mix(s16 *samples, unsigned int numSamples, bool consider_framelimit, int sampleRate);3536// Called from main thread37// This clamps the samples to 16-bit before starting to work on them.38// Volume is a multiplier from 0.0f to 1.0f.39void PushSamples(const s32* samples, unsigned int num_samples, float volume);4041void Clear();4243void GetAudioDebugStats(char *buf, size_t bufSize);44void ResetStatCounters();4546private:47void UpdateBufferSize();4849int maxBufsize_;50int targetBufsize_;5152// This can be adjusted, for the case of non-60hz output (a few hz off).53int inputSampleRateHz_ = 44100;5455int16_t *buffer_;56std::atomic<u32> indexW_;57std::atomic<u32> indexR_;58float numLeftI_ = 0.0f;5960u32 frac_ = 0;61float outputSampleRateHz_ = 0.0;62int lastBufSize_ = 0;63int lastPushSize_ = 0;64u32 ratio_ = 0;6566int underrunCount_ = 0;67int overrunCount_ = 0;68int underrunCountTotal_ = 0;69int overrunCountTotal_ = 0;7071int droppedSamples_ = 0;7273int64_t inputSampleCount_ = 0;74int64_t outputSampleCount_ = 0;7576double startTime_ = 0.0;77};787980