diff --git a/sdl2-hyper-sonic-drivers/CMakeLists.txt b/sdl2-hyper-sonic-drivers/CMakeLists.txt index c3c44dde..9a19cc5c 100644 --- a/sdl2-hyper-sonic-drivers/CMakeLists.txt +++ b/sdl2-hyper-sonic-drivers/CMakeLists.txt @@ -103,6 +103,7 @@ target_sources(${LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/MIDDriver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/IMidiDriver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/IMidiChannel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/IMidiChannelVoice.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/westwood/ADLDriver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/scummvm/MidiDriver_BASE.cpp @@ -113,6 +114,7 @@ target_sources(${LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/scummvm/MidiDriver_ADLIB.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/opl/OplDriver.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/opl/OplChannel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/midi/opl/OplVoice.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/HyperSonicDrivers/drivers/opl/OplWriter.cpp diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannel.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannel.hpp index a406cddb..9f747160 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannel.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannel.hpp @@ -2,6 +2,7 @@ #include #include +#include namespace HyperSonicDrivers::drivers::midi { @@ -24,7 +25,7 @@ namespace HyperSonicDrivers::drivers::midi const bool isPercussion; protected: - + std::list m_voices; // MIDI Events //virtual void noteOff(const uint8_t note) noexcept = 0; //virtual void noteOn(const uint8_t note, const uint8_t vol) noexcept = 0; diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannelVoice.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannelVoice.hpp index 3175dc3b..96108508 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannelVoice.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/IMidiChannelVoice.hpp @@ -1,10 +1,12 @@ #pragma once #include -#include +//#include namespace HyperSonicDrivers::drivers::midi { + class IMidiChannel; + /** * Interface for Midi Channel Voice message to have a polyphonic MidiChannel. * this is mono-phonic channel, multiple combination of this gives a polyphonic MidiChannel @@ -15,14 +17,32 @@ namespace HyperSonicDrivers::drivers::midi IMidiChannelVoice() = default; virtual ~IMidiChannelVoice() = default; + inline IMidiChannel* getChannel() const noexcept { return m_channel; } + uint8_t getChannelNum() const noexcept; + inline uint8_t getNote() const noexcept { return m_note; } + inline uint8_t getVolume() const noexcept { return m_volume; }; + void setVolumes(const uint8_t volume) noexcept; + inline bool isFree() const noexcept { return m_free; } + inline bool isVibrato() const noexcept { return m_vibrato; } + protected: IMidiChannel* m_channel = nullptr; // MIDI channel uint8_t m_note = 0; /* note number */ uint8_t m_volume = 0; /* note volume */ + uint8_t m_real_volume = 0; /* adjusted note volume */ int16_t m_pitch_factor = 0; /* pitch-wheel value */ bool m_free = true; - bool m_sustain = false; - bool m_vibrato = false; + bool m_sustain = false; // this are Opl exclusive or are midi? + bool m_vibrato = false; // "" + + private: + /// + /// The volume is between 0-127 as a per MIDI specification. + /// OPLWriter expect a MIDI volume value and converts to OPL value. + /// OPL chips has a volume attenuation (inverted values) + /// range from 0-64 inverted (0 is max, 64 is muted). + /// + uint8_t calcVolume_() const noexcept; }; } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/opl/OplVoice.cpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/opl/OplVoice.cpp index 6d8e0cb3..ec0ef3fd 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/opl/OplVoice.cpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/opl/OplVoice.cpp @@ -2,17 +2,16 @@ #include #include #include +#include namespace HyperSonicDrivers::drivers::midi::opl { using audio::midi::MIDI_PERCUSSION_CHANNEL; using hardware::opl::OPL2instrument_t; - constexpr int VIBRATO_THRESHOLD = 40; constexpr int8_t HIGHEST_NOTE = 127; - OplVoice::OplVoice(const uint8_t slot, const drivers::opl::OplWriter* oplWriter) : m_slot(slot), m_oplWriter(oplWriter) { @@ -194,10 +193,4 @@ namespace HyperSonicDrivers::drivers::midi::opl m_instr = instr; } - - void OplVoice::setVolumes(const uint8_t volume) noexcept - { - m_volume = volume; - m_real_volume = calcVolume_(); - } } diff --git a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/opl/OplVoice.hpp b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/opl/OplVoice.hpp index 5a3d50e2..d64148ea 100644 --- a/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/opl/OplVoice.hpp +++ b/sdl2-hyper-sonic-drivers/src/HyperSonicDrivers/drivers/midi/opl/OplVoice.hpp @@ -5,12 +5,12 @@ #include #include #include -#include namespace HyperSonicDrivers::drivers::midi::opl { constexpr int opl_sustain_threshold = 64; + /// /// This is only the execution for a MidiChannel /// used in a MIDI Channel -> Opl Channel @@ -24,7 +24,6 @@ namespace HyperSonicDrivers::drivers::midi::opl /// /// It might release the note depending on sustains value /// - /// /// /// /// true = voice released. false=voice sutained @@ -50,43 +49,22 @@ namespace HyperSonicDrivers::drivers::midi::opl void pause() const noexcept; void resume() const noexcept; - void setVolumes(const uint8_t volume) noexcept; - // - //inline IMidiChannel* getChannel() const noexcept { return m_channel; } - inline uint8_t getChannelNum() const noexcept { return m_channel->channel; } inline const hardware::opl::OPL2instrument_t* getInstrument() const noexcept { return m_instr; } // Methods to get private variables, not really used inline uint8_t getSlot() const noexcept { return m_slot; } - inline bool isFree() const noexcept { return m_free; } inline bool isSecondary() const noexcept { return m_secondary; } - inline bool isVibrato() const noexcept { return m_vibrato; } - inline uint8_t getNote() const noexcept { return m_note; } protected: void setInstrument(const hardware::opl::OPL2instrument_t* instr) noexcept; - //inline uint8_t getRealVolume() const noexcept { return m_real_volume; } - //inline void setRealVolume(const uint8_t volume) noexcept { m_real_volume = calcVolume_(); } private: + const drivers::opl::OplWriter* m_oplWriter; const uint8_t m_slot; /* OPL channel number */ - uint8_t m_real_volume = 0; /* adjusted note volume */ uint8_t m_real_note = 0; /* adjusted note number */ int8_t m_finetune = 0; /* frequency fine-tune */ const hardware::opl::OPL2instrument_t* m_instr = nullptr; /* current instrument */ bool m_secondary = false; - - const drivers::opl::OplWriter* m_oplWriter; - - /// - /// The volume is between 0-127 as a per MIDI specification. - /// OPLWriter expect a MIDI volume value and converts to OPL value. - /// OPL chips has a volume attenuation (inverted values) - /// range from 0-64 inverted (0 is max, 64 is muted). - /// - inline uint8_t calcVolume_() const noexcept { - return std::min((static_cast(m_volume) * m_channel->volume / 127), 127); - } }; } diff --git a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/midi/opl/TestOplVoice.cpp b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/midi/opl/TestOplVoice.cpp index b347a423..6cfa27af 100644 --- a/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/midi/opl/TestOplVoice.cpp +++ b/sdl2-hyper-sonic-drivers/test/HyperSonicDrivers/drivers/midi/opl/TestOplVoice.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace HyperSonicDrivers::drivers::midi::opl {