ScummVM API documentation
pcspk_pit.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef MADS_CORE_PCSPK_PIT_H
23#define MADS_CORE_PCSPK_PIT_H
24
25#include "common/array.h"
26#include "common/scummsys.h"
27
28namespace MADS {
29
38public:
39 explicit PCSpeakerPITRenderer(uint32 sampleRate,
40 uint32 pitClock = 1193182);
42
44 void advanceToSampleFraction(uint32 numerator, uint32 denominator);
45 void writeMode3Count(uint16 count);
46 void setControl(bool timerGate, bool speakerEnabled);
47 int16 generateSample(byte volume);
48
49private:
50 class PCSpeakerOutputStage;
51
52 enum {
53 kFractionalPhases = 32,
54 kImpulseDurationUs = 3125,
55 kSampleFracBits = 24,
56 kCoefficientFracBits = 30
57 };
58
59 void initializeImpulse();
60 void resetState();
61 void addTransition(int level, uint64 elapsedPitClocks = 0);
62 void advanceCounter(uint64 pitClockUnits);
63 bool isUndersampled(uint16 count) const;
64 int outputLevel() const;
65
66 uint32 _sampleRate;
67 uint32 _pitClock;
68 uint64 _phase;
69 uint64 _samplePhase;
70 uint64 _sampleCounter;
71 uint16 _count;
72 uint16 _pendingCount;
73 bool _hasPendingCount;
74 bool _counterLoaded;
75 bool _timerGate;
76 bool _speakerEnabled;
77 bool _high;
78 bool _undersampled;
79 bool _hasUndersampledReload;
80 uint64 _lastUndersampledReloadSample;
81
82 uint32 _impulseLength;
83 uint32 _impulseHead;
84 Common::Array<int32> _impulseLut;
85 Common::Array<int32> _impulseBuffer;
86 int32 _reconstructedLevel;
87 int _targetLevel;
88 PCSpeakerOutputStage *_outputStage;
89
92};
93
94} // End of namespace MADS
95
96#endif // MADS_CORE_PCSPK_PIT_H
Definition: pcspk_pit.h:37
void advanceToSampleFraction(uint32 numerator, uint32 denominator)