|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
SOUNDMANAGER ( FMOD)
Information sur la source
Description
Ceci est un Sound Engine ( Moteur de sons ) permetant l'utilisation de la bibliotheque Fmod et la rendant encore plus facile a utilser. Prochainement une sources utilisant ce moteur ^^ bonne chance
Source
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using FMOD;
- namespace Mehdi_Media_Player
- {
- static class SoundManager
- {
- #region Fields
-
- private static FMOD.System system = null;
-
- private static Sound music = null;
-
- private static string currentPath;
- private static Channel Channel = null;
-
- public delegate void EndMusicEventHandler(object sender, EventArgs e);
- public delegate void ErrorEventHandler(RESULT result);
-
- private static CHANNEL_CALLBACK channelCallback;
- public static event EndMusicEventHandler EndMusic;
- public static event ErrorEventHandler EngineError;
-
- #endregion
- #region Properties
-
- public static string CurrentPath
- {
- get { return currentPath; }
- set { currentPath = value; }
- }
- public static Sound Music
- {
- get { return music;}
- }
- #endregion
-
- #region Init-UpDate-Release
-
- public static void Initialize(int NbChannel)
- {
- RESULT result;
-
- result = Factory.System_Create(ref system);
- if(EngineError!=null)EngineError(result);
-
- uint version = 0;
-
- result = system.getVersion(ref version);
- if(EngineError!=null)EngineError(result);
-
- if (version < VERSION.number)
- {
- throw new ApplicationException("Error! You are using an old version of FMOD " + version.ToString("X") + ". This program requires " + VERSION.number.ToString("X") + ".");
- }
-
- result = system.init(NbChannel, INITFLAG.NORMAL, (IntPtr)null);
- if(EngineError!=null)EngineError(result);
- channelCallback = new CHANNEL_CALLBACK(OnEndMusic);
-
- }
- public static void Update()
- {
- RESULT result= system.update();
- if (EngineError != null) EngineError(result);
- }
- public static void Release()
- {
- RESULT result= RESULT.OK;
- if (music != null)
- {
- result = music.release();
- if (EngineError != null) EngineError(result);
- }
- if(system!=null)
- result = system.release();
- if (EngineError != null) EngineError(result);
- }
-
- #endregion
- #region MainFunctions
- #region Play Functions
-
- public static void Play()
- {
- Play(currentPath);
- }
- public static void Play(string path)
- {
- Play(path, false);
- }
- public static void Play(string path, bool paused)
- {
- bool isPlaying = false;
- RESULT result= RESULT.OK;
-
- if (Channel != null)
- {
- //si la musique existe
- result = Channel.isPlaying(ref isPlaying);
- }
- else
- {
- isPlaying = false;
- }
-
- if (EngineError != null) EngineError(result);
-
- if ((currentPath == path) && isPlaying)//si la musique du chemin courant est entrain detre joué
- {
- return;
- }
- else if (currentPath == path)//sinon la musique du chemin courant nest pas entrain detre joué
- {
- result = system.playSound(CHANNELINDEX.FREE, music, false, ref Channel);
- if(EngineError!=null)EngineError(result);
- if(Channel!=null)
- result= Channel.setCallback(FMOD.CHANNEL_CALLBACKTYPE.END, channelCallback, 0);
- if (EngineError != null) EngineError(result);
- }
- else
- {
-
- //si cest une nouvelle musique
- if (music != null)
- {
-
- if (Channel != null)
- {
- Channel.stop();
- Channel = null;
- }
-
- result = music.release();
- music = null;
- if(EngineError!=null)EngineError(result);
- }
-
- result = system.createStream(path, MODE.SOFTWARE | MODE.CREATECOMPRESSEDSAMPLE | MODE.LOOP_OFF, ref music);
- if(EngineError!=null)EngineError(result);
-
- result = system.playSound(CHANNELINDEX.FREE, music, paused, ref Channel);
- if(EngineError!=null)EngineError(result);
- if (Channel != null)
- result = Channel.setCallback(FMOD.CHANNEL_CALLBACKTYPE.END, channelCallback, 0);
- if (EngineError != null) EngineError(result);
- currentPath = path;
- }
- }
- #endregion
- #region Stop Functions
- public static void Stop()
- {
- if (Channel != null)
- {
- RESULT result = Channel.stop();
- Channel = null;
- if(EngineError!=null)EngineError(result);
- }
- }
- #endregion
- #region Pause Functions
-
- public static bool GetPaused()
- {
- bool pause = false;
- if (Channel != null)
- {
- RESULT result = Channel.getPaused(ref pause);
- if(EngineError!=null)EngineError(result);
- }
- return pause;
- }
- public static void SetPaused(bool stat)
- {
- if (Channel != null)
- {
- RESULT result = Channel.setPaused(stat);
- if(EngineError!=null)EngineError(result);
- }
- }
- public static void SetPaused()
- {
- bool paused = false;
- if (Channel != null)
- {
- RESULT result = Channel.getPaused(ref paused);
- if(EngineError!=null)EngineError(result);
- result = Channel.setPaused(!paused);
- if(EngineError!=null)EngineError(result);
- }
- }
-
- #endregion
- #region Volume Functions
- public static void SetMute()
- {
- bool mute = false;
- if (Channel != null)
- {
- RESULT result = Channel.getMute(ref mute);
- if(EngineError!=null)EngineError(result);
- result = Channel.setMute(!mute);
- if(EngineError!=null)EngineError(result);
- }
- }
- public static void SetMute(bool value)
- {
- if (Channel != null)
- {
- RESULT result = Channel.setMute(value);
- if(EngineError!=null)EngineError(result);
- }
- }
- public static bool GetMute()
- {
- bool mute = false;
- if (Channel != null)
- {
- RESULT result = Channel.getMute(ref mute);
- if(EngineError!=null)EngineError(result);
- }
- return mute;
- }
- public static float GetVolume()
- {
- float vol = 1.0f;
-
- if (Channel != null)
- {
- RESULT result = Channel.getVolume(ref vol);
- if (EngineError != null) EngineError(result);
- }
- return vol;
- }
- public static void SetVolume(float Value)
- {
- Value = Math.Abs(Value);
- if (Channel != null)
- {
- RESULT result = Channel.setVolume(Value);
- if (EngineError != null) EngineError(result);
- }
- }
- #endregion
- #region Frequence Functions
-
- public static float GetFrequency()
- {
- float frq = 0;
- if (Channel != null)
- {
- RESULT result = Channel.getFrequency(ref frq);
- if (EngineError != null) EngineError(result);
- }
- return ((frq * 100.0f) / 48000);
- }
- public static void SetFrequency(float freq)
- {
- if (Channel != null)
- {
- RESULT result = Channel.setFrequency(freq * 48000 / 100.0f);
- if(EngineError!=null)EngineError(result);
- }
- }
-
- #endregion
- #region Position Functions
-
- public static void SetPosition(uint pos)
- {
- uint ln = 0;
- if (music != null) music.getLength(ref ln, TIMEUNIT.MS);
- pos = (ln * pos / 100);
- if (Channel != null)
- {
- RESULT result = Channel.setPosition(pos, TIMEUNIT.MS);
- if(EngineError!=null)EngineError(result);
- }
- }
- public static uint GetPosition()
- {
- uint ln = 0;
- uint ms = 0;
- if (music != null)
- {
- RESULT result = music.getLength(ref ln, TIMEUNIT.MS);
- if (EngineError != null) EngineError(result);
- ms = GetMsPosition();
- ms = (100 * ms / ln);
- }
- else
- ms = 0;
- return ms;
- }
- public static void SetMsPosition(uint ms)
- {
- if (Channel != null)
- {
- RESULT result = Channel.setPosition(ms, TIMEUNIT.MS);
- if(EngineError!=null)EngineError(result);
- }
- }
- public static uint GetMsPosition()
- {
- uint ms = 0;
- if (Channel != null)
- {
- RESULT result = Channel.getPosition(ref ms, TIMEUNIT.MS);
- if(EngineError!=null)EngineError(result);
- }
- return ms;
- }
- public static uint GetLength()
- {
- uint ln = 0;
- if (music != null) music.getLength(ref ln, TIMEUNIT.MS);
- return ln;
- }
-
- #endregion
- #endregion
- #region Event Functions
- private static RESULT OnEndMusic(IntPtr channelraw, FMOD.CHANNEL_CALLBACKTYPE type, int command, uint commanddata1, uint commanddata2)
- {
- Channel = null;// en premier pour ne pas avoir erreur lors d'un MessageBox :) ; cas particulier
- if (EndMusic != null)
- EndMusic(currentPath, new EventArgs());
-
- return RESULT.OK;
- }
- #endregion
- #region Error Functions
-
- public static void ShowErrorException(RESULT result)
- {
- if (result != RESULT.OK)
- {
- throw new ApplicationException("Sound Manager Error! " + result + " - " + Error.String(result));
- }
- }
-
- public static void ShowErrorDialogBox(RESULT result, string AppName)
- {
- if (result != RESULT.OK)
- {
- System.Windows.Forms.MessageBox.Show("Sound Manager Error! " + result + " - " + Error.String(result), AppName, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
- }
- }
-
- #endregion
- #region Other Functions
-
- public static bool IsPlaying()
- {
- bool ply = false;
- if (Channel != null)
- {
- RESULT result = Channel.isPlaying(ref ply);
- if(EngineError!=null)EngineError(result);
- }
- return ply;
- }
-
- #endregion
- }
- }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FMOD;
namespace Mehdi_Media_Player
{
static class SoundManager
{
#region Fields
private static FMOD.System system = null;
private static Sound music = null;
private static string currentPath;
private static Channel Channel = null;
public delegate void EndMusicEventHandler(object sender, EventArgs e);
public delegate void ErrorEventHandler(RESULT result);
private static CHANNEL_CALLBACK channelCallback;
public static event EndMusicEventHandler EndMusic;
public static event ErrorEventHandler EngineError;
#endregion
#region Properties
public static string CurrentPath
{
get { return currentPath; }
set { currentPath = value; }
}
public static Sound Music
{
get { return music;}
}
#endregion
#region Init-UpDate-Release
public static void Initialize(int NbChannel)
{
RESULT result;
result = Factory.System_Create(ref system);
if(EngineError!=null)EngineError(result);
uint version = 0;
result = system.getVersion(ref version);
if(EngineError!=null)EngineError(result);
if (version < VERSION.number)
{
throw new ApplicationException("Error! You are using an old version of FMOD " + version.ToString("X") + ". This program requires " + VERSION.number.ToString("X") + ".");
}
result = system.init(NbChannel, INITFLAG.NORMAL, (IntPtr)null);
if(EngineError!=null)EngineError(result);
channelCallback = new CHANNEL_CALLBACK(OnEndMusic);
}
public static void Update()
{
RESULT result= system.update();
if (EngineError != null) EngineError(result);
}
public static void Release()
{
RESULT result= RESULT.OK;
if (music != null)
{
result = music.release();
if (EngineError != null) EngineError(result);
}
if(system!=null)
result = system.release();
if (EngineError != null) EngineError(result);
}
#endregion
#region MainFunctions
#region Play Functions
public static void Play()
{
Play(currentPath);
}
public static void Play(string path)
{
Play(path, false);
}
public static void Play(string path, bool paused)
{
bool isPlaying = false;
RESULT result= RESULT.OK;
if (Channel != null)
{
//si la musique existe
result = Channel.isPlaying(ref isPlaying);
}
else
{
isPlaying = false;
}
if (EngineError != null) EngineError(result);
if ((currentPath == path) && isPlaying)//si la musique du chemin courant est entrain detre joué
{
return;
}
else if (currentPath == path)//sinon la musique du chemin courant nest pas entrain detre joué
{
result = system.playSound(CHANNELINDEX.FREE, music, false, ref Channel);
if(EngineError!=null)EngineError(result);
if(Channel!=null)
result= Channel.setCallback(FMOD.CHANNEL_CALLBACKTYPE.END, channelCallback, 0);
if (EngineError != null) EngineError(result);
}
else
{
//si cest une nouvelle musique
if (music != null)
{
if (Channel != null)
{
Channel.stop();
Channel = null;
}
result = music.release();
music = null;
if(EngineError!=null)EngineError(result);
}
result = system.createStream(path, MODE.SOFTWARE | MODE.CREATECOMPRESSEDSAMPLE | MODE.LOOP_OFF, ref music);
if(EngineError!=null)EngineError(result);
result = system.playSound(CHANNELINDEX.FREE, music, paused, ref Channel);
if(EngineError!=null)EngineError(result);
if (Channel != null)
result = Channel.setCallback(FMOD.CHANNEL_CALLBACKTYPE.END, channelCallback, 0);
if (EngineError != null) EngineError(result);
currentPath = path;
}
}
#endregion
#region Stop Functions
public static void Stop()
{
if (Channel != null)
{
RESULT result = Channel.stop();
Channel = null;
if(EngineError!=null)EngineError(result);
}
}
#endregion
#region Pause Functions
public static bool GetPaused()
{
bool pause = false;
if (Channel != null)
{
RESULT result = Channel.getPaused(ref pause);
if(EngineError!=null)EngineError(result);
}
return pause;
}
public static void SetPaused(bool stat)
{
if (Channel != null)
{
RESULT result = Channel.setPaused(stat);
if(EngineError!=null)EngineError(result);
}
}
public static void SetPaused()
{
bool paused = false;
if (Channel != null)
{
RESULT result = Channel.getPaused(ref paused);
if(EngineError!=null)EngineError(result);
result = Channel.setPaused(!paused);
if(EngineError!=null)EngineError(result);
}
}
#endregion
#region Volume Functions
public static void SetMute()
{
bool mute = false;
if (Channel != null)
{
RESULT result = Channel.getMute(ref mute);
if(EngineError!=null)EngineError(result);
result = Channel.setMute(!mute);
if(EngineError!=null)EngineError(result);
}
}
public static void SetMute(bool value)
{
if (Channel != null)
{
RESULT result = Channel.setMute(value);
if(EngineError!=null)EngineError(result);
}
}
public static bool GetMute()
{
bool mute = false;
if (Channel != null)
{
RESULT result = Channel.getMute(ref mute);
if(EngineError!=null)EngineError(result);
}
return mute;
}
public static float GetVolume()
{
float vol = 1.0f;
if (Channel != null)
{
RESULT result = Channel.getVolume(ref vol);
if (EngineError != null) EngineError(result);
}
return vol;
}
public static void SetVolume(float Value)
{
Value = Math.Abs(Value);
if (Channel != null)
{
RESULT result = Channel.setVolume(Value);
if (EngineError != null) EngineError(result);
}
}
#endregion
#region Frequence Functions
public static float GetFrequency()
{
float frq = 0;
if (Channel != null)
{
RESULT result = Channel.getFrequency(ref frq);
if (EngineError != null) EngineError(result);
}
return ((frq * 100.0f) / 48000);
}
public static void SetFrequency(float freq)
{
if (Channel != null)
{
RESULT result = Channel.setFrequency(freq * 48000 / 100.0f);
if(EngineError!=null)EngineError(result);
}
}
#endregion
#region Position Functions
public static void SetPosition(uint pos)
{
uint ln = 0;
if (music != null) music.getLength(ref ln, TIMEUNIT.MS);
pos = (ln * pos / 100);
if (Channel != null)
{
RESULT result = Channel.setPosition(pos, TIMEUNIT.MS);
if(EngineError!=null)EngineError(result);
}
}
public static uint GetPosition()
{
uint ln = 0;
uint ms = 0;
if (music != null)
{
RESULT result = music.getLength(ref ln, TIMEUNIT.MS);
if (EngineError != null) EngineError(result);
ms = GetMsPosition();
ms = (100 * ms / ln);
}
else
ms = 0;
return ms;
}
public static void SetMsPosition(uint ms)
{
if (Channel != null)
{
RESULT result = Channel.setPosition(ms, TIMEUNIT.MS);
if(EngineError!=null)EngineError(result);
}
}
public static uint GetMsPosition()
{
uint ms = 0;
if (Channel != null)
{
RESULT result = Channel.getPosition(ref ms, TIMEUNIT.MS);
if(EngineError!=null)EngineError(result);
}
return ms;
}
public static uint GetLength()
{
uint ln = 0;
if (music != null) music.getLength(ref ln, TIMEUNIT.MS);
return ln;
}
#endregion
#endregion
#region Event Functions
private static RESULT OnEndMusic(IntPtr channelraw, FMOD.CHANNEL_CALLBACKTYPE type, int command, uint commanddata1, uint commanddata2)
{
Channel = null;// en premier pour ne pas avoir erreur lors d'un MessageBox :) ; cas particulier
if (EndMusic != null)
EndMusic(currentPath, new EventArgs());
return RESULT.OK;
}
#endregion
#region Error Functions
public static void ShowErrorException(RESULT result)
{
if (result != RESULT.OK)
{
throw new ApplicationException("Sound Manager Error! " + result + " - " + Error.String(result));
}
}
public static void ShowErrorDialogBox(RESULT result, string AppName)
{
if (result != RESULT.OK)
{
System.Windows.Forms.MessageBox.Show("Sound Manager Error! " + result + " - " + Error.String(result), AppName, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
}
#endregion
#region Other Functions
public static bool IsPlaying()
{
bool ply = false;
if (Channel != null)
{
RESULT result = Channel.isPlaying(ref ply);
if(EngineError!=null)EngineError(result);
}
return ply;
}
#endregion
}
}
Historique
- 10 mars 2008 19:58:20 :
- descripition manquante
- 14 mars 2008 03:44:44 :
- Version 1 Final
Sources du même auteur
Sources de la même categorie
Sources en rapport avec celle ci
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
PLay Sound [ par Charlie ]
Allo...Comment faire pour faire jouer un .wav sans utiliser la commande play sound ? Je suis en C et j'ai pas le droit d'utiliser de .dll ou de rajout
Télécommande carte son sound blaster [ par youenn56 ]
Bonjour,Je suis en train de créer un logiciel pour faire fonctionner un ordinateur en lecteur multimédia de salon, donc sans souris ni clavi
SoundPlayer et ressources [ par babe59 ]
Bonjour,J'ai trouvé différentes pistes pour lire un fichier WAV intégré à un fichier ressource mais je n'arrive pas à les faire fonctionner (je suis s
Algorithme RSA [ par douss4 ]
Bonsoir,J'ai essayé d'écrire un algorithme de cryptage (RSA). Le code à bien marché avec des int. J'ai changé les int par des float. Au moment du décr
|
Téléchargements
Logiciels à télécharger sur le même thème :
Comparez les prix Nouvelle version

HTC G1
Entre 449€ et 449€
|