Example #1
0
 private void btnPlay_Click(object sender, EventArgs e)
 {
     if (channel != null && channel.IsPlaying)
     {
         return;
     }
     sound   = fmod.CreateSound(MP3_PATH);
     channel = fmod.PlaySound(sound);
 }
Example #2
0
        public override void PlaySound(GenericAudioFile _f)
        {
            if (closing)
            {
                return;
            }
            var f = (FMODCoreFile)_f;

            system.PlaySound(f.snd);
        }
Example #3
0
		private void WaveFormWindow_Load(object sender, EventArgs e)
		{
			_system = Factory.CreateSystem();
			_system.Initialize(InitFlags.Normal);
			
			_sound = _system.CreateStream(SNUFF, Mode.LoopNormal);
			waveForm1.LoadSound(_sound);
			_channel = _system.PlaySound(_sound);
			totalMs = _sound.GetLength();
		}
Example #4
0
 public void Play(Sound sound, params DspType[] effects)
 {
     Reset();
     _channel             = _system.PlaySound(sound, true);
     _channel.SoundEnded += (s, e) => Reset();
     foreach (var dspType in effects)
     {
         var dsp = _system.CreateDspByType(dspType);
         _effects.Add(dsp);
         _channel.AddDsp(dsp, DspIndex.Tail);
     }
 }
Example #5
0
 public void Play()
 {
     _channel = _system.PlaySound(_sound, true);
     if (_autoDispose)
     {
         _channel.SoundEnded += (s, e) => Dispose();
     }
     for (var i = 0; i < _effects.Count; i++)
     {
         _channel.AddDsp(_effects[i], i);
     }
     _channel.Resume();
 }
Example #6
0
 private void PlayDrum(DrumType drumType)
 {
     _fmod.PlaySound(_drums[drumType]);
     _fmod.Update();
 }
Example #7
0
        /// <summary>
        /// Loads the specified file into the player.
        /// </summary>
        /// <returns>Boolean</returns>
        private async Task <bool> LoadMusicAsync(Action LoadMusicAction)
        {
            try
            {
                await InitializeSwitch.Dispatcher.RunAsync(() =>
                {
                    MediaChanging?.Invoke(this, new EventArgs());
                });
                await Stop();

                Result loadResult = Result.Ok;
                await Task.Run(() =>
                {
                    PlayerState = PlayerState.Stopped;
                    LoadMusicAction(); //loads the respective stream
                    //load the stream into the channel but don't play it yet.
                    loadResult = _fmodSys.PlaySound(_fmodSound, null, true, out _fmodChannel);
                });

                //get and update length of the track.
                Length = TimeSpan.FromMilliseconds(_fmodSound.LengthInMilliseconds).TotalSeconds;

                //set the channel callback for all the syncpoints
                loadResult = _fmodChannel.SetCallback(_channelEndCallback);

                //add all the sync points
                //1. when song ends
                loadResult = _fmodSound.AddSyncPoint(_fmodSound.LengthInMilliseconds, TimeUnit.Ms, "songended", out _endSyncPoint);

                //2. when song has reached the last 15 seconds
                loadResult = _fmodSound.AddSyncPoint(_fmodSound.LengthInMilliseconds - 15000, TimeUnit.Ms, "songabouttoended", out _last15SyncPoint);

                //3. when song has reached the last 5 seconds
                loadResult = _fmodSound.AddSyncPoint(_fmodSound.LengthInMilliseconds - 5000, TimeUnit.Ms, "fade", out _last5SyncPoint);

                //update the system once here so that
                //all the sync points and callbacks are saved and updated.
                loadResult = _fmodSys.Update();

                await InitializeSwitch.Dispatcher.RunAsync(() =>
                {
                    if (Equalizer == null)
                    {
                        Equalizer = new FmodEqualizer(_fmodSys, _fmodChannel);
                    }
                    else
                    {
                        (Equalizer as FmodEqualizer).ReInit(_fmodSys, _fmodChannel);
                    }
                    MediaStateChanged?.Invoke(this, new MediaStateChangedEventArgs(PlayerState.Stopped));
                });

                return(true);
            }
            catch (Exception ex)
            {
                BLogger.E("An error occured while loading music. Action {action}", ex, LoadMusicAction.ToString());
                await InitializeSwitch.NotificationManager.ShowMessageAsync(ex.Message);

                return(false);
            }
        }
Example #8
0
        public async Task <bool> Load(Mediafile mediaFile)
        {
            if (mediaFile != null && mediaFile.Length != "00:00")
            {
                //tell all listeners that we are about to change media
                await InitializeCore.Dispatcher.RunAsync(() => { MediaChanging?.Invoke(this, new EventArgs()); });

                //stop currently playing track and free the channel
                await Stop();

                //create a stream of the new track
                Result loadResult = _fmodSys.CreateStream(mediaFile.Path, _isMobile ? Mode.LowMem & Mode.IgnoreTags : Mode.Default, out _fmodSound);

                //load the stream into the channel but don't play it yet.
                loadResult = _fmodSys.PlaySound(_fmodSound, null, true, out _fmodChannel);

                //this checks if looping is enabled and then sets the loop
                SetLoop();

                //START EXPERIMENT!
                //volume normalization code.
                //FMODSys.CreateDSPByType(Fmod.CoreDSP.DspType.NORMALIZE, out DSP dsp);

                //FMODChannel.addDSP(ChannelControlDspIndex.HEAD, dsp);

                //dsp.setParameterFloat((int)Fmod.CoreDSP.DspNormalize.THRESHHOLD, 1.0f);
                //dsp.setParameterFloat((int)Fmod.CoreDSP.DspNormalize.MAXAMP, 2.0f);

                //dsp.setActive(true);
                //END EXPERIMENT!

                //load equalizer
                if (Equalizer == null)
                {
                    Equalizer = new FmodEqualizer(_fmodSys, _fmodChannel);
                }
                else
                {
                    (Equalizer as FmodEqualizer).ReInit(_fmodSys, _fmodChannel);
                }

                //get and update length of the track.
                Length = TimeSpan.FromMilliseconds(_fmodSound.LengthInMilliseconds).TotalSeconds;

                //set the channel callback for all the syncpoints
                loadResult = _fmodChannel.SetCallback(_channelEndCallback);

                //add all the sync points
                //1. when song ends
                loadResult = _fmodSound.AddSyncPoint(_fmodSound.LengthInMilliseconds, TimeUnit.Ms, "songended", out _endSyncPoint);

                //2. when song has reached the last 15 seconds
                loadResult = _fmodSound.AddSyncPoint(_fmodSound.LengthInMilliseconds - 15000, TimeUnit.Ms, "songabouttoended", out _last15SyncPoint);

                //3. when song has reached the last 5 seconds
                loadResult = _fmodSound.AddSyncPoint(_fmodSound.LengthInMilliseconds - 5000, TimeUnit.Ms, "fade", out _last5SyncPoint);

                //update the system once here so that
                //all the sync points and callbacks are saved and updated.
                loadResult = _fmodSys.Update();

                PlayerState          = PlayerState.Stopped;
                CurrentlyPlayingFile = mediaFile;

                //check if all was successful
                return(loadResult == Result.Ok);
            }
            string error = "The file " + mediaFile.OrginalFilename + " is either corrupt, incomplete or unavailable. \r\n\r\n Exception details: No data available.";

            if (IgnoreErrors)
            {
                await InitializeCore.NotificationManager.ShowMessageAsync(error);
            }
            else
            {
                await InitializeCore.NotificationManager.ShowMessageBoxAsync(error, "File corrupt");
            }
            return(false);
        }
 public Channel PlaySound(Sound sound)
 {
     return(FmodSystem.PlaySound(sound.FModSound));
 }