From 4dfe9f97fbda6552f4b52cb93ad70d8b2a4f6848 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 7 Apr 2022 15:46:48 -0500 Subject: [PATCH] prepare for wavetable synth --- CMakeLists.txt | 1 + src/engine/instrument.h | 42 ++++++++++++++++++++++++++++++++++++ src/engine/waveSynth.cpp | 5 +++++ src/engine/waveSynth.h | 46 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 src/engine/waveSynth.cpp create mode 100644 src/engine/waveSynth.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a01272803..c5fc06e70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -302,6 +302,7 @@ src/engine/sample.cpp src/engine/song.cpp src/engine/sysDef.cpp src/engine/wavetable.cpp +src/engine/waveSynth.cpp src/engine/vgmOps.cpp src/engine/platform/abstract.cpp src/engine/platform/genesis.cpp diff --git a/src/engine/instrument.h b/src/engine/instrument.h index ab00c9aab..1c8525436 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -477,6 +477,47 @@ struct DivInstrumentFDS { } }; +enum DivWaveSynthEffects { + DIV_WS_NONE=0, + // one waveform effects + DIV_WS_INVERT, + DIV_WS_ADD, + DIV_WS_SUBTRACT, + DIV_WS_AVERAGE, + DIV_WS_PHASE, + // two waveform effects + DIV_WS_NONE_DUAL=128, + DIV_WS_WIPE, + DIV_WS_FADE, + DIV_WS_PING_PONG, + DIV_WS_OVERLAY, + DIV_WS_NEGATIVE_OVERLAY, + DIV_WS_PHASE_DUAL, +}; + +struct DivInstrumentWaveSynth { + int wave1, wave2; + unsigned char rateDivider, width, height; + DivWaveSynthEffects effect; + bool oneShot, enabled, global; + unsigned char speed, param1, param2, param3, param4; + DivInstrumentWaveSynth(): + wave1(0), + wave2(0), + rateDivider(1), + width(32), + height(32), + effect(DIV_WS_NONE), + oneShot(false), + enabled(false), + global(false), + speed(1), + param1(0), + param2(0), + param3(0), + param4(0) {} +}; + struct DivInstrument { String name; bool mode; @@ -488,6 +529,7 @@ struct DivInstrument { DivInstrumentAmiga amiga; DivInstrumentN163 n163; DivInstrumentFDS fds; + DivInstrumentWaveSynth ws; /** * save the instrument to a SafeWriter. diff --git a/src/engine/waveSynth.cpp b/src/engine/waveSynth.cpp new file mode 100644 index 000000000..ca3f342c7 --- /dev/null +++ b/src/engine/waveSynth.cpp @@ -0,0 +1,5 @@ +#include "waveSynth.h" + +bool DivWaveSynth::tick() { + return false; +} \ No newline at end of file diff --git a/src/engine/waveSynth.h b/src/engine/waveSynth.h new file mode 100644 index 000000000..5e5fd6540 --- /dev/null +++ b/src/engine/waveSynth.h @@ -0,0 +1,46 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _WAVESYNTH_H +#define _WAVESYNTH_H + +#include "instrument.h" +#include "wavetable.h" + +class DivWaveSynth { + DivInstrument* ins; + int pos, stage, divCounter; + int output[256]; + public: + /** + * tick this DivWaveSynth. + * @return whether the wave has changed. + */ + bool tick(); + void init(DivInstrument* ins); + DivWaveSynth(): + ins(NULL), + pos(0), + stage(0), + divCounter(0) { + memset(output,0,sizeof(int)*256); + } +}; + +#endif