void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
    // If there is already a background music source we stop it first
    if (s_backgroundSource != AL_NONE)
        stopBackgroundMusic(false);

    // Changing file path to full path
    std::string fullPath = FileUtils::getInstance()->fullPathForFilename(pszFilePath);

    BackgroundMusicsMap::const_iterator it = s_backgroundMusics.find(fullPath);
    if (it == s_backgroundMusics.end())
    {
        preloadBackgroundMusic(fullPath.c_str());
        it = s_backgroundMusics.find(fullPath);
    }

    if (it != s_backgroundMusics.end())
    {
        s_backgroundSource = it->second->source;
        alSourcei(s_backgroundSource, AL_LOOPING, bLoop ? AL_TRUE : AL_FALSE);
        setBackgroundVolume(s_volume);
        alSourcePlay(s_backgroundSource);
        checkALError("playBackgroundMusic:alSourcePlay");
    }
}
	void SimpleAudioEngine::setBackgroundMusicVolume(float volume)
	{
		if (s_volume != volume && volume >= -0.0001 && volume <= 1.0001)
		{
    		s_volume = volume;

			setBackgroundVolume(volume);
		}
	}
void SimpleAudioEngine::setBackgroundMusicVolume(float volume)
{
    if (s_volume != volume && volume >= -0.0001 && volume <= 1.0001)
    {
        s_volume = volume;

        // No source, no background music, no volume adjustment
        if (s_backgroundSource != AL_NONE)
        {
            setBackgroundVolume(volume);
        }
    }
}
	//
	// background audio (using mmrenderer)
	//
    void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
	{
    	if (!s_isBackgroundInitialized)
    	{
    		const char 		*mmrname = NULL;
    		const char 		*ctxtname = "mmrplayer";
    		char 			 cwd[PATH_MAX];
    		mode_t 			 mode = S_IRUSR | S_IXUSR;

    		getcwd(cwd, PATH_MAX);
    		string path = "file://";
    		path += cwd;
    		path += "/";
    		path += pszFilePath;

    		s_mmrConnection = mmr_connect(mmrname);
    		if (!s_mmrConnection)
    		{
    			perror("mmr_connect");
    			s_hasMMRError = true;
    			return;
    		}

    		s_mmrContext = mmr_context_create(s_mmrConnection, ctxtname, 0, mode);
    		if (!s_mmrContext)
    		{
    			perror(ctxtname);
    			s_hasMMRError = true;
    			return;
    		}

    		if ((s_audioOid = mmr_output_attach(s_mmrContext, "audio:default", "audio")) < 0)
    		{
    			mmrerror(s_mmrContext, "audio:default");
    			return;
    		}

    		if (mmr_input_attach(s_mmrContext, path.data(), "autolist") < 0)
    		{
    			fprintf(stderr, "unable to load %s\n", path.data());
    			mmrerror(s_mmrContext, path.data());
    			return;
    		}

    		s_currentBackgroundStr 	  = pszFilePath;
			s_isBackgroundInitialized = true;
			setBackgroundVolume(s_volume);
    	}
	}