예제 #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));
 }