1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*
* Paula.h
* -------
* Purpose: Emulating the Amiga's sound chip, Paula, by implementing resampling using band-limited steps (BLEPs)
* Notes : (currently none)
* Authors: OpenMPT Devs
* Antti S. Lankila
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#pragma once
#include "openmpt/all/BuildSettings.hpp"
#include "Snd_defs.h"
#include "Mixer.h"
OPENMPT_NAMESPACE_BEGIN
namespace Paula
{
inline constexpr int PAULA_HZ = 3546895;
inline constexpr int MINIMUM_INTERVAL = 4; // Tradeoff between quality and speed (lower = less aliasing)
inline constexpr int BLEP_SCALE = 17; // TODO: Should be 1 for float mixer
inline constexpr int BLEP_SIZE = 2048;
using BlepArray = std::array<mixsample_t, BLEP_SIZE>;
class BlepTables
{
enum AmigaFilter
{
A500Off = 0,
A500On,
A1200Off,
A1200On,
Unfiltered,
NumFilterTypes
};
std::array<Paula::BlepArray, AmigaFilter::NumFilterTypes> WinSincIntegral;
public:
void InitTables();
const Paula::BlepArray &GetAmigaTable(Resampling::AmigaFilter amigaType, bool enableFilter) const;
};
class State
{
// MAX_BLEPS configures how many BLEPs (volume steps) are being kept track of per channel,
// and thus directly influences how much memory this feature wastes per virtual channel.
// Paula::BLEP_SIZE / Paula::MINIMUM_INTERVAL would be a safe maximum,
// but even a sample (alternating at +1/-1, thus causing a step on every frame) played at 200 kHz,
// which is way out of spec for the Amiga, will only get close to 128 active BLEPs with Paula::MINIMUM_INTERVAL == 4.
// Hence 128 is chosen as a tradeoff between quality and memory consumption.
static constexpr uint16 MAX_BLEPS = 128;
struct Blep
{
int16 level;
uint16 age;
};
public:
SamplePosition remainder, stepRemainder;
int numSteps; // Number of full-length steps
private:
uint16 activeBleps = 0, firstBlep = 0; // Count of simultaneous bleps to keep track of
int16 globalOutputLevel = 0; // The instantenous value of Paula output
Blep blepState[MAX_BLEPS];
public:
State(uint32 sampleRate = 48000);
void Reset();
void InputSample(int16 sample);
int OutputSample(const BlepArray &WinSincIntegral);
void Clock(int cycles);
};
}
OPENMPT_NAMESPACE_END
|