Esempio n. 1
0
 ResSound* ResSound::create(const std::string& file, bool streaming)
 {
     ResSound* rs = new ResSound;
     rs->init(file, streaming);
     rs->setName(file);
     return rs;
 }
Esempio n. 2
0
    Resource* ResSound::createResSound(CreateResourceContext& context)
    {
        ResSound* rs = new ResSound;
        rs->init(context, SoundSystem::instance);
        setNode(rs, context.walker.getNode());
        context.resources->add(rs);

        return rs;
    }
Esempio n. 3
0
    spSoundInstance SoundPlayer::prepareSound(Resource* ressound_, Channel* channel, const PlayOptions& opt)
    {
        ResSound* ressound = safeCast<ResSound*>(ressound_);
        if (!ressound || !ressound->getSound())
            return 0;

        if (!channel)
            return 0;

        spSoundInstance s = new SoundInstance;
        sound_desc desc;

        float volume = opt._volume;


        if (volume < 0.f)
            volume = _volume;

        desc.sound = ressound->getSound();
        desc.cbDone = _onSoundDone;
        desc.cbAboutEnd = _onSoundAboutDone;
        desc.cbUserData = s.get();
        desc.looping = opt._looped;
        desc.id = ressound->getName();
        desc.volume = volume;
        desc.paused = opt._paused;
        desc.pitch = opt._pitch;
		desc.seek = opt._seek;

        s->_player = this;
        s->_desc = desc;
        s->_channel = channel;
        s->_startTime = getTime();

        s->_startFadeIn = 0;
        s->_fadeInMS = opt._fadeIn;

        if (opt._looped)
            s->_startFadeOut = 0;
        else
            s->_startFadeOut = desc.sound->getDuration() - opt._fadeOut;

        s->_fadeOutMS = opt._fadeOut;

        s->_volume = volume;// *_volume;
        s->_state = SoundInstance::Normal;

        if (opt._fadeIn)
        {
            s->_state = SoundInstance::FadingIn;
            desc.volume = 0.0f;
        }

        return s;
    }
Esempio n. 4
0
	spSoundInstance SoundPlayer::play(Resource *ressound_, bool looping, unsigned int fadeInMS, unsigned int fadeOutMS, float primaryVolume, bool pause, Channel *continueChannel)
	{
		ResSound *ressound = safeCast<ResSound*>(ressound_);
		spSoundInstance s = new SoundInstance();
		s->_player = this;
		if ( primaryVolume < 0.f )
		{
			primaryVolume = _volume;
		}

		if (!ressound || !ressound->getSound())
			return s;

		//printf("PlayResSound:\n");
		Channel *channel = continueChannel;
		if (!channel)
			channel = SoundSystem::instance->getFreeChannel();
		if (!channel)
			return s;


		sound_desc desc;
		desc.sound = ressound->getSound();
		desc.cbDone = _onSoundDone;
		desc.cbAboutEnd = _onSoundAboutDone;
		desc.cbUserData = s.get();
		desc.looping = looping;
		desc.id = ressound->getName();
		desc.volume = primaryVolume;
		desc.paused = pause;



		s->_desc = desc;
		s->_channel = channel;
		s->_startTime = getTime();

		s->_startFadeIn = 0;
		s->_fadeInMS = fadeInMS;

		if (looping)
			s->_startFadeOut = 0;
		else
			s->_startFadeOut = desc.sound->getDuration() - fadeOutMS;

		s->_fadeOutMS = fadeOutMS;

		s->_volume = primaryVolume;	
		s->_state = SoundInstance::Normal;

		if (fadeInMS)
		{
			s->_state = SoundInstance::FadingIn;
			desc.volume = 0.0f;
		}

		_sounds.push_back(s);

		if (continueChannel)
			channel->continuePlay(desc);
		else
			channel->play(desc);

		return s;
	}