예제 #1
0
파일: alsound.cpp 프로젝트: BTML/colobot
int ALSound::Play(SoundType sound, const Math::Vector &pos, float amplitude, float frequency, bool loop)
{
    if (!m_enabled)
    {
        return -1;
    }
    if (m_sounds.find(sound) == m_sounds.end())
    {
        GetLogger()->Debug("Sound %d was not loaded!\n", sound);
        return -1;
    }

    int channel;
    bool alreadyLoaded = false;
    if (!SearchFreeBuffer(sound, channel, alreadyLoaded))
    {
        return -1;
    }

    if (!alreadyLoaded)
    {
        if (!m_channels[channel]->SetBuffer(m_sounds[sound].get()))
        {
            m_channels[channel]->SetBuffer(nullptr);
            return -1;
        }
    }

    Channel* chn = m_channels[channel].get();

    chn->SetPosition(pos);
    chn->SetVolumeAtrib(1.0f);

    // setting initial values
    chn->SetStartAmplitude(amplitude);
    chn->SetStartFrequency(frequency);
    chn->SetChangeFrequency(1.0f);
    chn->ResetOper();
    chn->SetFrequency(frequency);
    chn->SetVolume(powf(amplitude * chn->GetVolumeAtrib(), 0.2f) * m_audioVolume);
    chn->SetLoop(loop);

    if (!chn->Play())
    {
        m_channelsLimit = m_channels.size() - 1;
        GetLogger()->Debug("Changing channel limit to %u.\n", m_channelsLimit);
        m_channels.erase(channel);

        return -1;
    }

    return channel | ((chn->GetId() & 0xffff) << 16);
}
예제 #2
0
Channel* Mixer::Play(Source& source, int loop, bool deleteondone, bool deletesourceondone)
{
	Lock();
	Channel* newchannel = new (std::nothrow) Channel;
	if (newchannel) {
		newchannel->Play(source, loop);
		newchannel->deleteondone = deleteondone;
		newchannel->deletesourceondone = deletesourceondone;
		channels.push_back(newchannel);
	}
	Unlock();
	return newchannel;
}
예제 #3
0
Channel* Mixer::Play(Stream& stream, int loop, bool deleteondone)
{
	Lock();
	Channel* newchannel = new (std::nothrow) Channel();
	if (newchannel) {
		newchannel->Play(stream, loop);
		newchannel->deleteondone = deleteondone;
		newchannel->stopping = false;
		channels.push_back(newchannel);
	}
	Unlock();
	return newchannel;
}