private void CleanUpSound(ref FMOD.Sound fmodSound)
        {
            this.State            = PlayerState.Stop;
            this.CurrentMediaFile = null;

            if (this.channelInfo != null && this.channelInfo.Channel != null)
            {
                this.channelInfo.File.State = PlayerState.Stop;
                this.channelInfo.Channel.setCallback(null);
                this.channelInfo.Channel = null;
                this.channelInfo.File    = null;
                this.channelInfo         = null;
            }

            if (fmodSound != null)
            {
                var result = fmodSound.release();
                result.ERRCHECK();
                fmodSound = null;
            }

            this.timer.Stop();

            this.currentPositionMs = 0;
            this.OnPropertyChanged("CurrentPositionMs");
            this.LengthMs = 0;
        }
示例#2
0
    void PlayNewSong()
    {
        string documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).ToString();
        string path            = documentsFolder + "/AGR2280/Custom Music/";

        string[] availableFiles = Directory.GetFiles(path, "*.mp3");

        // Pick song to stream
        songToPlay = UnityEngine.Random.Range(0, availableFiles.Length);

        if (channel != null)
        {
            channel = null;
        }
        PlayingMusic = null;

        result           = system.init(1, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
        result           = system.createSound(availableFiles [songToPlay], FMOD.MODE.CREATESTREAM, ref PlayingMusic);
        result           = system.playSound(music, PlayingMusic, false, ref channel);
        result           = system.createDSPByType(FMOD.DSP_TYPE.HIGHPASS, ref musicHighPass);
        result           = system.createDSPByType(FMOD.DSP_TYPE.LOWPASS, ref musicLowPass);
        result           = channel.addDSP(musicHighPass, ref highPassFilter);
        result           = channel.addDSP(musicLowPass, ref lowPassFilter);
        firstSongStarted = true;
    }
示例#3
0
 internal Sound(FMOD.Sound sound, string file, string name, float volume = 1.0f)
 {
     _sound = sound;
     _file = file;
     _name = name;
     _volume = volume;
 }
示例#4
0
 public static Sound FromFmod(FMOD.Sound sound)
 {
     if (sound == null)
     {
         throw new ArgumentNullException("sound");
     }
     return(new Sound(sound));
 }
示例#5
0
    public void SetSound(FMOD.Sound sound)
    {
        if (Channel != null)
        {
            Channel.stop();
        }

        Sound = sound;
    }
示例#6
0
        protected void RegisterSound(FMOD.Sound sound)
        {
            IntPtr raw = sound.getRaw();

            if (allSounds.ContainsKey(raw))
            {
                allSounds.Remove(raw);
            }
            allSounds.Add(raw, this);
        }
示例#7
0
        public virtual void Dispose()
        {
            if (!Cloned && sound != null)
            {
                sound.release();
                sound = null;
            }

            disposed = true;
        }
示例#8
0
 public void StopMusic()
 {
     PlayingMusic.release();
     channel.stop();
     system.close();
     system.release();
     channel      = null;
     PlayingMusic = null;
     system       = null;
 }
示例#9
0
 void OnApplicationQuit()
 {
     PlayingMusic.release();
     channel.stop();
     system.close();
     system.release();
     channel      = null;
     PlayingMusic = null;
     system       = null;
 }
示例#10
0
        //This function is used to add a delay in the detection to playback ratio.
        //For example, if an obstacle is spawned to the music, it will be spawned immediately
        //upon the song detecting a beat, when oftentimes we want to line up that obstacle
        //with the point in the music it plays. So, the obstacle will spawn before the song gets
        //to the beat detected point.
        //Use milliseconds to express the amount of delay time you want between playback and detection.
        public void loadSongToDelay(int milliseconds)
        {
            delayedSong = true;
            songChannel1.setVolume(0);

            audio2 = new FMOD.Sound();
            FMODErrorCheck(system.createStream(songString, FMOD.MODE.SOFTWARE, ref audio2));

            songChannel2 = new FMOD.Channel();
            FMODErrorCheck(system.playSound(FMOD.CHANNELINDEX.FREE, audio2, true, ref songChannel2));
            songChannel2.setChannelGroup(channelMusic);
            timeToDelay = milliseconds;
        }
示例#11
0
    void Start()
    {
        _mutedSourceJustForUserSpeed = GameObject.Find("MutedSourceJustForDefaultSpeed").GetComponent <CustomAudioSource>();

        FMOD.Sound sound = _mutedSourceJustForUserSpeed.Sound;

        if (sound != null)
        {
            uint totalTime;
            _mutedSourceJustForUserSpeed.Sound.getLength(out totalTime, FMOD.TIMEUNIT.MS);
            _totalTimeTimeSpan = TimeSpan.FromMilliseconds(totalTime);
        }

        _userProgression = GetComponent <Text>();
    }
示例#12
0
文件: Test.cs 项目: Filibert/DOREMI
    void Start()
    {
        _audioMixer = AudioMixer.Instance;
        _source     = GetComponent <CustomAudioSource>();

        // Get the first track in Assets/Resources.
        foreach (var item in Directory.GetDirectories(Directory.GetCurrentDirectory() + "/Assets/Resources/").ToList())
        {
            foreach (var track in Directory.GetFiles(item).Where(n => Path.GetExtension(n) == ".wav"))
            {
                _track = _audioMixer.Load(track);
                break;
            }

            break;
        }

        _source.Play(_track);
        _source.Channel.setMode(FMOD.MODE.LOOP_NORMAL);
        _source.Channel.setLoopCount(-1);
    }
        private void CleanUpSound(ref FMOD.Sound fmodSound)
        {
            this.timer.Stop();

            this.State            = PlayerState.Stop;
            this.CurrentMediaFile = null;

            if (this.channelInfo != null)
            {
                this.channelInfo.CleanUp();
                this.channelInfo = null;
                this.system.update().ERRCHECK();
            }

            if (fmodSound != null)
            {
                fmodSound.release().ERRCHECK();
                fmodSound = null;
                this.system.update().ERRCHECK();
            }

            this.LengthMs          = 0;
            this.CurrentPositionMs = 0;
        }
示例#14
0
        public RESULT createStream            (string name, MODE mode, out Sound sound)
        {
            CREATESOUNDEXINFO exinfo = new CREATESOUNDEXINFO();
            exinfo.cbsize = Marshal.SizeOf(exinfo);

            return createStream(name, mode, ref exinfo, out sound);
        }
示例#15
0
        public RESULT createStream            (string name, MODE mode, ref CREATESOUNDEXINFO exinfo, out Sound sound)
        {
            sound = null;

            byte[] stringData;
            stringData = Encoding.UTF8.GetBytes(name + Char.MinValue);
            
            exinfo.cbsize = Marshal.SizeOf(exinfo);

            IntPtr soundraw;
            RESULT result = FMOD_System_CreateStream(rawPtr, stringData, mode, ref exinfo, out soundraw);
            sound = new Sound(soundraw);

            return result;
        }
示例#16
0
        public RESULT createStream            (string name, MODE mode, ref CREATESOUNDEXINFO exinfo, out Sound sound)
        {
            sound = null;

            byte[] stringData;
            stringData = Encoding.UTF8.GetBytes(name + Char.MinValue);

            CREATESOUNDEXINFO_INTERNAL exinfoInternal = CREATESOUNDEXINFO_INTERNAL.CreateFromExternal(ref exinfo);

            IntPtr soundraw;
            RESULT result = FMOD5_System_CreateStream(rawPtr, stringData, mode, ref exinfoInternal, out soundraw);
            sound = new Sound(soundraw);

            return result;
        }
示例#17
0
 // HACER: CREAR Y REPRODUCIR EVENTOS 3D O SIN POSICIONAMIENTO (CREATE3D(), PLAY3D())
 public void Create(string path, FMOD.MODE mode, out FMOD.Sound sound)
 {
     SoundSystem.instance.ErrorCheck(_soundSystem.createSound(path, mode | FMOD.MODE._3D, out sound));
 }
        //Loads a song into memory given a sample size and file-path to an audio file.
        //The most commonly used and accurate Sample Size is 1024.
        public void LoadSong(int sSize, string audioString)
        {
            //Take in Aruguments
            sampleSize = sSize;
            songString = audioString;

            stopW.Start();
            areWePlaying = true;
            specFlux = 0.0f;
            timeBetween = 0;
            initialTime = (int)stopW.ElapsedMilliseconds;
            currentTime = 0;
            currentSeconds = 0;
            lastSeconds = 0;
            currentMillis = 0;
            currentMinutes = 0;
            median = 0.0f;
            smoothMedian = 0.0f;
            beatThreshold = 0.6f;
            thresholdSmoother = 0.6f;
            started = false;
            lastBeatRegistered = new TimeStamp();
            audio = new FMOD.Sound();
            songChannel1 = new FMOD.Channel();

            channelMusic = new FMOD.ChannelGroup();

            previousFFT = new float[sampleSize
                / 2 + 1];
            for (int i = 0; i < sampleSize / 2; i++)
            {
                previousFFT[i] = 0;
            }

            //Brute force for testing
            //songString = "Music/drums.wav";

            //Create channel and audio
            FMODErrorCheck(system.createChannelGroup(null, ref channelMusic));
               // CREATESOUNDEXINFO ex = new CREATESOUNDEXINFO();

            FMODErrorCheck(system.createStream(songString, FMOD.MODE.SOFTWARE, ref audio));

            audio.getLength(ref seconds, FMOD.TIMEUNIT.MS);
            audio.getDefaults(ref sampleRate, ref zeroF, ref zeroF, ref zero);
            seconds = ((seconds + 500) / 1000);
            minutes = seconds / 60;
            fullSeconds = (int)seconds;
            seconds = seconds - (minutes * 60);

            FMODErrorCheck(system.playSound(FMOD.CHANNELINDEX.FREE, audio, true, ref songChannel1));

            //hzRange = (sampleRate / 2) / static_cast<float>(sampleSize);
            songChannel1.setChannelGroup(channelMusic);
            songChannel1.setPaused(true);

            Console.WriteLine("Song Length: " + minutes + ":" + seconds);
            Console.WriteLine("Sample Rate: " + sampleRate);

            //std::cout << "Freq Range: " << hzRange << std::endl;
            //songChannel1.setVolume(0);
        }
示例#19
0
 // Pre-loading FSB files (from disk or from memory, use FMOD_OPENMEMORY_POINT to point to pre-loaded memory).
 public RESULT preloadFSB(string filename, int streaminstance, Sound sound)
 {
     return FMOD_EventSystem_PreloadFSB(eventsystemraw, filename, streaminstance, sound.getRaw());
 }
示例#20
0
 private Sound(FMOD.Sound sound)
     : this()
 {
     _fmodSound = sound;
 }
示例#21
0
 public ChannelCollection(FMOD.Sound fmodSound, IReadOnlyList <RESULT> suppressions)
     : this()
 {
     _fmodSound    = fmodSound;
     _suppressions = suppressions;
 }
示例#22
0
 public void Play(FMOD.Sound sound)
 {
     SetSound(sound);
     Play();
 }
示例#23
0
        //Loads a song into memory given a sample size and file-path to an audio file.
        //The most commonly used and accurate Sample Size is 1024.
        public void LoadSong(int sSize, string audioString)
        {
            //Take in Aruguments
            sampleSize = sSize;
            songString = audioString;

            stopW.Start();
            areWePlaying       = true;
            specFlux           = 0.0f;
            timeBetween        = 0;
            initialTime        = (int)stopW.ElapsedMilliseconds;
            currentTime        = 0;
            currentSeconds     = 0;
            lastSeconds        = 0;
            currentMillis      = 0;
            currentMinutes     = 0;
            median             = 0.0f;
            smoothMedian       = 0.0f;
            beatThreshold      = 0.6f;
            thresholdSmoother  = 0.6f;
            started            = false;
            lastBeatRegistered = new TimeStamp();
            audio        = new FMOD.Sound();
            songChannel1 = new FMOD.Channel();
            beatWait     = false;
            channelMusic = new FMOD.ChannelGroup();

            previousFFT = new float[sampleSize
                                    / 2 + 1];
            for (int i = 0; i < sampleSize / 2; i++)
            {
                previousFFT[i] = 0;
            }

            //Brute force for testing
            //songString = "Music/drums.wav";

            //Create channel and audio
            FMODErrorCheck(system.createChannelGroup(null, ref channelMusic));
            // CREATESOUNDEXINFO ex = new CREATESOUNDEXINFO();

            FMODErrorCheck(system.createStream(songString, FMOD.MODE.SOFTWARE, ref audio));

            audio.getLength(ref seconds, FMOD.TIMEUNIT.MS);
            audio.getDefaults(ref sampleRate, ref zeroF, ref zeroF, ref zero);
            seconds     = ((seconds + 500) / 1000);
            minutes     = seconds / 60;
            fullSeconds = (int)seconds;
            seconds     = seconds - (minutes * 60);

            FMODErrorCheck(system.playSound(FMOD.CHANNELINDEX.FREE, audio, true, ref songChannel1));

            //hzRange = (sampleRate / 2) / static_cast<float>(sampleSize);
            songChannel1.setChannelGroup(channelMusic);
            songChannel1.setPaused(true);

            Console.WriteLine("Song Length: " + minutes + ":" + seconds);
            Console.WriteLine("Sample Rate: " + sampleRate);

            //std::cout << "Freq Range: " << hzRange << std::endl;
            //songChannel1.setVolume(0);
        }
示例#24
0
文件: fmod.cs 项目: huming2207/ghgame
        public RESULT playSound(CHANNELINDEX channelid, Sound sound, bool paused, ref Channel channel)
        {
            RESULT result      = RESULT.OK;
            IntPtr      channelraw;
            Channel     channelnew  = null;

            if (channel != null)
            {
                channelraw = channel.getRaw();
            }
            else
            {
                channelraw  = new IntPtr();
            }

            try
            {
                result = FMOD_System_PlaySound(systemraw, channelid, sound.getRaw(), (paused ? 1 : 0), ref channelraw);
            }
            catch
            {
                result = RESULT.ERR_INVALID_PARAM;
            }
            if (result != RESULT.OK)
            {
                return result;
            }

            if (channel == null)
            {
                channelnew = new Channel();
                channelnew.setRaw(channelraw);
                channel = channelnew;
            }
            else
            {
                channel.setRaw(channelraw);
            }

            return result;
        }
示例#25
0
 public RESULT createSound(string name, MODE mode, ref CREATESOUNDEXINFO exinfo, out Sound sound)
 {
     sound = null;
     byte[] bytes = Encoding.UTF8.GetBytes(name + '\0');
     exinfo.cbsize = Marshal.SizeOf(exinfo);
     IntPtr raw;
     RESULT result = System.FMOD5_System_CreateSound(this.rawPtr, bytes, mode, ref exinfo, out raw);
     sound = new Sound(raw);
     return result;
 }
示例#26
0
        // Sound/DSP/Channel creation and retrieval.
        public RESULT createSound(string name_or_data, MODE mode, ref CREATESOUNDEXINFO exinfo, ref Sound sound)
        {
            var result = RESULT.OK;
            var soundraw = new IntPtr();
            Sound soundnew = null;

            mode = mode | MODE.UNICODE;

            try
            {
                result = FMOD_System_CreateSound(systemraw, name_or_data, mode, ref exinfo, ref soundraw);
            }
            catch
            {
                result = RESULT.ERR_INVALID_PARAM;
            }
            if (result != RESULT.OK)
            {
                return result;
            }

            if (sound == null)
            {
                soundnew = new Sound();
                soundnew.setRaw(soundraw);
                sound = soundnew;
            }
            else
            {
                sound.setRaw(soundraw);
            }

            return result;
        }
示例#27
0
 internal SyncPoint(IntPtr ptr, FMOD.Sound sound, IReadOnlyList <RESULT> suppressions)
 {
     _pointer      = ptr;
     _sound        = sound;
     _suppressions = suppressions;
 }
示例#28
0
文件: fmod.cs 项目: olbers/sauip4
 public RESULT recordStart(Sound sound, bool loop)
 {
     return FMOD_System_RecordStart(systemraw, sound.getRaw(), loop);
 }
示例#29
0
 private string GetSoundName(Sound sound)
 {
     StringBuilder name = new StringBuilder(0x100);
     sound.getName(name, name.Capacity);
     return name.ToString().Trim();
 }
        //This function is used to add a delay in the detection to playback ratio.
        //For example, if an obstacle is spawned to the music, it will be spawned immediately
        //upon the song detecting a beat, when oftentimes we want to line up that obstacle
        //with the point in the music it plays. So, the obstacle will spawn before the song gets
        //to the beat detected point.
        //Use milliseconds to express the amount of delay time you want between playback and detection.
        public void loadSongToDelay(int milliseconds)
        {
            delayedSong = true;
            songChannel1.setVolume(0);

            audio2 = new FMOD.Sound();
            FMODErrorCheck(system.createStream(songString, FMOD.MODE.SOFTWARE, ref audio2));

            songChannel2 = new FMOD.Channel();
            FMODErrorCheck(system.playSound(FMOD.CHANNELINDEX.FREE, audio2, true, ref songChannel2));
            songChannel2.setChannelGroup(channelMusic);
            timeToDelay = milliseconds;
        }
示例#31
0
 public RESULT recordStart            (int id, Sound sound, bool loop)
 {
     return FMOD_System_RecordStart(rawPtr, id, sound.getRaw(), loop);
 }
示例#32
0
 public void Play(FMOD.Sound sound, FMOD.ChannelGroup channelGroup, bool paused, out FMOD.Channel channel, FMOD.VECTOR pos, FMOD.VECTOR vel, FMOD.VECTOR alt_pan_pos)
 {
     _soundSystem.playSound(sound, channelGroup, paused, out channel);
     _channel = channel;
     _channel.set3DAttributes(ref pos, ref vel, ref alt_pan_pos);
 }
示例#33
0
        public RESULT getSubSoundParent(out Sound parentsound)
        {
            parentsound = null;

            IntPtr subsoundraw;
            RESULT result = FMOD_Sound_GetSubSoundParent(rawPtr, out subsoundraw);
            parentsound = new Sound(subsoundraw);

            return result;
        }
示例#34
0
        public RESULT createStream            (byte[] data, MODE mode, ref CREATESOUNDEXINFO exinfo, out Sound sound)
        {
            sound = null;

            CREATESOUNDEXINFO_INTERNAL exinfoInternal = CREATESOUNDEXINFO_INTERNAL.CreateFromExternal(ref exinfo);

            IntPtr soundraw;
            RESULT result = FMOD5_System_CreateStream(rawPtr, data, mode, ref exinfoInternal, out soundraw);
            sound = new Sound(soundraw);

            return result;
        }
示例#35
0
        public RESULT getSound               (int index, out Sound sound)
        {
            sound = null;

            IntPtr soundraw;
            RESULT result = FMOD_SoundGroup_GetSound(rawPtr, index, out soundraw);
            sound = new Sound(soundraw);

            return result;
        }
示例#36
0
        public RESULT createStream            (byte[] data, MODE mode, ref CREATESOUNDEXINFO exinfo, out Sound sound)
        {
            sound = null;

            exinfo.cbsize = Marshal.SizeOf(exinfo);

            IntPtr soundraw;
            RESULT result = FMOD_System_CreateStream(rawPtr, data, mode, ref exinfo, out soundraw);
            sound = new Sound(soundraw);

            return result;
        }
示例#37
0
文件: fmod.cs 项目: huming2207/ghgame
        public RESULT setSubSound(int index, Sound subsound)
        {
            IntPtr subsoundraw = subsound.getRaw();

            return FMOD_Sound_SetSubSound(soundraw, index, subsoundraw);
        }
示例#38
0
        public RESULT playSound              (Sound sound, ChannelGroup channelGroup, bool paused, out Channel channel)
        {
            channel = null;

            IntPtr channelGroupRaw = (channelGroup != null) ? channelGroup.getRaw() : IntPtr.Zero;

            IntPtr channelraw;
            RESULT result = FMOD_System_PlaySound(rawPtr, sound.getRaw(), channelGroupRaw, paused, out channelraw);
            channel = new Channel(channelraw);

            return result;
        }
示例#39
0
文件: fmod.cs 项目: huming2207/ghgame
        public RESULT createStream(byte[] data, MODE mode, ref CREATESOUNDEXINFO exinfo, ref Sound sound)
        {
            RESULT result           = RESULT.OK;
            IntPtr      soundraw    = new IntPtr();
            Sound       soundnew    = null;

            try
            {
                result = FMOD_System_CreateStream(systemraw, data, mode, ref exinfo, ref soundraw);
            }
            catch
            {
                result = RESULT.ERR_INVALID_PARAM;
            }
            if (result != RESULT.OK)
            {
                return result;
            }

            if (sound == null)
            {
                soundnew = new Sound();
                soundnew.setRaw(soundraw);
                sound = soundnew;
            }
            else
            {
                sound.setRaw(soundraw);
            }

            return result;
        }
示例#40
0
        public RESULT getSubSound             (int index, out Sound subsound)
        {
            subsound = null;

            IntPtr subsoundraw;
            RESULT result = FMOD_Sound_GetSubSound(rawPtr, index, out subsoundraw);
            subsound = new Sound(subsoundraw);

            return result;
        }
示例#41
0
    static FMOD.RESULT DialogueEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, FMOD.Studio.EventInstance instance, IntPtr parameterPtr)
    {
        IntPtr stringPtr;

        instance.getUserData(out stringPtr);

        GCHandle stringHandle = GCHandle.FromIntPtr(stringPtr);
        String   key          = stringHandle.Target as String;

        switch (type)
        {
        case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:
        {
            FMOD.MODE soundMode = FMOD.MODE.LOOP_NORMAL | FMOD.MODE.CREATECOMPRESSEDSAMPLE | FMOD.MODE.NONBLOCKING;
            var       parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));

            if (key.Contains("."))
            {
                FMOD.Sound dialogueSound;
                var        soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(Application.streamingAssetsPath + "/" + key, soundMode, out dialogueSound);
                if (soundResult == FMOD.RESULT.OK)
                {
                    parameter.sound         = dialogueSound.handle;
                    parameter.subsoundIndex = -1;
                    Marshal.StructureToPtr(parameter, parameterPtr, false);
                }
            }
            else
            {
                FMOD.Studio.SOUND_INFO dialogueSoundInfo;
                var keyResult = FMODUnity.RuntimeManager.StudioSystem.getSoundInfo(key, out dialogueSoundInfo);
                if (keyResult != FMOD.RESULT.OK)
                {
                    break;
                }
                FMOD.Sound dialogueSound;
                var        soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(dialogueSoundInfo.name_or_data, soundMode | dialogueSoundInfo.mode, ref dialogueSoundInfo.exinfo, out dialogueSound);
                if (soundResult == FMOD.RESULT.OK)
                {
                    parameter.sound         = dialogueSound.handle;
                    parameter.subsoundIndex = dialogueSoundInfo.subsoundindex;
                    Marshal.StructureToPtr(parameter, parameterPtr, false);
                }
            }
        }
        break;

        case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND:
        {
            var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
            var sound     = new FMOD.Sound();
            sound.handle = parameter.sound;
            sound.release();
        }
        break;

        case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROYED:
            stringHandle.Free();
            break;
        }
        return(FMOD.RESULT.OK);
    }
示例#42
0
        public RESULT getCurrentSound       (out Sound sound)
        {
            sound = null;

            IntPtr soundraw;
            RESULT result = FMOD_Channel_GetCurrentSound(getRaw(), out soundraw);
            sound = new Sound(soundraw);

            return result;
        }
示例#43
0
 public SoundChannel(Sound sound)
 {
     m_fadeTimer = new System.Timers.Timer(FADE_TIMER_INTERVAL);
     m_fadeTimer.Elapsed += new ElapsedEventHandler(fadeTimer_Elapsed);
     this.Sound = sound;
 }
示例#44
0
文件: fmod.cs 项目: huming2207/ghgame
        public RESULT getCurrentSound(ref Sound sound)
        {
            RESULT result      = RESULT.OK;
            IntPtr soundraw    = new IntPtr();
            Sound  soundnew    = null;

            try
            {
                result = FMOD_Channel_GetCurrentSound(channelraw, ref soundraw);
            }
            catch
            {
                result = RESULT.ERR_INVALID_PARAM;
            }
            if (result != RESULT.OK)
            {
                return result;
            }

            if (sound == null)
            {
                soundnew = new Sound();
                soundnew.setRaw(soundraw);
                sound = soundnew;
            }
            else
            {
                sound.setRaw(soundraw);
            }

            return result;
        }
示例#45
0
 public void Dispose()
 {
     if(m_fadeTimer.Enabled) {
         m_fadeTimer.Enabled = false;
     }
     bool playing = false;
     if(m_channel != null) {
         m_channel.isPlaying(ref playing);
         if(playing) {
             m_channel.stop();
         }
         m_channel = null;
     }
     if(m_sound != null) {
         m_sound.release();
         m_sound = null;
     }
     GC.SuppressFinalize(this);
 }
示例#46
0
文件: fmod.cs 项目: huming2207/ghgame
        public RESULT getSound(int index, ref Sound sound)
        {
            RESULT result         = RESULT.OK;
            IntPtr soundraw      = new IntPtr();
            Sound soundnew      = null;

            try
            {
                result = FMOD_SoundGroup_GetSound(soundgroupraw, index, ref soundraw);
            }
            catch
            {
                result = RESULT.ERR_INVALID_PARAM;
            }
            if (result != RESULT.OK)
            {
                return result;
            }

            if (sound == null)
            {
                soundnew = new Sound();
                soundnew.setRaw(soundraw);
                sound = soundnew;
            }
            else
            {
                sound.setRaw(soundraw);
            }

            return result;
        }
示例#47
0
 private string GetSoundName(Sound sound)
 {
     StringBuilder sb = new StringBuilder(256);
     sound.getName(sb, sb.Capacity);
     return sb.ToString().Trim();
 }
示例#48
0
文件: fmod.cs 项目: huming2207/ghgame
        public RESULT createStream(string name_or_data, MODE mode, ref Sound sound)
        {
            RESULT result           = RESULT.OK;
            IntPtr      soundraw    = new IntPtr();
            Sound       soundnew    = null;

            mode = mode | FMOD.MODE.UNICODE;

            try
            {
                result = FMOD_System_CreateStream(systemraw, name_or_data, mode, 0, ref soundraw);
            }
            catch
            {
                result = RESULT.ERR_INVALID_PARAM;
            }
            if (result != RESULT.OK)
            {
                return result;
            }

            if (sound == null)
            {
                soundnew = new Sound();
                soundnew.setRaw(soundraw);
                sound = soundnew;
            }
            else
            {
                sound.setRaw(soundraw);
            }

            return result;
        }
示例#49
0
        public RESULT getSubSound(int index, ref Sound subsound)
        {
            var result = RESULT.OK;
            var subsoundraw = new IntPtr();
            Sound subsoundnew = null;

            try
            {
                result = FMOD_Sound_GetSubSound(soundraw, index, ref subsoundraw);
            }
            catch
            {
                result = RESULT.ERR_INVALID_PARAM;
            }
            if (result != RESULT.OK)
            {
                return result;
            }

            if (subsound == null)
            {
                subsoundnew = new Sound();
                subsoundnew.setRaw(subsoundraw);
                subsound = subsoundnew;
            }
            else
            {
                subsound.setRaw(subsoundraw);
            }

            return result;
        }
示例#50
0
文件: fmod.cs 项目: huming2207/ghgame
 public RESULT recordStart(int id, Sound sound, bool loop)
 {
     return FMOD_System_RecordStart(systemraw, id, sound.getRaw(), (loop ? 1 : 0));
 }
示例#51
0
    public void DisplayAndPlayMusicInstrument()
    {
        DestroyEverything(); string folderName = DropdownMusic.options[DropdownMusic.value].text;
        string musicFolderPath = _dictionnaryMusic[folderName];
        var    score           = (GameObject)Resources.Load(folderName + "/" + folderName + "Score", typeof(GameObject));

        if (score != null)
        {
            Debug.Log(score);
            score = Instantiate(score, transform);
        }
        int i = 1;

        foreach (var track in Directory.GetFiles(musicFolderPath).Where(n => (Path.GetExtension(n) == ".mp3") || (Path.GetExtension(n) == ".wav")))
        {
            Slider slider = Instantiate(VolumeSlider);

            slider.transform.SetParent(Canvas.transform, false);
            slider.transform.Translate(new Vector3(-20, -i, 0));
            slider.onValueChanged.AddListener(delegate { ChangeVolume(slider, Path.GetFileName(track)); });


            Button goButton = Instantiate(MuteButton);
            goButton.transform.SetParent(Canvas.transform, false);
            goButton.GetComponentInChildren <Text>().text = Path.GetFileName(track);
            goButton.transform.Translate(new Vector3(i, 0, 0));
            goButton.transform.localScale = new Vector3(0.85f, 1, 1);

            goButton.onClick.AddListener(() =>
            {
                if (_sources.ContainsKey(goButton.GetComponentInChildren <Text>().text))
                {
                    if (Math.Abs(_sources[goButton.GetComponentInChildren <Text>().text].Volume) > 0.2)
                    {
                        _sources[goButton.GetComponentInChildren <Text>().text].Volume = 0;
                        slider.value = 0;
                    }
                    else
                    {
                        _sources[goButton.GetComponentInChildren <Text>().text].Volume = 1;
                        slider.value = 1;
                    }
                }
            });

            FMOD.Sound        sound  = _audioMixer.Load(track);
            CustomAudioSource source = Instantiate(SourcePrefab).GetComponent <CustomAudioSource>();
            OrchestraPrefab.AddSource(source);
            source.SetSound(sound);

            _sources.Add(Path.GetFileName(track), source);

            _sliders[slider] = source;
            Source           = source;
            i += 30;
        }
        //OrchestraPrefab.MutedSourceJustForDefaultSpeed;
        foreach (var source in _sources)
        {
            source.Value.Play();
        }
    }