Example #1
0
bool DDAudio::OnAssetReload(Asset& asset)
{
    dsprintf("Being asked to load [%s]\n", asset.Name().c_str());
    if(asset.Type() == Asset::Sound)
    {
        ALuint buffer;
        ALsizei size;
        ALsizei frequency;
        ALenum format;

        bool success = Wave::LoadToOpenALBuffer(asset.Path().c_str(),
                                 &buffer, &size, &frequency, &format);

        if(!success)
        {
            return false;
        }

        mSoundNameId.insert
        (
            std::pair<std::string, int>
            (
                std::string(asset.Name()),
                buffer
            )
        );

        return true;
    }
    else if(asset.Type() == Asset::Stream)
    {
        mStreamNameAsset.insert
        (
            std::pair<std::string, Asset*>
            (
                std::string(asset.Name()),
                &asset
            )
        );
        return true;
    }
    else
    {
        assert(false);
    }

    return false;
}
Example #2
0
void DDAudio::OnAssetDestroyed(Asset& asset)
{
    if(asset.Type() == Asset::Sound)
    {
        std::map<std::string, int>::iterator iter =
            mSoundNameId.find(asset.Name());
        ALuint buffer = iter->second;
        alDeleteBuffers(1, &buffer);
        mSoundNameId.erase(iter);
    }
    else if(asset.Type() == Asset::Stream)
    {
        std::map<std::string, Asset*>::iterator iter =
            mStreamNameAsset.find(asset.Name());
        mStreamNameAsset.erase(iter);
    }
    else
    {
        assert(false);
    }
}