Example #1
0
int AdLibMusic::readBuffer(int16 *data, const int numSamples) {
	if (_musicData == NULL) {
		// no music loaded
		memset(data, 0, numSamples * sizeof(int16));
	} else if ((_currentMusic == 0) || (_numberOfChannels == 0)) {
		// music loaded but not played as of yet
		memset(data, 0, numSamples * sizeof(int16));
		// poll anyways as pollMusic() can activate the music
		pollMusic();
		_nextMusicPoll = _sampleRate / 50;
	} else {
		uint32 render;
		uint remaining = numSamples;
		while (remaining) {
			render = (remaining > _nextMusicPoll) ? _nextMusicPoll : remaining;
			remaining -= render;
			_nextMusicPoll -= render;
			YM3812UpdateOne(_opl, data, render);
			data += render;
			if (_nextMusicPoll == 0) {
				pollMusic();
				_nextMusicPoll = _sampleRate / 50;
			}
		}
	}
	return numSamples;
}
Example #2
0
void GmMusic::timerCall(void) {
	_timerCount += _midiDrv->getBaseTempo();
	if (_timerCount > (1000000 / 50)) {
		// call pollMusic() 50 times per second
		_timerCount -= 1000000 / 50;
		if (_musicData != NULL)
			pollMusic();
	}
}
Example #3
0
void playMusic(std::string file, float volume)
{
	if (playingFile == file) {
		return;
	}

	if (playing != NULL) {
		al_stop_duh(player);
		unload_duh(playing);
	}

	std::string fileName = ResourceHandler::getInstance()->getRealFilename(file);

	if (!exists(fileName.c_str())) {
		throw DBSH07_EXCEPTION("Unable to load " + fileName);
	}

	playing = dumb_load_xm_quick(fileName.c_str());
	player = al_start_duh(playing, 2, 0, volume, 4096, 44100);
	playingFile = file;

	pollMusic();
}
Example #4
0
void Game::logic()
{
	pollMusic();

    switch (mState) 
    {
        case SPLASHSCREEN:
            mSplashScreen->logic();
            if (mSplashScreen->isDrawingDone())
            {
				clear_keybuf();
                setState(MENU);
            }
            break;
        case BONUS_LEVEL_OR_SHOP:
            mLevel->logic();
            if (mOptionalDialog->getState() == OptionalDialog::NONE
                && !mOptionalDialog->isVisible()
                    && !mDialog->isVisible())
            {
                mOptionalDialog->setVisible(true);
            }
            else if (!mDialog->isVisible()
                && mOptionalDialog->getState() == OptionalDialog::SHOP)
            {
                setState(SHOP);
            }
            else if (!mDialog->isVisible()
                && mOptionalDialog->getState() == OptionalDialog::BONUS_LEVEL)
            {
                startNextLevel();
            }
            break;
        case HIGH_SCORE:
        case SHOP:
        case MENU:
			break;
        case LEVEL:
            mLevel->logic();
            if (mLevel->isGameOver())
            {
                setState(HIGH_SCORE);
            }
            else if (mLevel->isLevelComplete())
            {
                std::cout << "LEVEL COMPLETE" << std::endl;
                prepareNextLevel();
            }
            else if (mLevel->isQuit())
            {
                setState(MENU);
            }
            break;
		case END:
			mEnding->logic();

			if (mEnding->isDone())
			{
				setState(HIGH_SCORE);
			}
            break;
        case PAUSE:
            break;
        case EXIT:
            break;
   	    default:
			throw DBSH07_EXCEPTION("Unknown game state.");
   }
   
      mGui->logic();

    if (key[KEY_F10]) 
    {
        setState(EXIT);
    }

    if (key[KEY_P] && !mPauseButtonPressed && mState == PAUSE)
    {
        setState(LEVEL);
    }
    else if (key[KEY_P] && !mPauseButtonPressed && mState == LEVEL)
    {
        setState(PAUSE);
    }

    mPauseButtonPressed = key[KEY_P] != 0;
}