/// <summary>
        /// Adds a Reference.
        /// </summary>
        public static void Add(int Handle, int SpecificHandle, object proc)
        {
#if !__IOS__
            if (proc == null)
            {
                return;
            }

            if (proc.Equals(Freeproc))
            {
                return;
            }

            var key = Tuple.Create(Handle, SpecificHandle);

            var contains = Procedures.ContainsKey(key);

            if (Freeproc != null && Procedures.All(pair => pair.Key.Item1 != Handle))
            {
                Bass.ChannelSetSync(Handle, SyncFlags.Free, 0, Freeproc);
            }

            if (contains)
            {
                Procedures[key] = proc;
            }
            else
            {
                Procedures.TryAdd(key, proc);
            }
#endif
        }
        public void Add(int Handle, int SpecificHandle, object proc)
        {
            if (proc.Equals(_freeproc))
            {
                return;
            }

            var key = Tuple.Create(Handle, SpecificHandle);

            var contains = _procedures.ContainsKey(key);

            if (proc == null)
            {
                if (contains)
                {
                    _procedures.Remove(key);
                }

                return;
            }

            if (_freeproc != null && !_procedures.Any(pair => pair.Key.Item1 == Handle))
            {
                Bass.ChannelSetSync(Handle, SyncFlags.Free, 0, _freeproc);
            }

            if (contains)
            {
                _procedures[key] = proc;
            }
            else
            {
                _procedures.Add(key, proc);
            }
        }
Exemple #3
0
        /// <summary>
        /// Applies the Effect on a <paramref name="Channel"/>.
        /// </summary>
        /// <param name="Channel">The Channel to apply the Effect on.</param>
        /// <param name="Priority">Priority of the Effect in DSP chain.</param>
        public void ApplyOn(int Channel, int Priority = 0)
        {
            _channel  = Channel;
            _priority = Priority;

            _gch = GCHandle.Alloc(Parameters, GCHandleType.Pinned);

            _hfsync = Bass.ChannelSetSync(Channel, SyncFlags.Free, 0, _syncProcedure);
        }
Exemple #4
0
        /// <summary>
        /// Applies the Effect on a <paramref name="Channel"/>.
        /// </summary>
        /// <param name="Channel">The Channel to apply the Effect on.</param>
        /// <param name="Priority">Priority of the Effect in DSP chain.</param>
        public void ApplyOn(int Channel, int Priority = 0)
        {
            _channel  = Channel;
            _priority = Priority;

            if (!_gch.IsAllocated)
            {
                _gch = GCHandle.Alloc(Parameters, GCHandleType.Pinned);
            }

            _hfsync = Bass.ChannelSetSync(Channel, SyncFlags.Free, 0, (a, b, c, d) => Dispose());
        }
Exemple #5
0
        /// <summary>Create a stream from Memory (byte[]).</summary>
        public static int CreateStream(byte[] Memory, long Offset, long Length, BassFlags Flags)
        {
            var GCPin = GCHandle.Alloc(Memory, GCHandleType.Pinned);

            var Handle = CreateStream(GCPin.AddrOfPinnedObject(), Offset, Length, Flags);

            if (Handle == 0)
            {
                GCPin.Free();
            }
            else
            {
                Bass.ChannelSetSync(Handle, SyncFlags.Free, 0, (a, b, c, d) => GCPin.Free());
            }

            return(Handle);
        }
        public NetworkDecoder(string Url, Resolution BufferKind = Resolution.Short, Action <BufferProvider> callback = null)
            : base(BufferKind)
        {
            this.Url = Url;

            if (callback != null)
            {
                call = callback;
                proc = new DownloadProcedure(Callback);
            }

            Down_Handler = new SyncProcedure(OnDownloadCompleted);

            Handle = Bass.CreateStream(Url, 0, BufferKind.ToBassFlag() | BassFlags.Decode | BassFlags.Unicode, (callback != null ? proc : null), IntPtr.Zero);

            Bass.ChannelSetSync(Handle, SyncFlags.Downloaded, 0, Down_Handler, IntPtr.Zero);
        }
Exemple #7
0
        /// <summary>
        /// Create Stream Helper method.
        /// </summary>
        /// <param name="Function">The Stream Creation function.</param>
        /// <param name="Memory">The <see cref="object"/> to pin and pass to <paramref name="Function"/>.</param>
        /// <returns>The Handle returned by <paramref name="Function"/>.</returns>
        public static int CreateStreamHelper(Func <IntPtr, int> Function, object Memory)
        {
            var GCPin = GCHandle.Alloc(Memory, GCHandleType.Pinned);

            var Handle = Function(GCPin.AddrOfPinnedObject());

            if (Handle == 0)
            {
                GCPin.Free();
            }
            else
            {
                Bass.ChannelSetSync(Handle, SyncFlags.Free, 0, (a, b, c, d) => GCPin.Free());
            }

            return(Handle);
        }
Exemple #8
0
        /// <summary>
        /// Applies the DSP on a Channel.
        /// </summary>
        /// <param name="Channel">Channel to apply the DSP on.</param>
        /// <param name="Priority">Priority of the DSP in the DSP chain.</param>
        public void ApplyOn(int Channel, int Priority = 0)
        {
            this.Channel = Channel;

            _priority = Priority;

            _handle = Bass.ChannelSetDSP(Channel, OnDsp, Priority: _priority);

            Resolution = Bass.ChannelGetInfo(Channel).Resolution;

            Bass.ChannelSetSync(Channel, SyncFlags.Free, 0, (a, b, c, d) => Dispose());

            if (_handle != 0)
            {
                IsAssigned = true;
            }
            else
            {
                throw new InvalidOperationException("DSP Assignment Failed");
            }
        }
Exemple #9
0
        /// <summary>
        /// Applies the Effect on a <see cref="MediaPlayer"/>.
        /// </summary>
        /// <param name="Player">The <see cref="MediaPlayer"/> to apply the Effect on.</param>
        /// <param name="Priority">Priority of the Effect in DSP chain.</param>
        public void ApplyOn(MediaPlayer Player, int Priority = 0)
        {
            ApplyOn(Player.Handle, Priority);

            _mediaPlayer = true;

            Player.MediaLoaded += NewHandle =>
            {
                if (_wasActive)
                {
                    IsActive = false;
                }

                Bass.ChannelRemoveSync(_channel, _hfsync);

                _channel = NewHandle;
                _hfsync  = Bass.ChannelSetSync(NewHandle, SyncFlags.Free, 0, _syncProcedure);

                IsActive = _wasActive;
            };
        }
Exemple #10
0
        /// <summary>
        /// Creates a new synchronizable instance of <see cref="RecordingProvider"/> to be used with an <see cref="IRecorder"/>.
        /// </summary>
        /// <param name="Device">The Recording Device.</param>
        /// <param name="Wf"><see cref="WaveFormat"/> to use.</param>
        /// <param name="FrameRate">The <see cref="IRecorder"/>'s FrameRate.</param>
        public RecordingProvider(RecordingDevice Device, WaveFormat Wf, int FrameRate)
        {
            WaveFormat = Wf;

            BASS.RecordInit(Device.DeviceIndex);

            BASS.CurrentRecordingDevice = Device.DeviceIndex;

            var flags = BassFlags.RecordPause;

            if (Wf.Encoding == WaveFormatEncoding.Float && Wf.BitsPerSample == 32)
            {
                flags |= BassFlags.Float;
            }

            else if (Wf.Encoding == WaveFormatEncoding.Pcm && Wf.BitsPerSample == 8)
            {
                flags |= BassFlags.Byte;
            }

            else if (!(Wf.Encoding == WaveFormatEncoding.Pcm && Wf.BitsPerSample == 16))
            {
                throw new ArgumentException(nameof(Wf));
            }

            IsSynchronizable = FrameRate != -1;

            if (IsSynchronizable)
            {
                BASS.RecordingBufferLength = 3000 / FrameRate;
            }

            _handle = IsSynchronizable ? BASS.RecordStart(Wf.SampleRate, Wf.Channels, flags, BASS.RecordingBufferLength / 3, Procedure, IntPtr.Zero)
                                      : BASS.RecordStart(Wf.SampleRate, Wf.Channels, flags, Procedure);

            BASS.ChannelSetSync(_handle, SyncFlags.Free, 0, (H, C, D, U) => RecordingStopped?.Invoke(this, new EndEventArgs(null)));
        }