Example #1
0
void AudioManager::play_sample_playlist(SamplePlaylist *playlist, float volume)
{
	AudioSource *src;

	if (!playlist->started){
		src = request_source(&playlist->source_idx);
		if (src){
			playlist->it = playlist->samples.begin();
			src->set_sample((*playlist->it));
			src->set_volume(volume);
			src->set_playback_volume(volume);
			src->play();
			playlist->it++;
			playlist->started = true;
		}
	}
	else{
		src = get_audio_source(playlist->source_idx);
		if (src && !src->is_playing()){
			if (!(playlist->it == playlist->samples.end())){
				src->set_sample((*playlist->it));
				src->set_volume(volume);
				src->set_playback_volume(volume);
				src->play();
				playlist->it++;
			}
		}
	}

	if (playlist->loop && playlist->it == playlist->samples.end())
		playlist->it = playlist->samples.begin();
}
Example #2
0
int lua_AudioSource_play(lua_State* state)
{
    // Get the number of parameters.
    int paramCount = lua_gettop(state);

    // Attempt to match the parameters to a valid binding.
    switch (paramCount)
    {
        case 1:
        {
            if ((lua_type(state, 1) == LUA_TUSERDATA))
            {
                AudioSource* instance = getInstance(state);
                instance->play();
                
                return 0;
            }
            else
            {
                lua_pushstring(state, "lua_AudioSource_play - Failed to match the given parameters to a valid function signature.");
                lua_error(state);
            }
            break;
        }
        default:
        {
            lua_pushstring(state, "Invalid number of parameters (expected 1).");
            lua_error(state);
            break;
        }
    }
    return 0;
}
Example #3
0
void AudioManager::play_sample(AudioSample *sample, float volume, AUDIO_PLAYMODE mode, const Vector3 &position, int *src_idx)
{
	AudioSource *source = request_source(src_idx);
	if (source){
		source->set_sample(sample);
		source->set_volume(volume);
		source->set_playback_volume(volume);
		source->set_looping((bool)mode);
		source->set_position(position);
		source->play();
	}
}
void SceneManager::pop()
{
	if (m_activeList.empty()) 
	{
		throw std::runtime_error("Attempted to pop from an empty game state stack");
	}

	bool poppingExclusive = false;
	if (m_activeList.back().second == Modality::Exclusive)
	{
		poppingExclusive = true;
	}

	delete m_activeList.back().first;
	m_activeList.pop_back();

	if (!m_activeList.empty())
	{
		updateExclusiveScene();

		if (!poppingExclusive)
		{
			m_activeList.back().first->notifyUncoveredObjects();
		}

		auto go = m_activeList.back().first->getAllGameObjects();
		for (size_t i = 0; i < go.size(); i++)
		{
			//go[i]->activate();
			if (poppingExclusive)
			{
				go[i]->setEnabled(go[i]->wasEnabled(), false);
			}
		}

		if (poppingExclusive)
		{
			go = m_activeList[m_exclusiveScene].first->getAllGameObjects();
			for (size_t i = 0; i < go.size(); i++)
			{
				AudioSource * audio = go[i]->getGameComponent<AudioSource>();
				if (audio != nullptr)
				{
					if (audio->getType() == AudioType::STREAM && audio->wasPlaying())
					{
						audio->play();
					}
				}
			}
		}
	}
}
Example #5
0
void AudioController::resume()
{
#ifndef __ANDROID__    
    alcMakeContextCurrent(_alcContext);
#endif
    std::list<AudioSource*>::iterator itr = _playingSources.begin();

    // For each source that is playing, resume it.
    AudioSource* source = NULL;
    while (itr != _playingSources.end())
    {
        source = *itr;
        if (source->getState() == AudioSource::PAUSED)
        {
            source->play();
        }
        itr++;
    }
}