Exemple #1
0
bool SoundManager::PlayStream( const std::string& resource_path, double fadein_time, bool looped, int sound_group, U8 volume )
{
//	m_pSoundManagerImpl->PlayStream( resource_path, fadein_time, looped, sound_group, volume );

    if( m_mapNameToSoundSource.find( resource_path ) != m_mapNameToSoundSource.end() )
    {
        // A stream sound with the same name has already been loaded.
        return false;
    }

    SoundDesc desc;
    desc.Loop             = looped == 1 ? true : false;
    desc.Streamed         = true;
    desc.SourceManagement = SoundSource::Manual;

    SoundSource *pSource = CreateSoundSource( resource_path, desc );
    if( pSource )
    {
        m_mapNameToSoundSource[resource_path] = pSource;
        pSource->Play();
        return true;
    }
    else
    {
        LOG_PRINT_ERROR( "Cannot play streamed sound of: " + resource_path );
        return false;
    }
}
void CSound::PlaySample(size_t id, const float3& p, const float3& velocity, float volume, bool relative)
{
	boost::mutex::scoped_lock lck(soundMutex);

	if (sources.empty() || volume == 0.0f)
		return;

	if (id == 0)
	{
		numEmptyPlayRequests++;
		return;
	}

	if (p.distance(myPos) > sounds[id].MaxDistance())
	{
		if (!relative)
			return;
		else
			LogObject(LOG_SOUND) << "CSound::PlaySample: maxdist ignored for relative payback: " << sounds[id].Name();
	}

	SoundSource* best = GetNextBestSource(false);
	if (!best->IsPlaying() || (best->GetCurrentPriority() <= 0 && best->GetCurrentPriority() < sounds[id].GetPriority()))
		best->Play(&sounds[id], p, velocity, volume, relative);
	CheckError("CSound::PlaySample");
}
void SoundEffects::HandlePlaySound(StringHash eventType, VariantMap& eventData)
{
    Button* button = static_cast<Button*>(GetEventSender());
    const String& soundResourceName = button->GetVar(VAR_SOUNDRESOURCE).GetString();

    // Get the sound resource
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    Sound* sound = cache->GetResource<Sound>(soundResourceName);

    if (sound)
    {
        // Create a scene node with a SoundSource component for playing the sound. The SoundSource component plays
        // non-positional audio, so its 3D position in the scene does not matter. For positional sounds the
        // SoundSource3D component would be used instead
        Node* soundNode = scene_->CreateChild("Sound");
        SoundSource* soundSource = soundNode->CreateComponent<SoundSource>();
        soundSource->Play(sound);
        // In case we also play music, set the sound volume below maximum so that we don't clip the output
        soundSource->SetGain(0.75f);

        // Subscribe to the "sound finished" event generated by the SoundSource for removing the node once the sound has played
        // Note: the event is sent through the Node (similar to e.g. node physics collision and animation trigger events)
        // to not require subscribing to the particular component
        SubscribeToEvent(soundNode, E_SOUNDFINISHED, URHO3D_HANDLER(SoundEffects, HandleSoundFinished));
    }
}
Exemple #4
0
void MasterControl::Start()
{
    new InputMaster(context_, this);
    cache_ = GetSubsystem<ResourceCache>();
    graphics_ = GetSubsystem<Graphics>();
    renderer_ = GetSubsystem<Renderer>();
    CreateSineLookupTable();

    // Get default style
    defaultStyle_ = cache_->GetResource<XMLFile>("UI/DefaultStyle.xml");
    //Create console and debug HUD.
    CreateConsoleAndDebugHud();
    //Create the scene content
    CreateScene();
    //Create the UI content
    CreateUI();
    //Hook up to the frame update and render post-update events
    SubscribeToEvents();

    Sound* music = cache_->GetResource<Sound>("Resources/Music/Alien Chaos - Disorder.ogg"); //Battle
    music->SetLooped(true);
    Node* musicNode = world.scene->CreateChild("Music");
    SoundSource* musicSource = musicNode->CreateComponent<SoundSource>();
    musicSource->SetGain(0.32f);
    musicSource->SetSoundType(SOUND_MUSIC);
    musicSource->Play(music);
    
    
}
Exemple #5
0
void Bullet::Init(bool isPlayer, Vector2 spawnPosition)
{
	ResourceCache* cache = GetSubsystem<ResourceCache>();
	Graphics* graphics = GetSubsystem<Graphics>();

	halfHeight_ = graphics->GetHeight()  * PIXEL_SIZE * 0.5f;
	isPlayer_ = isPlayer;
	

	Sound* laserSound = cache->GetResource<Sound>(isPlayer_ ? "Sounds/laser01.wav" : "Sounds/laser02.wav");
	StaticSprite2D* sprite2D = node_->CreateComponent<StaticSprite2D>();

	if (isPlayer_)
		sprite2D->SetSprite( cache->GetResource<Sprite2D>("Sprites/blue_beam.png"));
	else
		sprite2D->SetSprite(cache->GetResource<Sprite2D>("Sprites/green_beam.png"));

	sprite2D->SetBlendMode(BLEND_ADDALPHA);

	SoundSource* soundSource = node_->CreateComponent<SoundSource>();
	soundSource->SetSoundType(SOUND_EFFECT);
	soundSource->SetGain(0.75f);
	soundSource->Play(laserSound);

	node_->SetPosition2D(spawnPosition);

	if (!isPlayer)
	{
		node_->Roll(180.0f);
	}
}
Exemple #6
0
void SoundSynthesis::CreateSound()
{
    // Sound source needs a node so that it is considered enabled
    node_ = new Node(context_);
    SoundSource* source = node_->CreateComponent<SoundSource>();

    soundStream_ = new BufferedSoundStream();
    // Set format: 44100 Hz, sixteen bit, mono
    soundStream_->SetFormat(44100, true, false);

    // Start playback. We don't have data in the stream yet, but the SoundSource will wait until there is data,
    // as the stream is by default in the "don't stop at end" mode
    source->Play(soundStream_);
}
Exemple #7
0
void SoundEffects::HandlePlayMusic(StringHash eventType, VariantMap& eventData)
{
    // Check if the music player node/component already exist
    if (scene_->GetChild("Music"))
        return;
    
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    Sound* music = cache->GetResource<Sound>("Music/Ninja Gods.ogg");
    // Set the song to loop
    music->SetLooped(true);
    
    // Create a scene node and a sound source for the music
    Node* musicNode = scene_->CreateChild("Music");
    SoundSource* musicSource = musicNode->CreateComponent<SoundSource>();
    // Set the sound type to music so that master volume control works correctly
    musicSource->SetSoundType(SOUND_MUSIC);
    musicSource->Play(music);
}
Exemple #8
0
void SoundEffects::HandlePlaySound(StringHash eventType, VariantMap& eventData)
{
    Button* button = static_cast<Button*>(GetEventSender());
    const String& soundResourceName = button->GetVar(VAR_SOUNDRESOURCE).GetString();
    
    // Get the sound resource
    ResourceCache* cache = GetSubsystem<ResourceCache>();
    Sound* sound = cache->GetResource<Sound>(soundResourceName);
    
    if (sound)
    {
        // Create a scene node with a SoundSource component for playing the sound. The SoundSource component plays
        // non-positional audio, so its 3D position in the scene does not matter. For positional sounds the
        // SoundSource3D component would be used instead
        Node* soundNode = scene_->CreateChild("Sound");
        SoundSource* soundSource = soundNode->CreateComponent<SoundSource>();
        soundSource->Play(sound);
        // In case we also play music, set the sound volume below maximum so that we don't clip the output
        soundSource->SetGain(0.75f);
        // Set the sound component to automatically remove its scene node from the scene when the sound is done playing
        soundSource->SetAutoRemove(true);
    }
}