示例#1
0
SoundSourcePtr SoundManager::play(std::string filename, float fadetime, float gain)
{
    if(!m_audioEnabled)
        return nullptr;

    ensureContext();

    if(gain == 0)
        gain = 1.0f;

    filename = resolveSoundFile(filename);
    SoundSourcePtr soundSource = createSoundSource(filename);
    if(!soundSource) {
        g_logger.error(stdext::format("unable to play '%s'", filename));
        return nullptr;
    }

    soundSource->setName(filename);
    soundSource->setRelative(true);
    soundSource->setGain(gain);

    if(fadetime > 0)
        soundSource->setFading(StreamSoundSource::FadingOn, fadetime);

    soundSource->play();

    m_sources.push_back(soundSource);

    return soundSource;
}
示例#2
0
/** Positional sound is cool, but creating a new object just to play a simple
 *  menu sound is not. This function allows for 'quick sounds' in a single call.
 *  \param sound_type Internal name of the sfx to play.
 *  \return a pointer to the sound, for instance to check when the sound finished.
 *          don't delete the returned pointer.
 */
SFXBase* SFXManager::quickSound(const std::string &sound_type)
{
    if (!sfxAllowed()) return NULL;

    m_quick_sounds.lock();
    std::map<std::string, SFXBase*>::iterator sound = 
                                     m_quick_sounds.getData().find(sound_type);

    if (sound == m_quick_sounds.getData().end())
    {
        // sound not yet in our local list of quick sounds
        SFXBase* new_sound = createSoundSource(sound_type, false);
        if (new_sound == NULL) return NULL;
        new_sound->play();
        m_quick_sounds.getData()[sound_type] = new_sound;
        m_quick_sounds.unlock();
        return new_sound;
    }
    else
    {
        SFXBase *base_sound = sound->second;
        base_sound->play();
        m_quick_sounds.unlock();
        return base_sound;
    }

}   // quickSound
示例#3
0
void SoundManager::playMusic(const std::string& filename, float fadetime)
{
    if(m_currentMusic == filename && m_musicSource)
        return;
    m_currentMusic = filename;

    if(!m_musicEnabled)
        return;

    if(filename.empty()) {
        m_musicSource = nullptr;
        return;
    }

    m_musicSource = createSoundSource(filename);
    if(!m_musicSource) {
        g_logger.error(stdext::format("unable to play '%s'", filename));
        return;
    }

    m_musicSource->setRelative(true);

    if(fadetime > 0) {
        m_musicSource->setGain(0);
        m_musicSource->setFading(StreamSoundSource::FadingOn, fadetime);
    }

    m_musicSource->play();
}
示例#4
0
//----------------------------------------------------------------------------
SFXBase* SFXManager::createSoundSource(const std::string &name,
                                       const bool add_to_SFXList)
{
    std::map<std::string, SFXBuffer*>::iterator i = m_all_sfx_types.find(name);
    if ( i == m_all_sfx_types.end() )
    {
        Log::error("SFXManager", 
                   "SFXManager::createSoundSource could not find the "
                   "requested sound effect : '%s'.", name.c_str());
        return NULL;
    }

    return createSoundSource( i->second, add_to_SFXList );
}  // createSoundSource
示例#5
0
void OscScene::handleMessage(const std::string &method, lo_arg **argv, const char *types)
{
    UNUSED(types);
    if (method == "create_source")
    {
        if (OSCutil::typeTagsMatch(types, "s"))
            createSoundSource(reinterpret_cast<const char*>(argv[0]));
    }
    else if (method == "create_listener")
    {
        if (OSCutil::typeTagsMatch(types, "s"))
            createListener(reinterpret_cast<const char *>(argv[0]));
    }
    else
        std::cerr << "Unknown method " << method << std::endl;
}
示例#6
0
void SoundManager::play(const std::string& filename)
{
    if(!m_soundEnabled)
        return;

    SoundSourcePtr soundSource = createSoundSource(filename);
    if(!soundSource) {
        g_logger.error(stdext::format("unable to play '%s'", filename));
        return;
    }

    soundSource->setRelative(true);
    soundSource->play();

    m_sources.push_back(soundSource);
}