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

mqPerformanceTest.cpp (3738B)


      1 #include <iostream>
      2 
      3 #include "synthLib/wavWriter.h"
      4 
      5 #include "mqLib/microq.h"
      6 #include "mqLib/mqhardware.h"
      7 
      8 #include "dsp56kEmu/jitunittests.h"
      9 #include "dsp56kEmu/threadtools.h"
     10 
     11 #include <vector>
     12 
     13 #include "mqConsoleLib/mqSettingsGui.h"
     14 
     15 using ButtonType = mqLib::Buttons::ButtonType;
     16 using EncoderType = mqLib::Buttons::Encoders;
     17 
     18 int main(int _argc, char* _argv[])
     19 {
     20 	std::cout << "Running unit tests..." << std::endl;
     21 
     22 	try
     23 	{
     24 //		dsp56k::InterpreterUnitTests tests;		// only valid if Interpreter is active
     25 		dsp56k::JitUnittests tests;				// only valid if JIT runtime is active
     26 //		return 0;
     27 	}
     28 	catch(std::string& _err)
     29 	{
     30 		std::cout << "Unit Test failed: " << _err << std::endl;
     31 		return -1;
     32 	}
     33 
     34 	std::cout << "Unit tests passed" << std::endl;
     35 
     36 	// create hardware
     37 	mqLib::MicroQ mq(mqLib::BootMode::Default);
     38 
     39 	if(!mq.isValid())
     40 	{
     41 		std::cout << "Failed to find OS update midi file. Put mq_2_23.mid next to this program" << std::endl;
     42 		std::cin.ignore();
     43 		return -2;
     44 	}
     45 
     46 	dsp56k::ThreadTools::setCurrentThreadName("main");
     47 
     48 	synthLib::AsyncWriter writer("mqOutput.wav", 44100, false);
     49 
     50 	constexpr uint32_t blockSize = 64;
     51 	std::vector<dsp56k::TWord> stereoOutput;
     52 	stereoOutput.resize(blockSize * 2);
     53 
     54 	bool waitingForBoot = true;
     55 	int counter = -1;
     56 
     57 	std::cout << "Device booting..." << std::endl;
     58 
     59 	mq.setButton(ButtonType::Play, true);
     60 
     61 	std::array<char,40> lastLcdContent{};
     62 	constexpr int lcdPrintDelay = 5000 / blockSize;
     63 	int lcdPrintTimer = -1;
     64 	bool foundEndText = false;
     65 
     66 	while(true)
     67 	{
     68 		if(waitingForBoot && mq.isBootCompleted())
     69 		{
     70 			std::cout << "Boot completed" << std::endl;
     71 
     72 			waitingForBoot = false;
     73 			mq.setButton(ButtonType::Play, false);
     74 			counter = 80000 / blockSize;
     75 		}
     76 
     77 		if(counter > 0)
     78 		{
     79 			--counter;
     80 			if(counter == 50000 / blockSize)
     81 			{
     82 				mq.setButton(ButtonType::Multimode, true);
     83 				std::cout << "Pressing Multimode + Peek" << std::endl;
     84 			}
     85 			if(counter == 40000 / blockSize)
     86 			{
     87 				mq.setButton(ButtonType::Peek, true);
     88 			}
     89 			else if(counter == (20000 / blockSize))
     90 			{
     91 				mq.setButton(ButtonType::Peek, false);
     92 				mq.setButton(ButtonType::Multimode, false);
     93 			}
     94 			else if(counter == (10000 / blockSize))
     95 			{
     96 				mq.setButton(ButtonType::Play, true);
     97 				std::cout << "Pressing Play to start demo playback" << std::endl;
     98 			}
     99 			else if(counter == 0)
    100 			{
    101 				mq.setButton(ButtonType::Play, false);
    102 
    103 				mq.getHardware()->getDspThread().setLogToStdout(true);
    104 			}
    105 		}
    106 		else
    107 		{
    108 			const auto& lcdData = mq.getHardware()->getUC().getLcd().getDdRam();
    109 			if(lcdData != lastLcdContent)
    110 			{
    111 				lcdPrintTimer = lcdPrintDelay;
    112 				lastLcdContent = lcdData;
    113 			}
    114 			else if(lcdPrintTimer > 0 && --lcdPrintTimer == 0)
    115 			{
    116 				auto printData = lcdData;
    117 				for (char& c : printData)
    118 				{
    119 					const auto u = static_cast<uint8_t>(c);
    120 					if(u < 32 || u > 127)
    121 						c = '?';
    122 				}
    123 
    124 				const auto lineA = std::string(&printData[0], 20);
    125 				const auto lineB = std::string(&printData[20], 20);
    126 				std::cout << "LCD: '" << lineA << "'" << std::endl << "LCD: '" << lineB << "'" << std::endl;
    127 
    128 				const auto hasEndText = lineA.find(" ...DEEPER ") != std::string::npos;
    129 
    130 				if(hasEndText)
    131 					foundEndText = true;
    132 				else if(foundEndText)
    133 					break;
    134 			}
    135 		}
    136 
    137 		mq.process(blockSize, 0);
    138 
    139 		if(counter == 0)
    140 		{
    141 			auto& outs = mq.getAudioOutputs();
    142 
    143 			for(size_t i=0; i<blockSize; ++i)
    144 			{
    145 				stereoOutput[(i<<1)  ] = outs[0][i];
    146 				stereoOutput[(i<<1)+1] = outs[1][i];
    147 			}
    148 
    149 			writer.append([&](std::vector<dsp56k::TWord>& _wavOut)
    150 			{
    151 				_wavOut.insert(_wavOut.end(), stereoOutput.begin(), stereoOutput.end());
    152 			});
    153 		}
    154 	}
    155 
    156 	std::cout << '\a';
    157 
    158 	std::cout << "Demo Playback has ended, press key to exit" << std::endl;
    159 
    160 	std::cin.ignore();
    161 
    162 	return 0;
    163 }