begin process at 2012 02 11 05:27:34
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

.NET

 > SOUNDMANAGER ( FMOD)

SOUNDMANAGER ( FMOD)


 Information sur la source

Note :
Aucune note
Catégorie :.NET Source .NET ( DotNet ) Classé sous :Fmod, Sound, Sound Manager, Sound Engine, mehdi Niveau :Débutant Date de création :10/03/2008 Date de mise à jour :14/03/2008 03:44:39 Vu :6 092

Auteur : T_Mehdi

Ecrire un message privé
Site perso
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 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

Source avec Zip Source .NET (Dotnet) ANALYSEUR LEXICAL
Source avec une capture Source .NET (Dotnet) CHIMERA GAMES ENGINE
Source avec Zip Source avec une capture Source .NET (Dotnet) QUICKLY MEDIA PLAYER
Source avec Zip Source .NET (Dotnet) MSN ADDIN

 Sources de la même categorie

Source avec Zip Source avec une capture Source .NET (Dotnet) ORIONBANQUE par toutphp
Source avec Zip Source avec une capture Source .NET (Dotnet) ORIONAPPLICATION par toutphp
Source avec Zip SOCKET CONNEXION CLIENT & SERVEUR par ziedto83
Source avec Zip Source .NET (Dotnet) FFMPEG.NET : WRAPPER .NET DE FFMPEG par MasterShadows
Source avec Zip Source .NET (Dotnet) ATTACHER, CRÉER ET SAUVEGARDER UNE BASE DE DONNÉES SQL SERVE... par Alvepinai

 Sources en rapport avec celle ci

Source avec une capture Source .NET (Dotnet) CHIMERA GAMES ENGINE par T_Mehdi
Source avec Zip Source avec une capture Source .NET (Dotnet) VISION SPECTRALE ET OSCILLOSCOPIQUE D'UN FICHIER AUDIO par MaxSoldier
Source avec Zip Source avec une capture Source .NET (Dotnet) ALGORITHME SOUNDEX par Bidou

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


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&#233;er un logiciel pour faire fonctionner un ordinateur en lecteur multim&#233;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 Utilisation de FMOD [ par sautebas ] Bonjour, Je débute dans le c# et j'aimerais utiliser fmod pour tout simplement jouer des son (mp3, wav, etc.). J'ai plus au moins copié le système de


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,874 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales