/// <summary>
        ///     Removes and audio stream from a mixer.
        /// </summary>
        /// <param name="audioStream">The audio stream.</param>
        /// <param name="mixerChannel">The mixer channel.</param>
        public static void RemoveFromMixer(AudioStream audioStream, MixerChannel mixerChannel)
        {
            if (audioStream == null || !audioStream.IsAudioLoaded())
            {
                return;
            }

            //throw new Exception("Audio file null or not audio not loaded");

            if (mixerChannel.ChannelId == int.MinValue)
            {
                throw new Exception("Mixer channel not initialized");
            }

            //lock (Lock)
            {
                // DebugHelper.WriteLine($"RemoveFromMixer {audioStream.Description} {audioStream.Channel}...");
                BassMix.BASS_Mixer_ChannelPause(audioStream.ChannelId);
                Bass.BASS_ChannelLock(mixerChannel.ChannelId, true);

                foreach (var channel in audioStream.ChannelIds)
                {
                    BassMix.BASS_Mixer_ChannelRemove(channel);
                }

                Bass.BASS_ChannelLock(mixerChannel.ChannelId, false);
                // DebugHelper.WriteLine("done");


                if (audioStream.MixerChannelId == mixerChannel.ChannelId)
                {
                    audioStream.MixerChannelId = int.MinValue;
                }
            }
        }
Пример #2
0
        public EffectPlugin ReplacePlugin(string pluginPath, MixerChannel channel, Action <Exception> onError, EffectPlugin oldPlugin)
        {
            int idx = Plugins.IndexOf(oldPlugin ?? throw new ArgumentNullException(nameof(oldPlugin)));

            try
            {
                EffectPlugin plugin = new EffectPlugin(pluginPath)
                {
                    EffectMix = oldPlugin.EffectMix
                };

                RemovePlugin(oldPlugin);

                lock (((ICollection)Plugins).SyncRoot)
                {
                    Plugins.Insert(idx, plugin);
                }

                return(plugin);
            }
            catch (Exception e)
            {
                onError?.Invoke(e);

                return(null);
            }
        }
Пример #3
0
 public static bool Contains(MixerChannel channel)
 {
     if (channel == null)
     {
         return(false);
     }
     return(channels.Contains(channel));
 }
        public SyncedSamplePlayer(Channel speakerOutput, Channel monitorOutput)
        {
            _mixer = new MixerChannel(this);

            _mainPlayer = new AudioPlayer();
            _mixer.AddInputChannel(_mainPlayer.Output);

            _outputSplitter = new OutputSplitter(_mixer, speakerOutput, monitorOutput);
        }
Пример #5
0
        public ModulePlayer(string libraryFolder = "")
        {
            Output      = new MixerChannel(this);
            _mainPlayer = new AudioPlayer();

            _libraryFolder = libraryFolder;

            Output.AddInputChannel(_mainPlayer.Output);
        }
        /// <summary>
        ///     Initialises the raw loop mixer.
        /// </summary>
        private void InitialiseRawLoopMixer()
        {
            // DebugHelper.WriteLine("InitialiseRawLoopMixer");

            _rawLoopMixer          = new MixerChannel(this, MixerChannelOutputType.MultipleOutputs);
            _rawLoopOutputSplitter = new OutputSplitter(_rawLoopMixer, SpeakerOutput, MonitorOutput);

            // DebugHelper.WriteLine("END InitialiseRawLoopMixer");
        }
Пример #7
0
 public static void AddChannel(MixerChannel channel)
 {
     lock (lockObj)
     {
         if (!Contains(channel))
         {
             channels.Add(channel);
             MasterChannel.AddSource(channel);
         }
     }
 }
Пример #8
0
 public static void RemoveChannel(MixerChannel channel)
 {
     lock (lockObj)
     {
         if (Contains(channel))
         {
             channels.Remove(channel);
             MasterChannel.RemoveSource(channel);
         }
     }
 }
Пример #9
0
        public Mixer(int channelCount)
        {
            output = new WasapiOut()
            {
                Latency = 4
            };
            MasterChannel = new MixerChannel("Master", channelCount, output.Device.DeviceFormat.SampleRate);

            var w = new MixerChannelToCSCore(MasterChannel).ToWaveSource();

            output.Initialize(w);
            output.Play();
        }
        private void InitialiseSampler()
        {
            // DebugHelper.WriteLine("InitialiseSampler");

            // create mixer channel
            _samplerMixer = new MixerChannel(this);
            _samplerMixer.SetVolume((decimal)DefaultFadeOutStartVolume);
            _samplerMixer.CutBass();
            _samplerOutputSplitter = new OutputSplitter(_samplerMixer, SpeakerOutput, MonitorOutput);

            _samplePlayer = new TrackSamplePlayer(this);
            _samplerMixer.AddInputChannel(_samplePlayer.Output);

            _samplerMixer.SetVolume(50);

            // DebugHelper.WriteLine("END InitialiseSampler");
        }
Пример #11
0
        public EffectPlugin AddPlugin(string pluginPath, MixerChannel channel, Action <Exception> onError)
        {
            try
            {
                EffectPlugin plugin = new EffectPlugin(pluginPath);

                lock (((ICollection)Plugins).SyncRoot)
                {
                    Plugins.Add(plugin);
                }

                return(plugin);
            }
            catch (Exception e)
            {
                onError?.Invoke(e);

                return(null);
            }
        }
        /// <summary>
        ///     Adds an audio stream to a mixer
        /// </summary>
        /// <param name="audioStream">The audio stream.</param>
        /// <param name="mixerChannel">The mixer channel.</param>
        public static void AddToMixer(AudioStream audioStream, MixerChannel mixerChannel)
        {
            if (audioStream == null || !audioStream.IsAudioLoaded())
            {
                throw new Exception("Audio file null or not audio not loaded");
            }

            if (mixerChannel.ChannelId == int.MinValue)
            {
                throw new Exception("Mixer channel not initialized");
            }

            // DebugHelper.WriteLine($"AddToMixer {audioStream.Description} {mixerChannel} {audioStream.Channel}...");

            BassMix.BASS_Mixer_StreamAddChannel(mixerChannel.ChannelId, audioStream.ChannelId,
                                                BASSFlag.BASS_MIXER_PAUSE | BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_MIXER_NORAMPIN |
                                                BASSFlag.BASS_MUSIC_AUTOFREE);
            Thread.Sleep(1);

            audioStream.MixerChannelId = mixerChannel.ChannelId;

            // DebugHelper.WriteLine("done");
        }
Пример #13
0
 public AudioPlayer(IBmpProvider bpmProvider = null)
 {
     Output          = new MixerChannel(bpmProvider);
     _streamSections = new List <AudioStreamSection>();
 }