QtFM::Chip Class
The Chip class gives register-level access to a chip core that an Engine runs. More…
| Header | #include <QtFM> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::FM) |
| Module | Nt FM C++ Classes |
List of all members, including inherited members
Public Functions
| ChipType | type() const |
| void | writeRegister(quint16 reg, quint8 value, float delay = 0) |
| void | reset() |
| void | setGain(float dB) |
Detailed Description
Get a chip from Engine::chip(), after naming it in EngineConfig::chips. Writes are sent to the audio thread like every other command, so they are thread-safe and never block, and a delay places a write on an exact sample:
EngineConfig config;
config.chips = {ChipType::OPL2};
Engine engine(config);
Chip *opl = engine.chip(ChipType::OPL2);
// An organ-like tone on channel 0, as an AdLib driver would set it up.
const quint8 setup[][2] = {{0x20, 0x01}, {0x40, 0x10}, {0x60, 0xf0}, {0x80, 0x77},
{0x23, 0x01}, {0x43, 0x00}, {0x63, 0xf0}, {0x83, 0x77}};
for (const auto &w : setup)
opl->writeRegister(w[0], w[1]);
// A C major arpeggio: frequency number 0x157 is C in block 4; key on, then off.
const int fnums[] = {0x157, 0x1b0, 0x202, 0x2ae};
for (int i = 0; i < 4; ++i) {
const float t = 0.25f * float(i);
opl->writeRegister(0xa0, quint8(fnums[i] & 0xff), t);
opl->writeRegister(0xb0, quint8(0x20 | (4 << 2) | (fnums[i] >> 8)), t);
opl->writeRegister(0xb0, quint8((4 << 2) | (fnums[i] >> 8)), t + 0.2f);
}
Voices that Engine::play() starts on the chip use its channels too: a game that writes registers itself should not also play patches for that chip.
Differences from Qt
Registers cannot be read back.
Member Function Documentation
void QtFM::Chip::reset()
Resets the chip and frees every channel that voices were playing on.
void QtFM::Chip::setGain(float dB)
Sets the gain of the chip's output to dB.
ChipType QtFM::Chip::type() const
Returns the type of the chip.
void QtFM::Chip::writeRegister(quint16 reg, quint8 value, float delay = 0)
Writes value to the register reg of the chip, delay seconds after the engine's current render position.