OPLMIDIDevice::OPLMIDIDevice(const char *args)
{
	OPL_SetCore(args);
	FullPan = opl_fullpan;
	FWadLump data = Wads.OpenLumpName("GENMIDI");
	OPLloadBank(data);
	SampleRate = (int)OPL_SAMPLE_RATE;
}
OPLMIDIDevice::OPLMIDIDevice()
{
	Stream = NULL;
	Tempo = 0;
	Division = 0;
	Events = NULL;
	Started = false;

	FWadLump data = Wads.OpenLumpName("GENMIDI");
	OPLloadBank(data);
}
示例#3
0
OPLmusicBlock::OPLmusicBlock (FILE *file, int len, int rate, int maxSamples)
	: SampleRate (rate), NextTickIn (0), Looping (false), ScoreLen (len)
{
	scoredata = NULL;
	SampleBuff = NULL;
	TwoChips = !opl_onechip;
	io = new OPLio;

#ifdef _WIN32
	InitializeCriticalSection (&ChipAccess);
#else
	ChipAccess = SDL_CreateMutex ();
	if (ChipAccess == NULL)
	{
		return;
	}
#endif

	scoredata = new BYTE[len];
	if (fread (scoredata, 1, len, file) != (size_t)len || io->OPLinit (TwoChips + 1, rate))
	{
		delete[] scoredata;
		scoredata = NULL;
		return;
	}

	// Check for MUS format
	if (*(DWORD *)scoredata == MAKE_ID('M','U','S',0x1a))
	{
		FWadLump data = Wads.OpenLumpName ("GENMIDI");
		if (0 != OPLloadBank (data))
		{
			delete[] scoredata;
			scoredata = NULL;
			return;
		}
		BlockForStats = this;
		SamplesPerTick = ((rate/14)+5)/10;	// round to nearest, not lowest
		RawPlayer = NotRaw;
	}
	// Check for RDosPlay raw OPL format
	else if (((DWORD *)scoredata)[0] == MAKE_ID('R','A','W','A') &&
			 ((DWORD *)scoredata)[1] == MAKE_ID('D','A','T','A'))
	{
		RawPlayer = RDosPlay;
		if (*(WORD *)(scoredata + 8) == 0)
		{ // A clock speed of 0 is bad
			*(WORD *)(scoredata + 8) = 0xFFFF; 
		}
		SamplesPerTick = Scale (rate, SHORT(*(WORD *)(scoredata + 8)), 1193180);
	}
	// Check for modified IMF format (includes a header)
	else if (((DWORD *)scoredata)[0] == MAKE_ID('A','D','L','I') &&
		     scoredata[4] == 'B' && scoredata[5] == 1)
	{
		int songlen;
		BYTE *max = scoredata + ScoreLen;
		RawPlayer = IMF;
		SamplesPerTick = rate / IMF_RATE;

		score = scoredata + 6;
		// Skip track and game name
		for (int i = 2; i != 0; --i)
		{
			while (score < max && *score++ != '\0') {}
		}
		if (score < max) score++;	// Skip unknown byte
		if (score + 8 > max)
		{ // Not enough room left for song data
			delete[] scoredata;
			scoredata = NULL;
			return;
		}
		songlen = LONG(*(DWORD *)score);
		if (songlen != 0 && (songlen +=4) < ScoreLen - (score - scoredata))
		{
			ScoreLen = songlen + int(score - scoredata);
		}
	}

	SampleBuff = new int[maxSamples];
	Restart ();
}