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

n2xrom.cpp (690B)


      1 #include "n2xrom.h"
      2 
      3 #include <algorithm>
      4 
      5 namespace n2x
      6 {
      7 	Rom::Rom()
      8 	{
      9 		if(!isValidRom(data()))
     10 			invalidate();
     11 	}
     12 
     13 	Rom::Rom(const std::string& _filename) : RomData(_filename)
     14 	{
     15 		if(!isValidRom(data()))
     16 			invalidate();
     17 	}
     18 
     19 	Rom::Rom(const std::vector<uint8_t>& _data, const std::string& _filename) : RomData(_data, _filename)
     20 	{
     21 		if(!isValidRom(data()))
     22 			invalidate();
     23 	}
     24 
     25 	bool Rom::isValidRom(const std::vector<uint8_t>& _data)
     26 	{
     27 		constexpr uint8_t key[] = {'n', 'r', '2', 0, 'n', 'L', '2', 0};
     28 
     29 		if(_data.size() < std::size(key))
     30 			return false;
     31 
     32 		const auto it = std::search(_data.begin(), _data.end(), std::begin(key), std::end(key));
     33 		return it != _data.end();
     34 	}
     35 }