Skip to content

Commit

Permalink
clean-ups
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed Sep 30, 2023
1 parent eeb7274 commit f0fd8eb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 36 deletions.
2 changes: 2 additions & 0 deletions sdl2-hyper-sonic-drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdint>
#include <list>
#include <HyperSonicDrivers/drivers/midi/IMidiChannelVoice.hpp>

namespace HyperSonicDrivers::drivers::midi
{
Expand All @@ -24,7 +25,7 @@ namespace HyperSonicDrivers::drivers::midi
const bool isPercussion;

protected:

std::list<IMidiChannelVoice> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#pragma once

#include <cstdint>
#include <HyperSonicDrivers/drivers/midi/IMidiChannel.hpp>
//#include <HyperSonicDrivers/drivers/midi/IMidiChannel.hpp>

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
Expand All @@ -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:
/// <summary>
/// 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).
/// </summary>
uint8_t calcVolume_() const noexcept;
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
#include <HyperSonicDrivers/drivers/midi/opl/OplVoice.hpp>
#include <HyperSonicDrivers/hardware/opl/OPL2instrument.h>
#include <HyperSonicDrivers/utils/ILogger.hpp>
#include <HyperSonicDrivers/drivers/midi/IMidiChannel.hpp>

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)
{
Expand Down Expand Up @@ -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_();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <HyperSonicDrivers/audio/opl/banks/OP2Bank.hpp>
#include <HyperSonicDrivers/hardware/opl/OPL2instrument.h>
#include <HyperSonicDrivers/drivers/opl/OplWriter.hpp>
#include <HyperSonicDrivers/drivers/midi/IMidiChannel.hpp>

namespace HyperSonicDrivers::drivers::midi::opl
{
constexpr int opl_sustain_threshold = 64;


/// <summary>
/// This is only the execution for a MidiChannel
/// used in a MIDI Channel -> Opl Channel
Expand All @@ -24,7 +24,6 @@ namespace HyperSonicDrivers::drivers::midi::opl
/// <summary>
/// It might release the note depending on sustains value
/// </summary>
/// <param name="channel"></param>
/// <param name="note"></param>
/// <param name="sustain"></param>
/// <returns>true = voice released. false=voice sutained</returns>
Expand All @@ -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;

/// <summary>
/// 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).
/// </summary>
inline uint8_t calcVolume_() const noexcept {
return std::min<uint8_t>((static_cast<uint32_t>(m_volume) * m_channel->volume / 127), 127);
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <HyperSonicDrivers/hardware/opl/OPL2instrument.h>
#include <HyperSonicDrivers/files/dmx/OP2File.hpp>
#include <HyperSonicDrivers/hardware/opl/OPLMock.hpp>
#include <HyperSonicDrivers/drivers/midi/IMidiChannel.hpp>

namespace HyperSonicDrivers::drivers::midi::opl
{
Expand Down

0 comments on commit f0fd8eb

Please sign in to comment.