Exemplo n.º 1
0
        public static void Detect(int device, bool exclusive, bool autoFormat, float bufferLength, bool doubleBuffer, bool eventDriven, bool async, bool dither, bool raw)
        {
            if (IsInitialized)
            {
                throw new InvalidOperationException("Device is already initialized.");
            }

            IsInitialized = true;

            Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detecting WASAPI device.");

            try
            {
                var flags = GetFlags(exclusive, autoFormat, doubleBuffer, eventDriven, async, dither, raw);
                BassUtils.OK(
                    BassWasapiHandler.Init(
                        device,
                        0,
                        0,
                        flags,
                        Buffer: bufferLength
                        )
                    );
                Update(device, flags);
                Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Inputs => {1}, Outputs = {2}, Rate = {3}, Format = {4}", BassWasapi.CurrentDevice, Info.Inputs, Info.Outputs, Info.Rate, Enum.GetName(typeof(WasapiFormat), Info.Format));
                Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Rates => {1}", BassWasapi.CurrentDevice, string.Join(", ", Info.SupportedRates));
            }
            finally
            {
                Free();
            }
        }
Exemplo n.º 2
0
        public static void Init(int device, bool exclusive, bool autoFormat, bool buffer, bool eventDriven, bool dither, int frequency, int channels, BassFlags flags)
        {
            if (IsInitialized)
            {
                throw new InvalidOperationException("Device is already initialized.");
            }

            IsInitialized = true;

            LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Initializing BASS WASAPI.");

            try
            {
                BassUtils.OK(
                    BassWasapiHandler.Init(
                        device,
                        frequency,
                        channels,
                        GetFlags(exclusive, autoFormat, buffer, eventDriven, dither)
                        )
                    );

                LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Initialized BASS WASAPI.");
            }
            catch
            {
                Free();
                throw;
            }
        }
Exemplo n.º 3
0
        public static void Init(int device, bool exclusive, bool eventDriven, bool dither, int frequency = 0, int channels = 0)
        {
            LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Initializing BASS WASAPI.");
            var flags = WasapiInitFlags.Shared;

            if (exclusive)
            {
                flags |= WasapiInitFlags.Exclusive;
            }
            if (eventDriven)
            {
                flags |= WasapiInitFlags.EventDriven;
            }
            if (dither)
            {
                flags |= WasapiInitFlags.Dither;
            }
            BassUtils.OK(BassWasapiHandler.Init(device, frequency, channels, flags, 0, 0));
            IsInitialized = true;
            Device        = device;
            Exclusive     = exclusive;
            EventDriven   = eventDriven;
            var exception = default(Exception);

            for (var a = 1; a <= INIT_ATTEMPTS; a++)
            {
                LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detecting WASAPI device, attempt: {0}", a);
                try
                {
                    var deviceInfo = default(WasapiDeviceInfo);
                    BassUtils.OK(BassWasapi.GetDeviceInfo(device, out deviceInfo));
                    Devices[device] = new BassWasapiDeviceInfo(
                        deviceInfo.MixFrequency,
                        0,
                        deviceInfo.MixChannels,
                        GetSupportedFormats(device, flags),
                        BassWasapi.CheckFormat(device, deviceInfo.MixFrequency, deviceInfo.MixChannels, flags)
                        );
                    LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Inputs => {1}, Outputs = {2}, Rate = {3}, Format = {4}", Device, Devices[device].Inputs, Info.Outputs, Info.Rate, Enum.GetName(typeof(WasapiFormat), Info.Format));
                    LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Rates => {1}", Device, string.Join(", ", Devices[device].SupportedRates));
                    return;
                }
                catch (Exception e)
                {
                    exception = e;
                    LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Warn, "Failed to detect WASAPI device: {0}", e.Message);
                }
                Thread.Sleep(INIT_ATTEMPT_INTERVAL);
            }
            if (exception != null)
            {
                Free();
                throw exception;
            }
            throw new NotImplementedException();
        }
Exemplo n.º 4
0
 public static void Free()
 {
     if (!IsInitialized)
     {
         return;
     }
     Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Releasing BASS WASAPI.");
     BassWasapi.Free();
     BassWasapiHandler.Free();
     IsInitialized = false;
 }
Exemplo n.º 5
0
        public static void Detect(int device, bool exclusive, bool autoFormat, bool buffer, bool eventDriven, bool dither)
        {
            if (IsInitialized)
            {
                throw new InvalidOperationException("Device is already initialized.");
            }

            IsInitialized = true;

            LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detecting WASAPI device.");

            try
            {
                var flags = GetFlags(exclusive, autoFormat, buffer, eventDriven, dither);
                BassUtils.OK(
                    BassWasapiHandler.Init(
                        device,
                        0,
                        0,
                        flags
                        )
                    );
                var deviceInfo = default(WasapiDeviceInfo);
                BassUtils.OK(BassWasapi.GetDeviceInfo(BassWasapi.CurrentDevice, out deviceInfo));
                Info = new BassWasapiDeviceInfo(
                    BassWasapi.CurrentDevice,
                    deviceInfo.MixFrequency,
                    0,
                    deviceInfo.MixChannels,
                    GetSupportedFormats(
                        BassWasapi.CurrentDevice,
                        flags
                        ),
                    BassWasapi.CheckFormat(
                        BassWasapi.CurrentDevice,
                        deviceInfo.MixFrequency,
                        deviceInfo.MixChannels,
                        flags
                        ),
                    device == BassWasapi.DefaultDevice
                    );

                LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Inputs => {1}, Outputs = {2}, Rate = {3}, Format = {4}", BassWasapi.CurrentDevice, Info.Inputs, Info.Outputs, Info.Rate, Enum.GetName(typeof(WasapiFormat), Info.Format));
                LogManager.Logger.Write(typeof(BassWasapiDevice), LogLevel.Debug, "Detected WASAPI device: {0} => Rates => {1}", BassWasapi.CurrentDevice, string.Join(", ", Info.SupportedRates));
            }
            finally
            {
                Free();
            }
        }
Exemplo n.º 6
0
 public override void Connect(IBassStreamComponent previous)
 {
     this.ConfigureWASAPI(previous);
     if (this.ShouldCreateMixer(previous))
     {
         Logger.Write(this, LogLevel.Debug, "Creating BASS MIX stream with rate {0} and {1} channels.", this.Rate, this.Channels);
         this.ChannelHandle = BassMix.CreateMixerStream(this.Rate, this.Channels, this.Flags);
         if (this.ChannelHandle == 0)
         {
             BassUtils.Throw();
         }
         Logger.Write(this, LogLevel.Debug, "Adding stream to the mixer: {0}", previous.ChannelHandle);
         BassUtils.OK(BassMix.MixerAddChannel(this.ChannelHandle, previous.ChannelHandle, BassFlags.Default | BassFlags.MixerBuffer));
         BassUtils.OK(BassWasapiHandler.StreamSet(this.ChannelHandle));
         this.MixerChannelHandles.Add(previous.ChannelHandle);
     }
     else
     {
         Logger.Write(this, LogLevel.Debug, "The stream properties match the device, playing directly.");
         BassUtils.OK(BassWasapiHandler.StreamSet(previous.ChannelHandle));
     }
 }