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;
            }
        }
Beispiel #2
0
        private static void Update(int device, WasapiInitFlags flags)
        {
            var info       = default(WasapiInfo);
            var deviceInfo = default(WasapiDeviceInfo);

            BassUtils.OK(BassWasapi.GetInfo(out info));
            BassUtils.OK(BassWasapi.GetDeviceInfo(BassWasapi.CurrentDevice, out deviceInfo));
            Info = new BassWasapiDeviceInfo(
                BassWasapi.CurrentDevice,
                deviceInfo.MixFrequency,
                0,
                deviceInfo.MixChannels,
                info.BufferLength,
                GetSupportedFormats(
                    BassWasapi.CurrentDevice,
                    flags
                    ),
                BassWasapi.CheckFormat(
                    BassWasapi.CurrentDevice,
                    deviceInfo.MixFrequency,
                    deviceInfo.MixChannels,
                    flags
                    ),
                device == BassWasapi.DefaultDevice
                );
        }
 public override bool Add(BassOutputStream stream)
 {
     if (this.Queue.Contains(stream.ChannelHandle))
     {
         Logger.Write(this, LogLevel.Debug, "Stream is already enqueued: {0}", stream.ChannelHandle);
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Adding stream to the queue: {0}", stream.ChannelHandle);
     //If there's nothing in the queue then we're starting.
     if (this.Queue.Count() == 0)
     {
         var flags = default(BassCrossfadeFlags);
         if (this.Behaviour.Start)
         {
             flags = BassCrossfadeFlags.FadeIn;
         }
         else
         {
             flags = BassCrossfadeFlags.None;
         }
         BassUtils.OK(BassCrossfade.ChannelEnqueue(stream.ChannelHandle, flags));
         return(true);
     }
     BassUtils.OK(BassCrossfade.ChannelEnqueue(stream.ChannelHandle));
     return(true);
 }
 protected override void OnDisposing()
 {
     if (BassWasapi.IsStarted)
     {
         BassUtils.OK(this.StopWASAPI(true));
     }
 }
Beispiel #5
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();
            }
        }
Beispiel #6
0
            private async Task AddOrUpdateMetaData()
            {
                Logger.Write(this, LogLevel.Debug, "Fetching meta data for new playlist items.");
                using (var transaction = this.Database.BeginTransaction(this.Database.PreferredIsolationLevel))
                {
                    var query = this.Database
                                .AsQueryable <PlaylistItem>(this.Database.Source(new DatabaseQueryComposer <PlaylistItem>(this.Database), transaction))
                                .Where(playlistItem => playlistItem.Status == PlaylistItemStatus.Import);
                    var info = default(CDInfo);
                    BassUtils.OK(BassCd.GetInfo(this.Drive, out info));
                    using (var writer = new MetaDataWriter(this.Database, this.Database.Queries.AddPlaylistMetaDataItem, transaction))
                    {
                        foreach (var playlistItem in query)
                        {
                            var metaData = await this.MetaDataSource.GetMetaData(playlistItem.FileName).ConfigureAwait(false);

                            foreach (var metaDataItem in metaData)
                            {
                                await writer.Write(playlistItem.Id, metaDataItem).ConfigureAwait(false);
                            }
                        }
                    }
                    transaction.Commit();
                }
            }
Beispiel #7
0
 protected override void OnDisposing()
 {
     if (this.ChannelHandle != 0)
     {
         Logger.Write(this, LogLevel.Debug, "Freeing BASS SOX stream: {0}", this.ChannelHandle);
         BassUtils.OK(BassSox.StreamFree(this.ChannelHandle));
     }
 }
Beispiel #8
0
 protected override void OnDisposing()
 {
     if (this.ChannelHandle != 0)
     {
         this.Reset();
         Logger.Write(this, LogLevel.Debug, "Freeing BASS GAPLESS stream: {0}", this.ChannelHandle);
         BassUtils.OK(Bass.StreamFree(this.ChannelHandle));
     }
 }
Beispiel #9
0
 public static IEnumerable <string> GetDrives()
 {
     for (int a = 0, b = BassCd.DriveCount; a < b; a++)
     {
         var cdInfo = default(CDInfo);
         BassUtils.OK(BassCd.GetInfo(a, out cdInfo));
         yield return(GetDriveName(cdInfo));
     }
 }
Beispiel #10
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();
        }
 private static IEnumerable <SelectionConfigurationOption> GetDrives()
 {
     for (int a = 0, b = BassCd.DriveCount; a < b; a++)
     {
         var cdInfo = default(CDInfo);
         BassUtils.OK(BassCd.GetInfo(a, out cdInfo));
         LogManager.Logger.Write(typeof(BassCdStreamProviderBehaviourConfiguration), LogLevel.Debug, "CD Drive: {0} => {1} => {2}", a, cdInfo.Name, cdInfo.Manufacturer);
         yield return(new SelectionConfigurationOption(cdInfo.Name, string.Format("{0} ({1}:\\)", cdInfo.Name, cdInfo.DriveLetter), cdInfo.Name));
     }
 }
Beispiel #12
0
 protected virtual void OnInit(object sender, EventArgs e)
 {
     if (!this.Enabled)
     {
         return;
     }
     BassUtils.OK(BassSox.Init());
     this.IsInitialized = true;
     Logger.Write(this, LogLevel.Debug, "BASS SOX Initialized.");
 }
Beispiel #13
0
 protected virtual void Stop()
 {
     Logger.Write(this, LogLevel.Debug, "Tempo effect disabled.");
     BassUtils.OK(Bass.ChannelSetAttribute(this.ChannelHandle, ChannelAttribute.Tempo, 0));
     BassUtils.OK(Bass.ChannelSetAttribute(this.ChannelHandle, ChannelAttribute.Pitch, 0));
     BassUtils.OK(Bass.ChannelSetAttribute(this.ChannelHandle, ChannelAttribute.TempoFrequency, this.Rate));
     BassUtils.OK(Bass.ChannelSetAttribute(this.ChannelHandle, ChannelAttribute.TempoUseAAFilter, 1));
     BassUtils.OK(Bass.ChannelSetAttribute(this.ChannelHandle, ChannelAttribute.TempoAAFilterLength, 32));
     BassUtils.OK(Bass.ChannelSetAttribute(this.ChannelHandle, ChannelAttribute.TempoUseQuickAlgorithm, 0));
 }
 public override void Connect(IBassStreamComponent previous)
 {
     BassUtils.OK(BassGapless.SetConfig(BassGaplessAttriubute.KeepAlive, true));
     Logger.Write(this, LogLevel.Debug, "Creating BASS GAPLESS stream with rate {0} and {1} channels.", this.Rate, this.Channels);
     this.ChannelHandle = BassGapless.StreamCreate(this.Rate, this.Channels, this.Flags);
     if (this.ChannelHandle == 0)
     {
         BassUtils.Throw();
     }
 }
Beispiel #15
0
 protected virtual bool StartWASAPI()
 {
     if (BassWasapi.IsStarted)
     {
         Logger.Write(this, LogLevel.Debug, "WASAPI has already been started.");
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Starting WASAPI.");
     BassUtils.OK(BassWasapi.Start());
     return(true);
 }
 public override bool Add(BassOutputStream stream)
 {
     if (this.Queue.Contains(stream.ChannelHandle))
     {
         Logger.Write(this, LogLevel.Debug, "Stream is already enqueued: {0}", stream.ChannelHandle);
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Adding stream to the queue: {0}", stream.ChannelHandle);
     BassUtils.OK(BassGapless.ChannelEnqueue(stream.ChannelHandle));
     return(true);
 }
Beispiel #17
0
 protected virtual bool StopWASAPI(bool reset)
 {
     if (!BassWasapi.IsStarted)
     {
         Logger.Write(this, LogLevel.Debug, "WASAPI has not been started.");
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Stopping WASAPI.");
     BassUtils.OK(BassWasapi.Stop(reset));
     return(true);
 }
Beispiel #18
0
 protected virtual void OnInit(object sender, EventArgs e)
 {
     if (!this.Enabled)
     {
         return;
     }
     this.OnConfigure();
     BassUtils.OK(Bass.Init(this.DirectSoundDevice, this.Output.Rate));
     this.IsInitialized = true;
     Logger.Write(this, LogLevel.Debug, "BASS Initialized.");
 }
Beispiel #19
0
 public override bool Remove(int channelHandle)
 {
     if (!this.Queue.Contains(channelHandle))
     {
         Logger.Write(this, LogLevel.Debug, "Stream is not enqueued: {0}", channelHandle);
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Removing stream from the queue: {0}", channelHandle);
     BassUtils.OK(BassGapless.ChannelRemove(channelHandle));
     return(true);
 }
 protected override void OnDisposing()
 {
     if (this.ChannelHandle != 0)
     {
         Logger.Write(this, LogLevel.Debug, "Freeing BASS stream: {0}", this.ChannelHandle);
         BassUtils.OK(Bass.StreamFree(this.ChannelHandle)); //Not checking result code as it contains an error if the application is shutting down.
     }
     this.Stop();
     BassAsioDevice.Free();
     base.OnDisposing();
 }
 protected virtual bool StartASIO()
 {
     if (BassAsio.IsStarted)
     {
         Logger.Write(this, LogLevel.Debug, "ASIO has already been started.");
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Starting ASIO.");
     BassUtils.OK(BassAsio.Start(BassAsio.Info.PreferredBufferLength));
     return(true);
 }
 public override bool Remove(BassOutputStream stream, Action <BassOutputStream> callBack)
 {
     if (!this.Queue.Contains(stream.ChannelHandle))
     {
         Logger.Write(this, LogLevel.Debug, "Stream is not enqueued: {0}", stream.ChannelHandle);
         return(false);
     }
     Logger.Write(this, LogLevel.Debug, "Removing stream from the queue: {0}", stream.ChannelHandle);
     BassUtils.OK(BassGapless.ChannelRemove(stream.ChannelHandle));
     callBack(stream);
     return(true);
 }
Beispiel #23
0
 public override void Connect(IBassStreamComponent 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));
     this.MixerChannelHandles.Add(previous.ChannelHandle);
 }
Beispiel #24
0
 protected virtual void OnInit(object sender, EventArgs e)
 {
     if (!this.Enabled)
     {
         return;
     }
     BassUtils.OK(Bass.Configure(global::ManagedBass.Configuration.UpdateThreads, 0));
     BassUtils.OK(Bass.Configure(global::ManagedBass.Configuration.PlaybackBufferLength, this.Output.BufferLength));
     BassUtils.OK(Bass.Init(Bass.NoSoundDevice));
     this.IsInitialized = true;
     Logger.Write(this, LogLevel.Debug, "BASS (No Sound) Initialized.");
 }
Beispiel #25
0
 protected virtual void OnInit(object sender, EventArgs e)
 {
     if (!this.Enabled)
     {
         return;
     }
     this.IsInitialized = true;
     BassUtils.OK(Bass.Configure(global::ManagedBass.Configuration.UpdateThreads, 1));
     BassUtils.OK(Bass.Configure(global::ManagedBass.Configuration.PlaybackBufferLength, this.GetBufferLength()));
     BassUtils.OK(Bass.Configure(global::ManagedBass.Configuration.SRCQuality, this.Output.ResamplingQuality));
     BassUtils.OK(Bass.Init(this.DirectSoundDevice, this.Output.Rate));
     Logger.Write(this, LogLevel.Debug, "BASS Initialized.");
 }
 public static int GetDrive(SelectionConfigurationOption option)
 {
     for (int a = 0, b = BassCd.DriveCount; a < b; a++)
     {
         var cdInfo = default(CDInfo);
         BassUtils.OK(BassCd.GetInfo(a, out cdInfo));
         if (string.Equals(cdInfo.Name, option.Id, StringComparison.OrdinalIgnoreCase))
         {
             return(a);
         }
     }
     return(CD_NO_DRIVE);
 }
Beispiel #27
0
 public static int GetDrive(string name)
 {
     for (int a = 0, b = BassCd.DriveCount; a < b; a++)
     {
         var cdInfo = default(CDInfo);
         BassUtils.OK(BassCd.GetInfo(a, out cdInfo));
         if (string.Equals(GetDriveName(cdInfo), name, StringComparison.OrdinalIgnoreCase))
         {
             return(a);
         }
     }
     return(NO_DRIVE);
 }
Beispiel #28
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();
            }
        }
Beispiel #29
0
        private static IEnumerable <SelectionConfigurationOption> GetWASAPIDevices()
        {
            yield return(new SelectionConfigurationOption(BassWasapi.DefaultDevice.ToString(), "Default Device"));

            for (int a = 0, b = BassWasapi.DeviceCount; a < b; a++)
            {
                var deviceInfo = default(WasapiDeviceInfo);
                BassUtils.OK(BassWasapi.GetDeviceInfo(a, out deviceInfo));
                if (deviceInfo.IsInput || deviceInfo.IsDisabled || deviceInfo.IsLoopback || deviceInfo.IsUnplugged)
                {
                    continue;
                }
                LogManager.Logger.Write(typeof(BassWasapiStreamOutputConfiguration), LogLevel.Debug, "WASAPI Device: {0} => {1} => {2} => {3} => {4}", a, deviceInfo.ID, deviceInfo.Name, Enum.GetName(typeof(WasapiDeviceType), deviceInfo.Type), deviceInfo.MixFrequency);
                yield return(new SelectionConfigurationOption(deviceInfo.ID, deviceInfo.Name, string.Format("{0} ({1})", deviceInfo.Name, Enum.GetName(typeof(WasapiDeviceType), deviceInfo.Type))));
            }
        }
Beispiel #30
0
 public static int GetWasapiDevice(SelectionConfigurationOption option)
 {
     if (!string.Equals(option.Id, BassWasapi.DefaultDevice.ToString()))
     {
         for (int a = 0, b = BassWasapi.DeviceCount; a < b; a++)
         {
             var deviceInfo = default(WasapiDeviceInfo);
             BassUtils.OK(BassWasapi.GetDeviceInfo(a, out deviceInfo));
             if (string.Equals(deviceInfo.ID, option.Id, StringComparison.OrdinalIgnoreCase))
             {
                 return(a);
             }
         }
     }
     return(BassWasapi.DefaultDevice);
 }