Sound System: Difference between revisions

From PSwiki
Jump to navigation Jump to search
Lucubro (talk | contribs)
Lucubro (talk | contribs)
documentation of iSoundControl
Line 56: Line 56:
  }
  }


/** This interface defines the sound controller used by the application.
*
* The API allows the user to control the volume and the state of a group
* of sounds. The user can define a different SoundControl for each type
* of sound is needed to be controlled differently. For example one can
* use a SoundControl to manage voices and another one for the GUI's sounds.
*/
  struct iSoundControl
  struct iSoundControl
  {
  {
  int GetID()
  /**
  void SetVolume(float vol)
* Every SoundControl has a type as defined in this enum. There are two
  float GetVolume()
* special types: AMBIENT and MUSIC that control the ambient and the music
  void Mute()
* sounds respectively. There can be only one SoundControl of these two
  void Unmute()
* types at the same time while there can be an unlimited number of sound
  void SetToogle(bool toogle)
* controllers with type NORMAL.
  bool GetToogle()
*/
  void DeactivateToogle()
enum SndCtrl_Type
  void ActivateToogle()
{
  }
NORMAL = 0,
 
AMBIENT = 1,
MUSIC = 2
};
/**
* Get the SoundControl's ID.
* @return the Soundcontrol's ID.
*/
virtual int GetID() const=0;
  /**
* Get the SoundControl's type.
* @return the SoundControl's type.
*/
virtual int GetType() const=0;
/**
* Get the current volume of the sounds controlled by this SoundControl.
* @return the volume as a float.
*/
  virtual float GetVolume() const=0;
/**
* Set the volume of the sounds controlled by this SoundControl.
* @param vol the volume to be set.
*/
  virtual void SetVolume(float vol)=0;
/**
* Unmute sounds controlled by this SoundControl.
  */
virtual void Unmute()=0;
/**
* Mute sounds controlled by this SoundControl.
  */
virtual void Mute()=0;
/**
* Get the current Toggle state.
* @return true if sounds controlled by this SoundControl are activated,
* false otherwise.
*/
virtual bool GetToggle() const=0;
/**
* Set the current Toggle state.
* @param toggle true to activate the sounds controlled by this SoundControl,
  * false otherwise.
*/
virtual void SetToggle(bool toggle)=0;
  /**
* Deactivate sounds controlled by this SoundControl.
*/
virtual void DeactivateToggle()=0;
/**
* Activate sounds controlled by this SoundControl.
*/
  virtual void ActivateToggle()=0;
  };
==== Comments and differences with ''psSoundManager'' and ''SoundControl'' ====
==== Comments and differences with ''psSoundManager'' and ''SoundControl'' ====
* I still do not like the way PlaySound are handled here. I will find a better solution later.
* I still do not like the way PlaySound are handled here. I will find a better solution later.
Line 74: Line 143:
* The interface lets the user to handle more than a queue of sounds. Right now ''psSoundManager'' uses only one queue for NPCs' voices.
* The interface lets the user to handle more than a queue of sounds. Right now ''psSoundManager'' uses only one queue for NPCs' voices.
* Methods similar to ''psSoundManager::SetVoiceToggle()'' and ''psSoundManager::GetVoiceToggle()'' are not available since the user can access directly to the voice sound control through ''GetSndCtrl()'' (actually those methods are not needed even in ''psSoundManager'').
* Methods similar to ''psSoundManager::SetVoiceToggle()'' and ''psSoundManager::GetVoiceToggle()'' are not available since the user can access directly to the voice sound control through ''GetSndCtrl()'' (actually those methods are not needed even in ''psSoundManager'').
* ''psSoundManager'' uses 4 ''psToggle''. That class add to a boolean toggle only the callback feature that should not be accessed by external classes so I have decided to present an interface with only getters and setters. ''psToggle'' will still be used in the plugin module's implementation.
* Note that ''iSoundControl'' does not support the callback functionalities; indeed I do not think the user should use them. Those methods will be anyway implemented in the plugin module for internal uses.
* Note that ''iSoundControl'' does not support the callback functionalities; indeed I do not think the user should use them. Those methods will be anyway implemented in the plugin module for internal uses.
* ''psSoundManager'' uses 4 ''psToggle''. That class add to a boolean toggle only the callback feature that should not be accessed by external classes so I have decided to present an interface with only getters and setters. ''psToggle'' will still be used in the plugin module's implementation.
* The only add to ''iSOundControl'' is the type.


=== Sounds in factories ===
=== Sounds in factories ===

Revision as of 12:34, 9 June 2011

GSoC 2011 > Sound System

This page is a WORK IN PROGRESS edited by Lucubro. Information in this page are not definitive. If you have comments you can leave a message in the discussion page or in my personal talk.

In this page are described the features that will be applied to the sound related part of Planeshift. Notes about the features' implementation will be available as well.

Sound improvements

Make the Sound Manager a plugin

The Sound Manager today is inside the main planeshift client sources. It will be nice to have it made as a plugin to have a cleaner abstraction layer. The idea is to allow developers to use the sound system's functionalities entirely through an API. The programmers should not need to know any internal mechanics and they should never make use of internal classes of the sound system or of the Crystal Space sound classes.

The API

The module provides two interfaces: iSoundManager and iSoundControl defined as follows. These will be basically the corresponding classes of psSoundManager and SoundControl and they will have more or less similar methods. (Note that everything here is in progress: these interfaces (expecially iSoundManager) could vary a lot while I will work on the other features and improvements.)

struct iSoundManager
{
	void LoadActiveSector(string sector)		// Corresponding of  psSoundManager::Load(). I think this name is more descriptive
	void UnloadActiveSector()			// Corresponding of  psSoundManager::Unload()

	void Reload()

	iSoundControl AddSndCtrl(int ctrlID)
	void RemoveSndCtrl(int ctrlID)
	iSoundControl GetSndCtrl(int ctrlID)
	iSoundControl GetMainSndCtrl()

	void AddSndQueue(int queueID)
	void RemoveSndQueue(int queueID)
	bool PushQueueItem(int queueID, string fileName)

	void SetCombatStance(int newCombatStance)
	int GetCombatStance()
	void SetPosition(csVector3 playerPosition)
	csVector3 GetPosition()
	void SetTimeOfDay(int newTimeOfDay)
	int GetTimeOfDay()
	void SetWeather(int newWeather)
	int GetWeather()

	void SetLoopBGMToogle(bool toogle)
	bool IsLoopBGMToogleOn()
	void SetCombatMusicToogle(bool toogle)
	bool IsCombatMusicToogleOn()
	void SetListenerOnCameraToogle(bool toogle)
	bool IsListenerOnCameraToogleOn()

	void PlaySound(string fileName, bool loop, iSoundCtrl ctrl)
	void PlaySound(string fileName, bool loop, iSoundCtrl ctrl, csVector3 pos, csVector3 dir, float minDist, float maxDist)
	void StopSound(string fileName)

	void Update()
	void UpdateListener(iView view)
	void UpdateSoundPosition(string fileName, csVector3 position)
}
/** This interface defines the sound controller used by the application.
*
* The API allows the user to control the volume and the state of a group
* of sounds. The user can define a different SoundControl for each type
* of sound is needed to be controlled differently. For example one can
* use a SoundControl to manage voices and another one for the GUI's sounds.
*/
struct iSoundControl
{
	/**
	* Every SoundControl has a type as defined in this enum. There are two
	* special types: AMBIENT and MUSIC that control the ambient and the music
	* sounds respectively. There can be only one SoundControl of these two
	* types at the same time while there can be an unlimited number of sound
	* controllers with type NORMAL.
	*/
	enum SndCtrl_Type
	{
		NORMAL = 0,
		AMBIENT = 1,
		MUSIC = 2
	};

	/**
	* Get the SoundControl's ID.
	* @return the Soundcontrol's ID.
	*/
	virtual int GetID() const=0;

	/**
	* Get the SoundControl's type.
	* @return the SoundControl's type.
	*/
	virtual int GetType() const=0;

	/**
	* Get the current volume of the sounds controlled by this SoundControl.
	* @return the volume as a float.
	*/
	virtual float GetVolume() const=0;

	/**
	* Set the volume of the sounds controlled by this SoundControl.
	* @param vol the volume to be set.
	*/
	virtual void SetVolume(float vol)=0;

	/**
	* Unmute sounds controlled by this SoundControl.
	*/
	virtual void Unmute()=0;

	/**
	* Mute sounds controlled by this SoundControl.
	*/
	virtual void Mute()=0;

	/**
	* Get the current Toggle state.
	* @return true if sounds controlled by this SoundControl are activated,
	* false otherwise.
	*/
	virtual bool GetToggle() const=0;

	/**
	* Set the current Toggle state.
	* @param toggle true to activate the sounds controlled by this SoundControl,
	* false otherwise.
	*/
	virtual void SetToggle(bool toggle)=0;

	/**
	* Deactivate sounds controlled by this SoundControl.
	*/
	virtual void DeactivateToggle()=0;

	/**
	* Activate sounds controlled by this SoundControl.
	*/
	virtual void ActivateToggle()=0;
};

Comments and differences with psSoundManager and SoundControl

  • I still do not like the way PlaySound are handled here. I will find a better solution later.
  • Note that the main SoundControl is treated differently as it controls the overall properties.
  • The interface lets the user to handle more than a queue of sounds. Right now psSoundManager uses only one queue for NPCs' voices.
  • Methods similar to psSoundManager::SetVoiceToggle() and psSoundManager::GetVoiceToggle() are not available since the user can access directly to the voice sound control through GetSndCtrl() (actually those methods are not needed even in psSoundManager).
  • psSoundManager uses 4 psToggle. That class add to a boolean toggle only the callback feature that should not be accessed by external classes so I have decided to present an interface with only getters and setters. psToggle will still be used in the plugin module's implementation.
  • Note that iSoundControl does not support the callback functionalities; indeed I do not think the user should use them. Those methods will be anyway implemented in the plugin module for internal uses.
  • The only add to iSOundControl is the type.

Sounds in factories

In CS every object has a factory and multiple instances, so you can have a mesh factory, which is a rock, and then instanciate it multiple times by changing its coords, rotation and texture. We would like to have the ability to associate sounds to the factories present in the world.

Distance lag effect of 3d emitters

Sound has a certain speed and openal unfortunately doesn't handle this factor so, even if it lowers the volume of distant sources, it will still make the sound of them run at the same time making the actual volume sound higher than it is actually. This would be about making emitters slow down when the player goes away from the source in order to unsync it from the other, more near emitters and go back to the normal speed after it has reached a certain offset from the more near object, in order to simulate this effect of distance and avoid equal sounds to stack.

Overall code cleanup

Here will follow a list of the cleanup interventions in the code.


Sounds events

We need to allow to play a sound when some events happen.

Random sounds on monsters

When they stand still and idle. If the race is an intelligent race, then we can play some phrases, if not we can just have screams/sounds.

Sounds associated to behaviours/actions of monsters

Like he is angry and plays the angry sound.

Sounds for each weapon and attack

If you attack with a sword you should hear the sound of a sword.

Random sounds from environment

Buzzes of flies, water for rivers, wind and so on so forth.


Musical instruments

This will allow players to use musical instruments.


Optional extensions

These things (or part of them) will be done during the GSoC coding time only time permitting. Otherwise they can still be included in the next GSoC or implemented by developers.

  • Add ability to limit number of channels. The idea is to be able to limit the amount of sounds played at the same time coming from different sources. In the same areas you can have rivers, monsters, wind, and even the player clicking on the UI.
  • Special actions to do when particular sound types are being played (for example reducing all other sounds/music volume)
  • Allow voice speech in game through peer to peer connection.
  • Have the walking sounds as a possible perception for monsters nearby. like a thief moving close to a monster to attack him first without making too much noise by walking, while a player with no sneak skills, will just make more noise while walking and the monster will hear this and attach him first.
  • Have the sound of a player walking that vary based on the ground; so if it's rocky texture it's harder sound, and if it's grass is softer sound.

Skills needed

Our server and client are all coded in C++ and the sounds are defined in XML files. For this project C++ knowledge is needed, some basic knowledge of XML. No MySQL knowledge is required.

Difficulty

medium to difficult, depending on the parts of this which are picked up