Пример #1
0
 public static void PlayChannel(this BassHandle handle, bool restart = false)
 {
     if (!handle.BASS_ChannelPlay(restart))
     {
         throw new BassException("ChannelPlay failed");
     }
 }
Пример #2
0
 public static void SetChannelAttribute(this BassHandle handle, ChannelAttribute attribute, float value)
 {
     if (!handle.BASS_ChannelSetAttribute(attribute, value))
     {
         throw new BassException("ChannelSetAttribute failed");
     }
 }
Пример #3
0
 public static void StopChannel(this BassHandle handle)
 {
     if (!handle.BASS_ChannelStop())
     {
         throw new BassException("ChannelStop failed");
     }
 }
Пример #4
0
 public static void PauseChannel(this BassHandle handle)
 {
     if (!handle.BASS_ChannelPause())
     {
         throw new BassException("ChannelPause failed");
     }
 }
Пример #5
0
 public static void FreeStream(this BassHandle handle)
 {
     if (!handle.BASS_StreamFree())
     {
         throw new BassException("StreamFree failed");
     }
 }
Пример #6
0
        public static float GetChannelAttribute(this BassHandle handle, ChannelAttribute attribute)
        {
            if (!handle.BASS_ChannelGetAttribute(attribute, out var value))
            {
                throw new BassException("ChannelGetAttribute failed");
            }

            return(value);
        }
Пример #7
0
 private static extern ChannelStatus BASS_ChannelIsActive(this BassHandle handle);
Пример #8
0
 private static extern bool BASS_ChannelStop(this BassHandle handle);
Пример #9
0
 private static extern bool BASS_ChannelPause(this BassHandle handle);
Пример #10
0
 private static extern bool BASS_ChannelPlay(this BassHandle handle, bool restart = false);
Пример #11
0
 private static extern bool BASS_StreamFree(this BassHandle handle);
Пример #12
0
 private static extern double BASS_ChannelBytes2Seconds(this BassHandle handle, ulong position);
Пример #13
0
 public static ulong GetChannelPosition(this BassHandle handle, LengthMode mode)
 {
     return(handle.BASS_ChannelGetPosition(mode));
 }
Пример #14
0
 public static ulong GetChannelLength(this BassHandle handle, LengthMode mode)
 {
     return(handle.BASS_ChannelGetLength(mode));
 }
Пример #15
0
 private static extern ulong BASS_ChannelGetPosition(this BassHandle handle, LengthMode mode);
Пример #16
0
 private static extern bool BASS_ChannelSetAttribute(this BassHandle handle, ChannelAttribute attribute, float value);
Пример #17
0
 public static ChannelStatus GetChannelStatus(this BassHandle handle)
 {
     return(handle.BASS_ChannelIsActive());
 }
Пример #18
0
        public static unsafe void Initialize(int device = -1, uint frequency = 44000, IntPtr windowHandle = default)
        {
            lock (LoadLock)
            {
                Log.Information($"Loading Bass version {BASS_GetVersion()}");

#if WINDOWS
                const string filter = "*." + Arch + ".dll";
#elif LINUX
                const string filter = "*." + Arch + ".so";
#elif OSX
                const string filter = "*." + Arch + ".dylib";
#endif

                foreach (var file in Directory.EnumerateFiles("BassPlugins", filter, SearchOption.AllDirectories))
                {
                    var path   = Path.GetFullPath(file);
                    var handle = BASS_PluginLoad(path, PluginUnicodeFlag);
                    if (handle == 0)
                    {
                        throw new BassException($"Loading {path} as plugin failed");
                    }
                    var infoPtr = BASS_PluginGetInfo(handle);
                    if (infoPtr == null)
                    {
                        throw new BassException($"Getting plugin info for {path} failed");
                    }
                    var info = *infoPtr;
                    Log.Information($"Loaded Bass plugin {Path.GetFileNameWithoutExtension(path)} version {info.version}. Supported formats: {string.Join(", ", ListSupportedFormats(info))}");
                }

#if WINDOWS
                if (windowHandle == IntPtr.Zero)
                {
                    windowHandle = GetActiveWindow();
                }
#endif

                if (!BASS_Init(device, frequency, 0, windowHandle, IntPtr.Zero))
                {
                    throw new BassException("Init failed");
                }

                if (BASS_GetConfig(BassConfig.Float) == 0)
                {
                    _floatFlag = StreamFlags.None;
                }
                else
                {
                    BassHandle floatable = BASS_StreamCreate(44100, 1, StreamFlags.SampleFloat, IntPtr.Zero, IntPtr.Zero); // try creating a floating-point stream
                    if (floatable != BassHandle.Null)
                    {
                        BASS_StreamFree(floatable); // floating-point channels are supported (free the test stream)
                        _floatFlag = StreamFlags.SampleFloat;
                    }
                    else
                    {
                        _floatFlag = StreamFlags.None;
                    }
                }

                if (_floatFlag.HasFlag(StreamFlags.SampleFloat))
                {
                    Log.Information("Enabling floating point data output");
                }


                Log.Information($"Setting useragent to {WebHelper.UserAgent}");
                BASS_SetConfigPtr(BassConfig.NetAgent, WebHelper.UserAgent);

                Log.Information("Bass initialization complete");
            }
        }
Пример #19
0
 public static double ConvertBytesToSeconds(this BassHandle handle, ulong position)
 {
     return(handle.BASS_ChannelBytes2Seconds(position));
 }