aboutsummaryrefslogtreecommitdiff
path: root/Src/external_dependencies/openmpt-trunk/soundlib/Paula.h
diff options
context:
space:
mode:
authorJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
committerJef <jef@targetspot.com>2024-09-24 08:54:57 -0400
commit20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch)
tree12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/external_dependencies/openmpt-trunk/soundlib/Paula.h
parent537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff)
downloadwinamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz
Initial community commit
Diffstat (limited to 'Src/external_dependencies/openmpt-trunk/soundlib/Paula.h')
-rw-r--r--Src/external_dependencies/openmpt-trunk/soundlib/Paula.h86
1 files changed, 86 insertions, 0 deletions
diff --git a/Src/external_dependencies/openmpt-trunk/soundlib/Paula.h b/Src/external_dependencies/openmpt-trunk/soundlib/Paula.h
new file mode 100644
index 00000000..527ea9e4
--- /dev/null
+++ b/Src/external_dependencies/openmpt-trunk/soundlib/Paula.h
@@ -0,0 +1,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