void CSoundSourceFMod::UpdateVolume()
{
	// only if channel active
	if(_FModChannel==-1)
		return;

	float fGain = CSoundSystemFMod::GetMe()->GetTypeVolume(GetType());

	//3D模式
	if(_b3DMode)
	{
		//得到与听者距离平方
		FLOAT fDistanceSQR = TDU_GetDistSq(GetPos(), CSoundSystemFMod::GetMe()->Listener_GetPos());

		//计算声音分贝
		INT  nVolumeDB= INT(floor(2000.0 * log10(fGain))); // convert to 1/100th decibels
		const static INT s_nDBMin= -10000;
		const static INT s_nDBMax= 0;
		TDU_Clamp(nVolumeDB, s_nDBMin, s_nDBMax);

		//根据距离计算音量
		nVolumeDB= _ComputeManualRollOff(nVolumeDB, s_nDBMin, s_nDBMax, _Alpha, fDistanceSQR);
		
		//计算线性值
		DOUBLE	dAttGain= pow((DOUBLE)10.0, DOUBLE(nVolumeDB)/2000.0);
		TDU_Clamp(dAttGain, 0.0f, 1.0f);

		FSOUND_SetVolume(_FModChannel, UINT(dAttGain*255));
	}
	else
	{
		FSOUND_SetVolume(_FModChannel, UINT(fGain*255));
	}
}
Beispiel #2
0
// Lecture des sons. Ils sont lu par streaming c'est à dire qu'ils sont chargés pendant la lecture.
void CSoundManager::Jouer
(
	std::string const & Filename, 
	ECanaux Canal, 
	bool bLoop
)
{
	if (!m_bCanauxJeu && Canal != CANAL_MUSIQUE)
		return;

	if (m_pSon[Canal])
		FSOUND_Stream_Close (m_pSon[Canal]);

	// Si bLoop == true alors le son boucle.
	if (bLoop)
	{
		FSOUND_SetLoopMode (0, FSOUND_LOOP_NORMAL);
		m_pSon[Canal] = FSOUND_Stream_Open((DIRECTORY + Filename).c_str(), FSOUND_LOOP_NORMAL, 0, 0);
		FSOUND_SetVolume (Canal, 64);
		FSOUND_SetVolumeAbsolute (Canal, 64);
	}
	// Sinon il est jouer une seule fois.
	else
	{
		m_pSon[Canal] = FSOUND_Stream_Open((DIRECTORY + Filename).c_str(), FSOUND_NORMAL, 0, 0);
		FSOUND_SetVolume (Canal, 255);
		FSOUND_SetVolumeAbsolute (Canal, 255);
	}

	FSOUND_Stream_Play (Canal, m_pSon[Canal]);
}
Beispiel #3
0
bool
Ambient::update(Time deltaT)
{
  if(baseBuffer == NULL || base == NULL || baseChannel == -1) return false;

  if(isActive == false && currentVolume == 0 && targetVolume == 0) {
    checkFMODError(FSOUND_Stream_Stop(base));
    checkFMODError(FSOUND_Stream_Close(base));
    return false;
  }
  
  if(currentVolume != targetVolume) {
    float fadeStep = deltaT * 1.0 / MAGIC_FADE_TIME_SECONDS;
    if(fadeStep > abs(targetVolume - currentVolume))
      currentVolume = targetVolume;
    else if(currentVolume > targetVolume)
      currentVolume -= fadeStep;
    else
      currentVolume += fadeStep;
  }

  int channelVolume = clamp(static_cast<int>(currentVolume * MAGIC_AMBIENT_VOLUME * 255), 0, 255);
  checkFMODError(FSOUND_SetVolume(baseChannel, channelVolume));
                   
  runningTime -= deltaT;
  if(runningTime <= 0) {
    targetVolume = 0;
    runningTime = 0;
  }

  return true;
}
Beispiel #4
0
static inline VOID M_SetVolume(int volume)
{
	if (mod && FMUSIC_GetType(mod) != FMUSIC_TYPE_NONE)
		FMUSIC_SetMasterVolume(mod, volume);
	if (fsoundchannel  != -1)
		FSOUND_SetVolume(fsoundchannel, volume);
}
Beispiel #5
0
	void LecteurAudio::joueurLectureMorceau()
	{
		// Si aucun fichier audio n'est actuellement ouvert, on quitte la fonction
		if (!fluxAudio)
		{
			qWarning("Demande de lecture alors qu'aucun fichier n'est ouvert (joueurLectureMorceau - LecteurAudio.cpp)");
			return;
		}

		// Si le lecteur etait a l'arret
		if (etatActuel == arret)
		{
			// L'etat passe a Lecture
			etatActuel = lecture;
			// On initialise le canal audio en commencant la lecture
			canalAudio = FSOUND_Stream_Play(FSOUND_FREE, fluxAudio);
			// On se positionne a l'endroit indique par le MJ
			FSOUND_Stream_SetTime(fluxAudio, joueurPositionTemps);
			// On regle le volume
			FSOUND_SetVolume(canalAudio, niveauVolume->value());
		}
		
		// Si le lecteur etait en pause
		else if (etatActuel == pause)
		{
			// L'etat passe a Lecture
			etatActuel = lecture;
			// On reprend la lecture du titre
			FSOUND_SetPaused(canalAudio, false);
		}
		
		// Dans tous les autres cas il s'agit d'une erreur
		else
			qWarning("Demande de lecture d'un titre alors que le lecteur n'est ni en pause, ni a l'arret (joueurLectureMorceau - LecteurAudio.cpp)");
	}
Beispiel #6
0
void MusicStream::play(double volume) {
    if (! playing && (music != NULL)) {
        channel = FSOUND_Stream_Play(FSOUND_FREE, music);
        FSOUND_SetVolume(channel, min(volume, 1) * 255);
        playing = true;
    }
}
 void SetVolume( float vol )
 {
     if (m) {
         printf( "Setting %d to %d\n", this->channel, (int) ( vol*GetMaxVolume() ) );
         F_API FSOUND_SetVolume( this->channel, (int) ( vol*GetMaxVolume() ) );
     }
 }
Beispiel #8
0
/******************************************************************************
 *
 * Update volume and separation (panning) of 2D source
 *
 *****************************************************************************/
EXPORT void HWRAPI (Update2DSoundParms) (INT32 chan, INT32 vol, INT32 sep)
{
	FSOUND_SAMPLE *fmsample;

	if (chan < 0)
		return;

	fmsample = FSOUND_GetCurrentSample(chan);

	if (fmsample)
	{
		if (!FSOUND_Sample_GetMode(fmsample) & FSOUND_2D)
		{
			DBG_Printf("FMOD(Update2DSoundParms,Main): 2D Vol/Pan on 3D channel %i?\n",chan);
			//return;
		}
	}
	else
		return;

	if (!FSOUND_SetPaused(chan, true))
		DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPaused, Pause, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError()));

	if (!FSOUND_SetVolume(chan,vol))
		DBG_Printf("FMOD(Update2DSoundParms, , channel %i to volume %i): %s\n", chan,vol,FMOD_ErrorString(FSOUND_GetError()));

	if (!FSOUND_SetPan(chan, sep == NORMAL_SEP ? FSOUND_STEREOPAN : sep))
		DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPan, channel %i to sep %i): %s\n", chan,sep,FMOD_ErrorString(FSOUND_GetError()));

	if (!FSOUND_SetPaused(chan, false))
		DBG_Printf("FMOD(Update2DSoundParms, FSOUND_SetPaused, Resume, channel %i): %s\n", chan,FMOD_ErrorString(FSOUND_GetError()));
}
Beispiel #9
0
	void LecteurAudio::appuiLecture(bool etatBouton)
	{
		// Le bouton vient d'etre enfonce
		if (etatBouton)
		{
			// On (re)met en lecture les lecteurs des joueurs
			emettreCommande(lectureMorceau);
			// L'etat passe a Lecture
			etatActuel = lecture;
			// Si le bouton pause etait enfonce il s'agit d'une reprise de pause
			if (actionPause->isChecked())
			{
				// On relache le bouton pause
				actionPause->setChecked(false);
				// On reprend la lecture du titre
				FSOUND_SetPaused(canalAudio, false);
			}

			// Sinon il s'agit d'une premiere lecture
			else
			{
				// On rend inoperant le passage sur un tag : sans cela un tag peut deplacer le curseur de temps entre
				// le lancement de la lecture et le repositionnement dans le temps
				repriseDeLecture = true;
				// On initialise le canal audio en commencant la lecture
				canalAudio = FSOUND_Stream_Play(FSOUND_FREE, fluxAudio);
				// On se positionne a l'endroit choisi par l'utilisateur
				FSOUND_Stream_SetTime(fluxAudio, positionTemps->value());
				// On regle le volume
				FSOUND_SetVolume(canalAudio, niveauVolume->value());
				// Le passage sur un tag est a nouveau operationnel
				repriseDeLecture = false;
			}
		}

		// Le bouton vient d'etre relache
		else
		{
			// Le lecteur etait dans l'etat Lecture
			if (etatActuel == lecture)
			{
				// On met en pause les lecteurs des joueurs
				emettreCommande(pauseMorceau);
				// On met le lecteur en Pause
				etatActuel = pause;
				// On enfonce le bouton pause
				actionPause->setChecked(true);
				// On met la lecture en pause
				FSOUND_SetPaused(canalAudio, true);
			}
			
			// Dans les autres cas il y a un probleme
			else
			{
				qWarning("Le bouton lecture etait enfonce alors que le lecteur n'etait pas en en train de lire (appuiLecture - LecteurAudio.cpp)");
				return;
			}
		}
	}
Beispiel #10
0
void CSample::Play(int channel)
{
    if(data)
    {
        FSOUND_StopSound(channel);
        FSOUND_SetVolume(channel,volume);
        FSOUND_PlaySound(channel,data);
    }
}
Beispiel #11
0
void CSoundSourceFMod::SetGain( FLOAT gain )
{
	TDU_Clamp(gain, 0.00001f, 1.0f);
	_Gain = gain;

	if(!_b3DMode)
	{
		FSOUND_SetVolume(_FModChannel, UINT(_Gain*255));
	}
}
Beispiel #12
0
long playSound(FSOUND_SAMPLE *handle, bool loop)
{
	long result;

	result = FSOUND_PlaySound(FSOUND_FREE, handle);
	FSOUND_SetVolume(result, DEF_VOLUME);
	if (loop)
		FSOUND_SetLoopMode(result, FSOUND_LOOP_NORMAL);
	else
		FSOUND_SetLoopMode(result, FSOUND_LOOP_OFF);
	return result;
}
Beispiel #13
0
void SoundSystem::setMusicVolume(float volume)
{
	ASSERT(volume >= 0.0f, "Volume is negative: " + ftos(volume));
	ASSERT(volume <= 1.0f, "Volume is greater than 100%: " + ftos(volume));

	musicVolume = volume;

	if(musicChannel>=0)
	{
		FSOUND_SetVolume(musicChannel, (int)(musicVolume * 255.0f));
	}
}
Beispiel #14
0
void glk_schannel_set_volume(schanid_t chan, glui32 vol)
{
    if (!chan) {
	gli_strict_warning("schannel_set_volume: invalid id.");
	return;
    }
    chan->volume = vol;
    if (chan->module)
	FMUSIC_SetMasterVolume(chan->module, chan->volume / 256);
    if (chan->sample)
	FSOUND_SetVolume(chan->channel, chan->volume / 256);
}
Beispiel #15
0
	//Update place rel chan's vol
static void relvol(INT32 chan)
{
	INT32 vol = FSOUND_GetVolume(chan);
	INT32 error = FSOUND_GetError();

	if (chan == relcheckup(chan))
		return;

	if (!vol && error)
		DBG_Printf("FMOD(relvol, FSOUND_GetVolume, Channel # %i): %s\n",chan,FMOD_ErrorString(error));
	else if (!FSOUND_SetVolume(relcheckup(chan), vol))
		DBG_Printf("FMOD(relvol, FSOUND_SetVolume, Channel # %i): %s\n",chan,FMOD_ErrorString(FSOUND_GetError()));
}
Beispiel #16
0
void
Ambient::play()
{
  if(baseChannel != -1) {
    int channelVolume = clamp(static_cast<int>(currentVolume * 255), 0, 255);
    checkFMODError(FSOUND_SetVolume(baseChannel, channelVolume));
    targetVolume = 1;
    
    if(averageRunningTime > 0) {
      runningTime = averageRunningTime + (fnrand() * averageRunningTime * 0.25);
    }
    else {
      runningTime = 60;
    }
  }
}
Beispiel #17
0
/////////////////////////////////////
// sets music volume
////////////////////////////////////////
int CSound::SetMusicVolume(int vol)
{
	MUSIC_VOLUME = vol;
	FSOUND_SetVolume(0,MUSIC_VOLUME);
	// by adam- fixed by leigh: switch off music if its volume is 0, or start it if volume is > 0 and nothing is playing

	if (MUSIC_VOLUME == 0 && CurrentSong != NULL)
	{
		Stopmusic();
	}
	if (MUSIC_VOLUME > 0 && CurrentSong == NULL && songname != "Empty")
	{
		Startmusic(songname);
	}

	return vol;
}
Beispiel #18
0
void CSound::Play3dSound(FSOUND_SAMPLE *sound, int volume, float x, float y)
{
	if (p->Options->sound == 1)
	{
		float xPos = (p->Player[p->Winsock->MyIndex]->X - x) / 2400.0f;
		float yPos = (p->Player[p->Winsock->MyIndex]->Y - y) / 2400.0f;
		if (xPos >= -1.0f && xPos <= 1.0f && yPos >= -1.0f && yPos <= 1.0f) //Within hearing range?
		{
			float soundPos[3] = {xPos, yPos, 0.0f};
			int returnedChannel = FSOUND_PlaySound(FSOUND_FREE, sound);
			FSOUND_SetVolume(returnedChannel, volume);
			FSOUND_3D_SetAttributes(returnedChannel, soundPos, NULL);
			FSOUND_3D_SetMinMaxDistance(returnedChannel, 0.15f, 1.0f);
			FSOUND_Update();
		}
	}
}
Beispiel #19
0
int CFMOD::PlaySample(char *sname,int wchannel,int flags)
{
    int number_samples_playing=0;
    CSample *sample; if(!bfmod) return 0;
    sample=GetSample(sname); if(!sample) return 0;
    for(int i=0;i<FSOUND_GetMaxChannels();i++)
    {
        if(sample->data==FSOUND_GetCurrentSample(i))
        {
            number_samples_playing++;
        }
    }
    if(number_samples_playing>=sample->max_simultaneous) return 0;
    if(flags) FSOUND_Sample_SetMode(sample->data, flags);
    FSOUND_SetVolume(wchannel,sample->volume);
    return FSOUND_PlaySound(wchannel,sample->data);
}
bool LLAudioChannelFMOD::updateBuffer()
{
	if (LLAudioChannel::updateBuffer())
	{
		// Base class update returned true, which means that we need to actually
		// set up the channel for a different buffer.

		LLAudioBufferFMOD *bufferp = (LLAudioBufferFMOD *)mCurrentSourcep->getCurrentBuffer();

		// Grab the FMOD sample associated with the buffer
		FSOUND_SAMPLE *samplep = bufferp->getSample();
		if (!samplep)
		{
			// This is bad, there should ALWAYS be a sample associated with a legit
			// buffer.
			llerrs << "No FMOD sample!" << llendl;
			return false;
		}


		// Actually play the sound.  Start it off paused so we can do all the necessary
		// setup.
		mChannelID = FSOUND_PlaySoundEx(FSOUND_FREE, samplep, FSOUND_DSP_GetSFXUnit(), true);

		//llinfos << "Setting up channel " << std::hex << mChannelID << std::dec << llendl;
	}

	// If we have a source for the channel, we need to update its gain.
	if (mCurrentSourcep)
	{
		// SJB: warnings can spam and hurt framerate, disabling
		if (!FSOUND_SetVolume(mChannelID, llround(getSecondaryGain() * mCurrentSourcep->getGain() * 255.0f)))
		{
// 			llwarns << "LLAudioChannelFMOD::updateBuffer error: " << FMOD_ErrorString(FSOUND_GetError()) << llendl;
		}
		
		if (!FSOUND_SetLoopMode(mChannelID, mCurrentSourcep->isLoop() ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF))
		{
// 			llwarns << "Channel " << mChannelID << "Source ID: " << mCurrentSourcep->getID()
// 					<< " at " << mCurrentSourcep->getPositionGlobal() << llendl;
// 			llwarns << "LLAudioChannelFMOD::updateBuffer error: " << FMOD_ErrorString(FSOUND_GetError()) << llendl;
		}
	}

	return true;
}
Beispiel #21
0
EXPORT void HWRAPI (UpdateSourceVolume) (INT32 chan, INT32 vol)
{
	if (chan < 0)
		return;

	if (!FSOUND_GetCurrentSample(chan))
		return;

	if (!FSOUND_SetVolume(chan,vol))
		DBG_Printf("FMOD(UpdateSourceVolume, FSOUND_SetVolume, channel %i to volume %i): %s\n", chan,vol,FMOD_ErrorString(FSOUND_GetError()));
	else
	{
#ifdef MORESTUFF
		DBG_Printf("FMOD(UpdateSourceVolume, Main): channel %i is set to the volume of %i", chan,vol);
#endif
		relvol(chan);
	}
}
Beispiel #22
0
void CSoundManager::Update3D (int x, int y, int Nr)
{
	int   vol, pan;
	float xdiff, ydiff, Abstand;

	xdiff = ((pPlayer[0]->xpos + 45)  - x);
	ydiff = ((pPlayer[0]->ypos + 45)  - y);

	Abstand = float(sqrt((xdiff * xdiff) + (ydiff * ydiff)));

	vol = (int)((100-float(Abstand/6.0f)) / 100.0f * pSoundManager->its_GlobalSoundVolume);

	if (vol < 0)
		vol = 0;
	else

	// neuer Wert ist nicht leiser als der alte?

	{
		// Sound links oder rechts vom Spieler ?
		if (x < pPlayer[0]->xpos + 45)
		{
			pan = 128 - (100 - vol);
			if (pan < 0)
				pan = 0;
		}
		else
		{
			pan = 128 + (100 - vol);
			if (pan > 255)
				pan = 255;
		}

		
		FSOUND_SetVolume (its_Sounds[Nr]->Channel, vol);
		FSOUND_SetPan	 (its_Sounds[Nr]->Channel, 128);		
	}
}
Beispiel #23
0
//-----------------------------------------------------------------------------
// Func: void CShip::loadSounds()
// Desc: Sounds are loaded (hence the name). 
//       The names of the sound files to load are hard-coded
// Note: Only loads sounds for the player
//-----------------------------------------------------------------------------
void CShip::loadSounds()
{
  if( initialized || !isPlayer )
  {
    return;
  }

  char *sndFile = "audio/ambmines.wav"; //"audio/b.wav"; //

  sndEngine = FSOUND_Sample_Load( FSOUND_FREE, 
                                  sndFile,
                                  FSOUND_8BITS | FSOUND_MONO | FSOUND_LOOP_NORMAL, 
                                  0 );
  if( sndEngine == NULL )
  {
    error.msg( "CLIENT: CShip::loadSounds(): couldn't load %s", sndFile );
  }
  
  channel = FSOUND_PlaySound( FSOUND_FREE, sndEngine );
  FSOUND_SetVolume( channel, 0 );

  error.msg( "CLIENT: Loaded sound %s", sndFile);
}
Beispiel #24
0
bool CSoundManager::PlayWave(int Vol, int Pan, int Freq, int Nr)
{
	if (false == InitSuccessfull)
		return false;

	int Channel;		// Benutzter Channel

	// hört man den Sound überhaupt ?
	//
	if(Vol == 0 ||
		its_GlobalSoundVolume == 0)
		return false;

	if(its_Sounds[Nr] == NULL)
		return false;

	// Sound spielen
	//
	Channel = FSOUND_PlaySound   (FSOUND_FREE, its_Sounds[Nr]->SoundData);

	// Kein freier Channel gefunden ?
	//
	if (Channel == -1)
		return false;

	its_Sounds[Nr]->Channel   = Channel;
	its_Sounds[Nr]->isPlaying = true;;

	// Und Werte für den Channel, in dem er gespielt wird, setzen
	//
	FSOUND_SetFrequency(Channel, Freq);
	FSOUND_SetVolume   (Channel, int(its_GlobalSoundVolume*Vol/100.0f*2.55f));
	FSOUND_SetPan	   (Channel, Pan);

	return true;
} // PlayWave
Beispiel #25
0
	void LecteurAudio::finDeTitreSlot()
	{
		// Si la lecture en boucle est activee
		if (enBoucle)
		{
			// On arrete les lecteurs des joueurs
			emettreCommande(arretMorceau);
			// On remet en lecture les lecteurs des joueurs
			emettreCommande(lectureMorceau);
			// On initialise le canal audio en commencant la lecture
			canalAudio = FSOUND_Stream_Play(FSOUND_FREE, fluxAudio);
			// On regle le volume
			FSOUND_SetVolume(canalAudio, niveauVolume->value());
			// On remet la barre de temps au depart
			positionTemps->setValue(0);
			positionTemps->update();
			// On met l'afficheur de temps a 0
			afficheurTemps->display("0:00");
		}

		// Si la lecture unique est activee
		else if (lectureUnique)
		{
			// On arrete les lecteurs des joueurs
			emettreCommande(arretMorceau);
			// On arrete le lecteur local
			arreter();
		}

		// Sinon on passe au titre suivant
		else
		{
			// Il existe un titre suivant
			if (titreCourant < listeChemins.size()-1)
			{
				// On passe au titre suivant
				titreCourant++;
				// On envoie le nouveau titre aux lecteurs des joueurs
				emettreCommande(nouveauMorceau, listeTitres->item(titreCourant)->text());
				// On demande aux lecteurs des joueurs de commencer a le lire
				emettreCommande(lectureMorceau);
				// Changement de titre en cours
				nouveauTitre(listeTitres->item(titreCourant)->text(), listeChemins[titreCourant]);
				// On met le lecteur en lecture
				etatActuel = lecture;
				// On initialise le canal audio en commencant la lecture
				canalAudio = FSOUND_Stream_Play(FSOUND_FREE, fluxAudio);
				// On regle le volume
				FSOUND_SetVolume(canalAudio, niveauVolume->value());
				// On enfonce le bouton Lecture
				actionLecture->setChecked(true);
			}
			
			// Il n'existe pas de titre suivant : on arrete le lecteur
			else
			{
				// On emet une demande d'arret aux autres utilisateurs
				emettreCommande(arretMorceau);
				// On arrete le lecteur
				arreter();
			}
		}
	}
Beispiel #26
0
	void LecteurAudio::changementVolume(int valeur)
	{
		// Si le lecteur est en lecture ou en pause on regle le volume
		if (etatActuel == lecture || etatActuel == pause)
			FSOUND_SetVolume(canalAudio, valeur);
	}
Beispiel #27
0
/*
[
    [DESCRIPTION]

    [PARAMETERS]
 
    [RETURN_VALUE]

    [REMARKS]

    [SEE_ALSO]
]
*/
int main()
{
    FSOUND_SAMPLE *samp1 = 0, *samp2 = 0;
    int key;
    int eqid1,eqid2;
   
    if (FSOUND_GetVersion() < FMOD_VERSION)
    {
        printf("Error : You are using the wrong DLL version!  You should be using FMOD %.02f\n", FMOD_VERSION);
        return 1;
    }

     /*
        INITIALIZE
    */
    FSOUND_SetBufferSize(100);  /* This is nescessary to get FX to work on output buffer */
    if (!FSOUND_Init(44100, 32, FSOUND_INIT_ENABLESYSTEMCHANNELFX))
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        return 1;
    }

    /*
        LOAD SAMPLES
    */

    /* PCM,44,100 Hz, 8 Bit, Mono */
    samp1 = FSOUND_Sample_Load(FSOUND_FREE, "../../media/drumloop.wav", FSOUND_2D, 0, 0);
    if (!samp1)
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        return 1;
    }
    FSOUND_Sample_SetMode(samp1, FSOUND_LOOP_OFF);

    /* PCM,44,100 Hz, 16 Bit, Stereo */
    samp2 = FSOUND_Sample_Load(FSOUND_FREE, "../../media/jules.mp3", FSOUND_HW2D | FSOUND_ENABLEFX, 0, 0);
    if (!samp2)
    {
        printf("Error!\n");
        printf("%s\n", FMOD_ErrorString(FSOUND_GetError()));
        return 1;
    }

    /*
        DISPLAY HELP
    */

    printf("FSOUND Output Method : ");
    switch (FSOUND_GetOutput())
    {
        case FSOUND_OUTPUT_NOSOUND:  printf("FSOUND_OUTPUT_NOSOUND\n"); break;
        case FSOUND_OUTPUT_WINMM:    printf("FSOUND_OUTPUT_WINMM\n"); break;
        case FSOUND_OUTPUT_DSOUND:   printf("FSOUND_OUTPUT_DSOUND\n"); break;
        case FSOUND_OUTPUT_ASIO:     printf("FSOUND_OUTPUT_ASIO\n"); break;
        case FSOUND_OUTPUT_OSS:      printf("FSOUND_OUTPUT_OSS\n"); break;
        case FSOUND_OUTPUT_ALSA:     printf("FSOUND_OUTPUT_ALSA\n"); break;
        case FSOUND_OUTPUT_ESD:      printf("FSOUND_OUTPUT_ESD\n"); break;
    };

    printf("FSOUND Mixer         : ");
    switch (FSOUND_GetMixer())
    {
        case FSOUND_MIXER_QUALITY_FPU:    printf("FSOUND_MIXER_QUALITY_FPU\n"); break;
        case FSOUND_MIXER_QUALITY_MMXP5:  printf("FSOUND_MIXER_QUALITY_MMXP5\n"); break;
        case FSOUND_MIXER_QUALITY_MMXP6:  printf("FSOUND_MIXER_QUALITY_MMXP6\n"); break;
    };
    printf("FSOUND Driver        : %s\n", FSOUND_GetDriverName(FSOUND_GetDriver()));

    printf("=========================================================================\n");
    printf("Press 1       Play SOFTWARE sound affected by following reverb dsp unit (wet)\n");
    printf("      2       Play SOFTWARE sound unaffected by following reverb dsp unit (dry)\n");
    if (FSOUND_GetOutput() == FSOUND_OUTPUT_DSOUND)
    {
        printf("      3       Play HARDWARE FX enabled sound using Direct X 8 (echo+flange)\n");
        printf("      4       Set EQ on global software output to be affect by DX8 FX\n");
        printf("              Press 1 or 2 to hear the effect (3 is unaffected)\n");
        printf("      5       Turn off EQ on global software output\n");
    }
    printf("      ESC     Quit\n");
    printf("=========================================================================\n");

    /*
        SET UP DSPS!
    */

    SetupReverb();

    /*
        Note if we are using a dsp unit for playing sounds, callback and parameter are ignored!
    */
    DrySFXUnit = FSOUND_DSP_Create(NULL, FSOUND_DSP_DEFAULTPRIORITY_USER+100, 0);
    FSOUND_DSP_SetActive(DrySFXUnit, TRUE);

    /*
        You must pause the software output before getting the FX handle on it.
    */
    if (FSOUND_GetOutput() == FSOUND_OUTPUT_DSOUND)
    {
        FSOUND_SetPaused(FSOUND_SYSTEMCHANNEL, TRUE);

        eqid1 = FSOUND_FX_Enable(FSOUND_SYSTEMCHANNEL, FSOUND_FX_PARAMEQ);
        eqid2 = FSOUND_FX_Enable(FSOUND_SYSTEMCHANNEL, FSOUND_FX_PARAMEQ);

        FSOUND_SetPaused(FSOUND_SYSTEMCHANNEL, FALSE);
    }

    /*
        START PLAYING!
    */

    do
    {
        key = 0;
        printf("channels playing = %d cpu usage = %.02f%%\r", FSOUND_GetChannelsPlaying(), FSOUND_GetCPUUsage());

        if (kbhit())
        {
            key = getch();


            if (key == '1') 
            {
                int channel = FSOUND_PlaySound(FSOUND_FREE, samp1);
            }
            if (key == '2') 
            {
                FSOUND_PlaySoundEx(FSOUND_FREE, samp1, DrySFXUnit, FALSE);
            }
            if (FSOUND_GetOutput() == FSOUND_OUTPUT_DSOUND)
            {       
                if (key == '3') 
                {
                    static int  fxchannel = FSOUND_FREE;
                    static int  echoid = -1, echoid2 = -1,flangeid = -1, firsttime;

                    if (fxchannel == FSOUND_FREE)
                    {
                        firsttime = TRUE;
                    }
                    else
                    {
                        firsttime = FALSE;
                    }

                    fxchannel = FSOUND_PlaySoundEx(fxchannel, samp2, DrySFXUnit, TRUE);     

                    /* 
                       NOTE! Even though it is for hardware FX, set it to a DrySFXUnit just 
                       in case a non hardware output mode has been selected (such as 
                       WINMM/Linux etc) and it actually drops back to 100% software 
                     */

                    FSOUND_SetVolume(fxchannel, 120); /* turn it down a bit! */
                
                    if (firsttime)
                    {
                        echoid   = FSOUND_FX_Enable(fxchannel, FSOUND_FX_ECHO);
                        echoid2  = FSOUND_FX_Enable(fxchannel, FSOUND_FX_ECHO);
                        flangeid = FSOUND_FX_Enable(fxchannel, FSOUND_FX_FLANGER);
                    }

                    FSOUND_SetPaused(fxchannel, FALSE);

                    FSOUND_FX_SetEcho(echoid,  80.0f, 70.0f, 100.0f, 100.0f, TRUE);
                    FSOUND_FX_SetEcho(echoid2,  100, 70.0f, 10, 10, FALSE);
                }
                if (key == '4')
                {
                    FSOUND_FX_SetParamEQ(eqid1, 8000, 36, -15);
                    FSOUND_FX_SetParamEQ(eqid2, 16000, 36, -15);
                }
                if (key == '5')
                {
                    FSOUND_FX_SetParamEQ(eqid1, 8000, 15, 0);
                    FSOUND_FX_SetParamEQ(eqid2, 8000, 15, 0);
                }
            }
        }
        Sleep(10);

    } while (key != 27);

    printf("\n");

    /*
        CLEANUP AND SHUTDOWN
    */

    FSOUND_DSP_Free(DrySFXUnit);    

    CloseReverb();

    FSOUND_Sample_Free(samp1);
    FSOUND_Sample_Free(samp2);

    FSOUND_Close();
   
    return 0;
}
/**	Sets the Volume of the stream to play at
 *
 *	@param volume	The volume to set the stream to play at
 *
 *	@returns boolean true or false, depending on whether setting the volume was successful or not
 *
 *	The valid range of values for the volume is 0 to 255, silent, to max volume respectively
 */
bool FMODStreamBuffer::Volume(unsigned char volume)
{
	if(FSOUND_SetVolume(m_channel,volume) == 1) return true;

	return false;
}
Beispiel #29
0
glui32 glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify)
{
    FILE *file;
    long pos, len;
    glui32 type;
    char *buf;
    int offset = 0;
    int i;

    if (!chan) {
	gli_strict_warning("schannel_play_ext: invalid id.");
	return 0;
    }

    /* stop previous noise */
    glk_schannel_stop(chan);

    if (repeats == 0)
	return 1;

    /* load sound resource into memory */

    if (!giblorb_is_resource_map())
    {
	char name[1024];

	sprintf(name, "%s/SND%ld", gli_workdir, snd); 

	file = fopen(name, "rb");
	if (!file)
	    return 0;

	fseek(file, 0, SEEK_END);
	len = ftell(file);

	buf = malloc(len);
	if (!buf) {
	    fclose(file);
	    return 0;
	}

	fseek(file, 0, 0);
	fread(buf, 1, len, file);
	fclose(file);

	/* identify by file magic the two types that fmod can do... */

	type = 0;	/* unidentified */

	/* AIFF */
	if (len > 4 && !memcmp(buf, "FORM", 4))		
	    type = giblorb_ID_FORM;

	/* WAVE */
	if (len > 4 && !memcmp(buf, "WAVE", 4))
	    type = giblorb_ID_WAVE;

	/* MIDI */
	if (len > 4 && !memcmp(buf, "MThd", 4))
	    type = giblorb_ID_MIDI;

	/* Ogg Vorbis */
	if (len > 4 && !memcmp(buf, "OggS", 4))
	    type = giblorb_ID_OGG;

	/* s3m */
	if (len > 0x30 && !memcmp(buf + 0x2c, "SCRM", 4))
	    type = giblorb_ID_MOD;

	/* XM */
	if (len > 20 && !memcmp(buf, "Extended Module: ", 17))
	    type = giblorb_ID_MOD;

	/* MOD */
	if (len > 1084)
	{
	    char resname[4];
	    memcpy(resname, buf + 1080, 4);
	    if (!strcmp(resname+1, "CHN") ||	/* 4CHN, 6CHN, 8CHN */
		    !strcmp(resname+2, "CN") ||	 /* 16CN, 32CN */
		    !strcmp(resname, "M.K.") || !strcmp(resname, "M!K!") ||
		    !strcmp(resname, "FLT4") || !strcmp(resname, "CD81") ||
		    !strcmp(resname, "OKTA") || !strcmp(resname, "    "))
		type = giblorb_ID_MOD;
	}

	if (!memcmp(buf, "\377\372", 2))	/* mp3 */
	    type = giblorb_ID_MP3;

	/* look for RIFF (future boy has broken resources...?) */
	if (len > 128 && type == 0)
	    for (i = 0; i < 124; i++)
		if (!memcmp(buf+i, "RIFF", 4))
		{
		    offset = i;
		    type = giblorb_ID_WAVE;
		    break;
		}

	if (type == 0)
	    type = giblorb_ID_MP3;
    }

    else
    {
	giblorb_get_resource(giblorb_ID_Snd, snd, &file, &pos, &len, &type);
	if (!file)
	    return 0;

	buf = malloc(len);
	if (!buf)
	    return 0;

	fseek(file, pos, 0);
	fread(buf, 1, len, file);
    }

    switch (type)
    {
    case giblorb_ID_FORM:
    case giblorb_ID_WAVE:
    case giblorb_ID_MP3:
	chan->sample = FSOUND_Sample_Load(FSOUND_UNMANAGED, buf + offset,
		FSOUND_NORMAL|FSOUND_LOADMEMORY, 0, len);
	if (!chan->sample) { free(buf); return 0; }
	if (repeats != 1)
	    FSOUND_Sample_SetMode(chan->sample, FSOUND_LOOP_NORMAL);
	else
	    FSOUND_Sample_SetMode(chan->sample, FSOUND_LOOP_OFF);
	chan->channel = FSOUND_PlaySound(FSOUND_FREE, chan->sample);
	FSOUND_SetVolume(chan->channel, chan->volume / 256);
	FSOUND_SetPaused(chan->channel, 0);
	break;

    case giblorb_ID_MOD:
    case giblorb_ID_MIDI:
	chan->module = FMUSIC_LoadSongEx(buf, 0, len, FSOUND_LOADMEMORY, 0, 0);
	if (!chan->module) { free(buf); return 0; }
	if (repeats != 1)
	    FMUSIC_SetLooping(chan->module, 1);
	else
	    FMUSIC_SetLooping(chan->module, 0);
	FMUSIC_SetMasterVolume(chan->module, chan->volume / 256);
	FMUSIC_PlaySong(chan->module);
	break;

    default:
	gli_strict_warning("schannel_play_ext: unknown resource type.");
    }

    free(buf);

    return 1;
}
Beispiel #30
0
void C4MusicFileOgg::SetVolume(int iLevel)
{
	FSOUND_SetVolume(Channel, (int) ((iLevel * 255) / 100));
}