gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

romfile.h (2973B)


      1 #pragma once
      2 
      3 #include <thread>
      4 #include <vector>
      5 #include <string>
      6 
      7 #include "dsp56kEmu/types.h"
      8 
      9 #include "baseLib/md5.h"
     10 
     11 #include "deviceModel.h"
     12 
     13 namespace dsp56k
     14 {
     15 	class HDI08;
     16 	class DSP;
     17 }
     18 
     19 namespace virusLib
     20 {
     21 class DspSingle;
     22 
     23 class ROMFile
     24 {
     25 public:
     26 	struct Chunk
     27 	{
     28 		uint8_t chunk_id = 0;
     29 		uint8_t size1 = 0;
     30 		uint8_t size2 = 0;
     31 		std::vector<uint32_t> items;
     32 	};
     33 
     34 	struct BootRom
     35 	{
     36 		uint32_t size = 0;
     37 		uint32_t offset = 0;
     38 		std::vector<uint32_t> data;
     39 	};
     40 
     41 	using TPreset = std::array<uint8_t, 512>;
     42 
     43 	explicit ROMFile(std::vector<uint8_t> _data, std::string _name, DeviceModel _model = DeviceModel::ABC);
     44 
     45 	static ROMFile invalid();
     46 
     47 	bool getMulti(int _presetNumber, TPreset& _out) const;
     48 	bool getSingle(int _bank, int _presetNumber, TPreset& _out) const;
     49 	bool getPreset(uint32_t _offset, TPreset& _out) const;
     50 
     51 	static std::string getSingleName(const TPreset& _preset);
     52 	static std::string getMultiName(const TPreset& _preset);
     53 	static std::string getPresetName(const TPreset& _preset, uint32_t _first, uint32_t _last);
     54 
     55 	std::thread bootDSP(DspSingle& _dsp) const;
     56 
     57 	bool isValid() const { return m_bootRom.size > 0; }
     58 
     59 	DeviceModel getModel() const { return m_model; }
     60 
     61 	std::string getModelName() const;
     62 
     63 	bool isTIFamily() const { return virusLib::isTIFamily(m_model); }
     64 
     65 	uint32_t getSamplerate() const
     66 	{
     67 		return isTIFamily() ? 44100 : 12000000 / 256;
     68 	}
     69 
     70 	static uint32_t getMultiPresetSize(const DeviceModel _model)
     71 	{
     72 		return 256;
     73 //		return isTIFamily(_model) ? 256 : 256;
     74 	}
     75 	uint32_t getMultiPresetSize() const
     76 	{
     77 		return getMultiPresetSize(m_model);
     78 	}
     79 
     80 	static uint32_t getSinglePresetSize(const DeviceModel _model)
     81 	{
     82 		return virusLib::isTIFamily(_model) ? 512 : 256;
     83 	}
     84 	uint32_t getSinglePresetSize() const
     85 	{
     86 		return getSinglePresetSize(m_model);
     87 	}
     88 
     89 	static uint8_t getSinglesPerBank()
     90 	{
     91 		return 128;
     92 	}
     93 
     94 	static constexpr uint32_t getRomSizeModelD()
     95 	{
     96 		return 1024 * 1024;
     97 	}
     98 
     99 	static constexpr uint32_t getRomSizeModelDInstaller()
    100 	{
    101 		return 1024 * 1024 * 7;
    102 	}
    103 
    104 	static constexpr uint32_t getRomSizeModelABC()
    105 	{
    106 		return 1024 * 512;
    107 	}
    108 
    109 	uint8_t getPresetsPerBank() const
    110 	{
    111 		return 128;
    112 	}
    113 
    114 	static uint32_t getRomBankCount(DeviceModel _model);
    115 
    116 	const std::vector<uint8_t>& getDemoData() const { return m_demoData; }
    117 
    118 	std::string getFilename() const { return isValid() ? m_romFileName : std::string(); }
    119 
    120 	const auto& getHash() const { return m_romDataHash; }
    121 
    122 	const auto& getRomFileData() const { return m_romFileData; }
    123 
    124 private:
    125 	std::vector<Chunk> readChunks(std::istream& _file) const;
    126 	bool loadPresetFiles();
    127 	bool loadPresetFile(std::istream& _file, DeviceModel _model);
    128 
    129 	bool initialize();
    130 
    131 	BootRom m_bootRom;
    132 	std::vector<uint32_t> m_commandStream;
    133 
    134 	DeviceModel m_model = DeviceModel::Invalid;
    135 
    136 	std::vector<TPreset> m_singles;
    137 	std::vector<TPreset> m_multis;
    138 	std::vector<uint8_t> m_demoData;
    139 
    140 	std::string m_romFileName;
    141 	std::vector<uint8_t> m_romFileData;
    142 	baseLib::MD5 m_romDataHash;
    143 };
    144 
    145 }