mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-12-12 13:21:51 +00:00
87d46ddd11
## 1.5.0 2020-09-28 * Drum note length expanding is now supported in real-time mode (Thanks to [Jean Pierre Cimalando](https://github.com/jpcima) for a work!) * Added support for OPNA chip with Neko Project II Kai YM2602 emulator usage (Thanks to [Jean Pierre Cimalando](https://github.com/jpcima) for a work!) * Added VGM file dumper which allows to output OPN2 commands into VGM file. (A new MIDI to VGM tool is now created with basing on libOPNMIDI) * Fixed an incorrect work of CC-121 (See https://github.com/Wohlstand/libADLMIDI/issues/227 for details) * Internality has been refactored and improved
70 lines
1.5 KiB
C++
70 lines
1.5 KiB
C++
// SPDX-License-Identifier: GPL-2.0-only
|
|
#pragma once
|
|
#include <vector>
|
|
#include <cmath>
|
|
#include <cstddef>
|
|
#include <stdint.h>
|
|
|
|
typedef int32_t sample;
|
|
|
|
namespace chip
|
|
{
|
|
class AbstractResampler
|
|
{
|
|
public:
|
|
AbstractResampler();
|
|
virtual ~AbstractResampler();
|
|
virtual void init(int srcRate, int destRate, size_t maxDuration);
|
|
virtual void setDestributionRate(int destRate);
|
|
virtual void setMaxDuration(size_t maxDuration);
|
|
virtual sample** interpolate(sample** src, size_t nSamples, size_t intrSize) = 0;
|
|
|
|
inline size_t calculateInternalSampleSize(size_t nSamples)
|
|
{
|
|
float f = nSamples * rateRatio_;
|
|
size_t i = static_cast<size_t>(f);
|
|
return ((f - i) ? (i + 1) : i);
|
|
}
|
|
|
|
protected:
|
|
inline void updateRateRatio() {
|
|
rateRatio_ = static_cast<float>(srcRate_) / destRate_;
|
|
}
|
|
|
|
protected:
|
|
int srcRate_, destRate_;
|
|
size_t maxDuration_;
|
|
float rateRatio_;
|
|
sample* destBuf_[2];
|
|
};
|
|
|
|
|
|
class LinearResampler : public AbstractResampler
|
|
{
|
|
public:
|
|
sample** interpolate(sample** src, size_t nSamples, size_t intrSize);
|
|
};
|
|
|
|
|
|
class SincResampler : public AbstractResampler
|
|
{
|
|
public:
|
|
void init(int srcRate, int destRate, size_t maxDuration);
|
|
void setDestributionRate(int destRate);
|
|
void setMaxDuration(size_t maxDuration);
|
|
sample** interpolate(sample** src, size_t nSamples, size_t intrSize);
|
|
|
|
private:
|
|
std::vector<float> sincTable_;
|
|
|
|
static const float F_PI_;
|
|
static const int SINC_OFFSET_;
|
|
|
|
void initSincTables();
|
|
|
|
static inline float sinc(float x)
|
|
{
|
|
return ((!x) ? 1.0f : (std::sin(x) / x));
|
|
}
|
|
};
|
|
}
|