UNPKG

broken-neees

Version:

A really broken NEEES emulator that introduces glitches and random bugs on purpose!

41 lines (37 loc) 800 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; const APU_MAX_VOLUME = 15; class VolumeEnvelope { constructor() { // input this.startFlag = false; // output this.dividerCount = 0; this.volume = 0; } clock(period, loop) { // start if needed if (this.startFlag) { this.startFlag = false; this.volume = APU_MAX_VOLUME; this.dividerCount = period; return; } // wait until dividerCount == 0 if (this.dividerCount > 0) { this.dividerCount--; return; } // change volume this.dividerCount = period; if (this.volume === 0) { if (loop) this.volume = APU_MAX_VOLUME; } else { this.volume--; } } } exports.default = VolumeEnvelope;