void SoundLooper::bar() {
	if(!(bars % 4) && bars > play_to){
		bars = 0;
	}
	if(bars == start_at){
		int status_was = status;
		// Play sound
		if (status == LOOPER_QUEUED){
			status = LOOPER_PLAYING;
		}
	
		if (status == LOOPER_STOPPING){
			status = LOOPER_IDLE;
			gui->intEvent(EVENT_CHANGE_TRG_COLOR, COLOR_TRG_IDLE);
		}
		if (status == LOOPER_PLAYING){
			FMOD::Channel *ch;
			ERRCHECK(sound->system->playSound(FMOD_CHANNEL_FREE, sample, false, &ch));
			ERRCHECK(ch->setChannelGroup(cg));
		}
		if(status_was != status) {
			gui->intEvent(EVENT_CHANGE_TRG_COLOR, status==LOOPER_PLAYING?COLOR_TRG_PLAYING:COLOR_TRG_IDLE);
		}
	}

	if(bars == play_to) {
		bars = 0;
	}
	else
		bars++;
}
Esempio n. 2
0
void SoundEngine::hatSpawn(float x, float y, float z) {
	FMOD::Channel* channel = nullptr;
	FMOD_VECTOR position = { x, y, z };
	result_ = system_->playSound(hatSpawnSound_, 0, true, &channel);
	result_ = channel->set3DAttributes(&position, 0);
	result_ = channel->setPaused(false);
}
bool CSGD_FModManager::PlaySound( int nID )
{
	if( !m_pSystem ) return false;

	//	check that ID is in range
	assert( nID > -1 && nID < (int)m_SoundList.size() && "ID is out of range" );

	//	Address of a channel handle pointer that receives the newly playing channel
	FMOD::Channel *channel;
	//	used to catch fMod-specific error codes
	FMOD_RESULT result;

	if( ( result = m_pSystem->playSound(FMOD_CHANNEL_FREE, m_SoundList[ nID ].fmSound , false, &channel) ) != FMOD_OK )
	{
		FMODERR( result );
	}

	//  set the volume of this playing channel
	channel->setVolume(m_SoundList[nID].fVolume);

	//  set the pan of this playing channel
	channel->setPan(m_SoundList[nID].fPan);

	//  set the volume of this playing channel
	//channel->setFrequency(m_SoundList[nID].fFreq);

	//	hold on to channel pointer for late use
	m_SoundList[ nID ].m_SoundChannels.push_back( channel );

	//	return success
	return true;
}
Esempio n. 4
0
SkySound SoundManager::play3DSound(std::string name, float volume, float x, float y, float z, bool echo, bool loop, float fallOffStart)
{
if(mSilent) return NULL;
	
	if ("" == name)
		return false;
	if(mInitFailed) return NULL;
	FMOD::Sound* sound = 0;
	FMOD::Channel* soundChannel;
	result = mSystem->createSound(name.c_str(), FMOD_SOFTWARE | FMOD_3D, 0, &sound); 
	
	if (!sound)
	{
		printf("FMOD Error loading %s!\n", name.c_str());
		checkErrors();
		return NULL;
	}
	sound->set3DMinMaxDistance(fallOffStart, 2000);
	sound->setMode(loop ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
	mSystem->playSound(FMOD_CHANNEL_FREE, sound, false, &soundChannel);
//	if(echo)
	//	soundChannel->addDSP(mReverb);


	FMOD_VECTOR pos = {x, y, z};
	FMOD_VECTOR vel = {0, 0, 0};
	soundChannel->setVolume(volume);
	soundChannel->set3DAttributes(&pos, &vel);

	mSystem->update();
//	printf("finished play3dsound\n");
	return soundChannel;
}
bool AudioEngineImpl::resume(int audioID)
{
    try {
        if (!mapChannelInfo[audioID].channel) {
            FMOD::Channel *channel = nullptr;
            FMOD::ChannelGroup *channelgroup = nullptr;
            //starts the sound in pause mode, use the channel to unpause
            FMOD_RESULT result = pSystem->playSound(mapChannelInfo[audioID].sound, channelgroup, true, &channel);
            if (ERRCHECK(result)) {
                return false;
            }
            channel->setMode(mapChannelInfo[audioID].loop ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF);
            channel->setLoopCount(mapChannelInfo[audioID].loop ? -1 : 0);
            channel->setVolume(mapChannelInfo[audioID].volume);
            channel->setUserData(reinterpret_cast<void *>(static_cast<std::intptr_t>(mapChannelInfo[audioID].id)));
            mapChannelInfo[audioID].channel = channel;
        }

        mapChannelInfo[audioID].channel->setPaused(false);
        AudioEngine::_audioIDInfoMap[audioID].state = AudioEngine::AudioState::PLAYING;

        return true;
    }
    catch (const std::out_of_range& oor) {
        printf("AudioEngineImpl::resume: invalid audioID: %d\n", audioID);
        return false;
    }
}
Esempio n. 6
0
void MCFMODSourceManager::setSourcePitch(unsigned int SourceIndex, int Cents)
{
   FMOD::Channel* fmodChannel = reinterpret_cast<FMOD::Channel*>(sSources[SourceIndex].Source);

   float fFrequencyRatio = (float)pow(2, Cents / 1200.0f);
   fmodChannel->setFrequency(fFrequencies[SourceIndex] * fFrequencyRatio);
}
Esempio n. 7
0
void SoundHolder::unlinkSound(void *channel)
{
	FMOD::Channel *pChannel = (FMOD::Channel*)channel;
	pChannel->setUserData(NULL);
	pChannel->setCallback(NULL);
	activeSounds.erase(channel);
}
Esempio n. 8
0
	int Game::playEnvironment()
	{
			bool soundDone=false;
			FMOD::System* system;
			FMOD_RESULT result = FMOD::System_Create(&system);
			system->init(32, FMOD_INIT_NORMAL, NULL);
			FMOD::Sound* sound;
			
			result = system->createSound("Ocean.WAV",FMOD_LOOP_NORMAL,NULL, &sound);
			FMOD::Channel* channel = 0;
			bool pauseSound = false;


			channel->isPlaying(&pauseSound);

			result = system->playSound(FMOD_CHANNEL_FREE, sound,false, &channel);
			soundDone=true;


			while (soundDone!=true)
			{
			channel->setPaused(false);
			system->update();

			result = sound->release();
			result = system->close();
			result = system->release();
			}
			return 0;
	}
Esempio n. 9
0
static FMOD_RESULT F_CALLBACK channelCallback(FMOD_CHANNEL* chanPtr,
                                              FMOD_CHANNEL_CALLBACKTYPE type,
                                              void* /*commanddata1*/,
                                              void* /*commanddata2*/)
{
    FMOD::Channel *channel = reinterpret_cast<FMOD::Channel*>(chanPtr);
    sfxbuffer_t *buf = 0;

    switch(type)
    {
    case FMOD_CHANNEL_CALLBACKTYPE_END:
        // The sound has ended, mark the channel.
        channel->getUserData(reinterpret_cast<void**>(&buf));
        if(buf)
        {
            DSFMOD_TRACE("channelCallback: sfxbuffer " << buf << " stops.");
            buf->flags &= ~SFXBF_PLAYING;
            // The channel becomes invalid after the sound stops.
            bufferInfo(buf).channel = 0;
        }
        channel->setCallback(0);
        channel->setUserData(0);
        break;

    default:
        break;
    }
    return FMOD_OK;
}
void SoundEngine::update()
{
    if (system)
    {
        system->update();
        
        // ---
        
        vector<Event> completedEvents;
        
        for (auto &it : playingEffects)
        {
            int playingId = it.first;
            int channelId = it.second.first;
            EffectRef effect = it.second.second;
            
            FMOD::Channel *channel;
            system->getChannel(channelId, &channel);
            
            bool playing;
            channel->isPlaying(&playing);
            
            if (!playing)
            {
                completedEvents.emplace_back(EVENT_COMPLETED, effect, channelId, playingId);
            }
        }
        
        for (auto event : completedEvents)
        {
            playingEffects.erase(event.playingId);
            processEvent(event);
        }
    }
}
Esempio n. 11
0
bool cgFMODSoundPlayerImpl::StopSoundChannel( cgID channel )
{
	FMOD::Channel * pkChannel = m_pkChannelStorage->Remove(channel);
	if (!pkChannel)
		return false;

	return pkChannel->stop();
}
Esempio n. 12
0
bool MCFMODSourceManager::isSourcePlaying(unsigned int SourceIndex)
{
   FMOD::Channel* fmodChannel = reinterpret_cast<FMOD::Channel*>(sSources[SourceIndex].Source);
   bool bChannelPlaying;

   fmodChannel->isPlaying(&bChannelPlaying);

   return bChannelPlaying;
}
Esempio n. 13
0
void SoundEngine::dead(int playerId) {
	Player* player = dynamic_cast<Player*>(Globals::gameObjects.playerMap[playerId]);
	FMOD::Channel* channel = nullptr;
	glm::vec3 pos = player->getPosition();
	FMOD_VECTOR position = { pos.x, pos.y, pos.z };
	result_ = system_->playSound(deadSound_, 0, true, &channel);
	result_ = channel->set3DAttributes(&position, 0);
	result_ = channel->setPaused(false);
}
Esempio n. 14
0
void SoundHolder::linkSound(void *channel)
{
	if (!channel)
		return;
	FMOD::Channel *pChannel = (FMOD::Channel*)channel;
	pChannel->setUserData(this);
	pChannel->setCallback(s_soundHolderCallback);
	activeSounds.insert(channel);
}
Esempio n. 15
0
//¼ÌÐøÉùÒô
bool SoundManager::continueSound(int *channelIndex)
{
	FMOD::Channel* channel;
	if (!channelIndex || *channelIndex == INVALID_SOUND_CHANNEL)
		return false;
	system->getChannel(*channelIndex, &channel);
	channel->setPaused(false);
	return true;
}
Esempio n. 16
0
//ÉèÖÃÒôÁ¿
bool SoundManager::setVolume(float volume, int *channelIndex)
{
	FMOD::Channel* channel;
	if (!channelIndex || *channelIndex == INVALID_SOUND_CHANNEL)
		return false;

	system->getChannel(*channelIndex, &channel);
	channel->setVolume(volume);
	return true;
}
Esempio n. 17
0
bool cgFMODSoundPlayerImpl::SetVolume( cgID channel, float fVolume )
{
	FMOD::Channel * pkChannel = m_pkChannelStorage->Find(channel);
	if (!pkChannel)
		return false;

	pkChannel->setVolume(fVolume);

	return true;
}
Esempio n. 18
0
void FmodSoundEngine::PlayHit(float factor)
{
	FMOD::Channel *channel;
	system->playSound(hitWav, NULL, false, &channel);
	float vol = systemIni.sndVolume*(0.5f+factor*0.25f);
	channel->setVolume(min(1.0f,vol)*defaultVolume);
	//channel->setPaused(false);
	//ERRCHECK(result);
	//ERRCHECK(result);
}
void AudioEngineImpl::setFinishCallback(int audioID, const std::function<void (int, const std::string &)> &callback){
 try{
    FMOD::Channel * channel = mapChannelInfo[audioID].channel;
    mapChannelInfo[audioID].callback = callback; 
    FMOD_RESULT result = channel->setCallback(channelCallback);
    ERRCHECK(result);
    }catch(const std::out_of_range& oor){
      printf("AudioEngineImpl::setFinishCallback: invalid audioID: %d\n", audioID);
  }
};
Esempio n. 20
0
void SoundManager::Set3DMinMaxDistance(int channelIndex, float minDistance, float maxDistance) {
    FMOD_RESULT result;
    FMOD::Channel *channel;

    if (channelIndex == INVALID_SOUND_CHANNEL)
        return;

    result = system->getChannel(channelIndex, &channel);
    if (result == FMOD_OK)
        channel->set3DMinMaxDistance(minDistance, maxDistance);
}
Esempio n. 21
0
void MCFMODSourceManager::releaseSources()
{
   for(unsigned int i = 0; i < iNumSources; i++)
   {
      FMOD::Channel* fmodChannel = reinterpret_cast<FMOD::Channel*>(sSources[i].Source);
      fmodChannel->stop();
   }

   fmodChannelGroup->release();
   delete[] fFrequencies;
}
Esempio n. 22
0
void MCFMODSourceManager::setSourcePan(unsigned int SourceIndex, float Pan)
{
   sSources[SourceIndex].Position[0] = Pan;

   FMOD::Channel* fmodChannel = reinterpret_cast<FMOD::Channel*>(sSources[SourceIndex].Source);
   bool bChannelPlaying;

   fmodChannel->isPlaying(&bChannelPlaying);

   if(bChannelPlaying)
      fmodChannel->setPan(Pan);
}
Esempio n. 23
0
void FmodSoundEngine::PlaySound(string filename, float volume)
{
	FMOD::Sound *sound;
	FMOD::Channel *channel;
	sound = (FMOD::Sound*)ReadMusic(Ansi2UTF8(filename).data());
	result = system->playSound(sound, NULL, true, &channel);
	//ERRCHECK(result);
	result = channel->setVolume((float)volume*defaultVolume);
	//ERRCHECK(result);
	result = channel->setPaused(false);
	//ERRCHECK(result);
}
Esempio n. 24
0
void MCFMODSourceManager::setSourceVolume(unsigned int SourceIndex, float Volume)
{
   sSources[SourceIndex].Volume = Volume;

   FMOD::Channel* fmodChannel = reinterpret_cast<FMOD::Channel*>(sSources[SourceIndex].Source);
   bool bChannelPlaying;

   fmodChannel->isPlaying(&bChannelPlaying);

   if(bChannelPlaying)
      fmodChannel->setVolume(Volume);
}
Esempio n. 25
0
void SoundManagerAL::PlaySoundImmediate( FMOD::Sound* buffer, SoundSource& sourceData  )
{
	if(! buffer ) return ;
	FMOD_VECTOR pos = { sourceData.x, sourceData.y, sourceData.z };
	FMOD_VECTOR vel = { sourceData.vx, sourceData.vy, sourceData.vz };
	
	FMOD::Channel* channel;
	FMOD_RESULT result = m_system->playSound(FMOD_CHANNEL_FREE, buffer, true, &channel);
	result = channel->set3DAttributes(&pos, &vel);
	result = channel->setPaused(false);
	
}
Esempio n. 26
0
FMOD_RESULT F_CALLBACK SoundInstanceEndPlaying(FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACKTYPE type, void *commanddata1, void *commanddata2)
{
	if(type == FMOD_CHANNEL_CALLBACKTYPE_END)
	{
		FMOD::Channel *cppchannel = (FMOD::Channel *)channel;
		Sound * sound = 0;
        FMOD_VERIFY(cppchannel->getUserData((void**)&sound));
        SoundSystem::Instance()->SendCallbackOnUpdate(sound);
	}

	return FMOD_OK;
}
Esempio n. 27
0
void CGameData::PlayGunShotSound()
{
	if (mGunShotSound != NULL)
	{
		FMOD::Channel* gunShotChannel;

		mFModSystem->playSound(FMOD_CHANNEL_REUSE, mGunShotSound, false, &gunShotChannel);
		
		gunShotChannel->setMode(FMOD_LOOP_NORMAL);
		gunShotChannel->setLoopCount(0);
	}
}
Esempio n. 28
0
	void FMOD_System::PlayRollSound()
	{
		if( roll != nullptr )
		{
			if( !IsPlaying( rollChannel ) && !IsPlaying( collisionChannel ) )
			{
				system->playSound( FMOD_CHANNEL_FREE, roll, true, &rollChannel );
				rollChannel->set3DAttributes( &ballPosition, nullptr );
				rollChannel->setPaused( false );
			}
		}
	}
Esempio n. 29
0
	void FMOD_System::PlayJetSound()
	{
		if( jet != nullptr )
		{
			if( !IsPlaying( jetChannel ) )
			{
				system->playSound( FMOD_CHANNEL_FREE, jet, true, &jetChannel );
				jetChannel->set3DAttributes( &ballPosition, nullptr );
				jetChannel->setPaused( false );
			}
		}
	}
Esempio n. 30
0
	void FMOD_System::PlayCollisionSound()
	{
		if( collision != nullptr )
		{
			if( !IsPlaying( collisionChannel ) )
			{
				system->playSound( FMOD_CHANNEL_FREE, collision, true, &collisionChannel );
				collisionChannel->set3DAttributes( &ballPosition, nullptr );
				collisionChannel->setPaused( false );
			}
		}
	}