public static void PlayChannel(this BassHandle handle, bool restart = false) { if (!handle.BASS_ChannelPlay(restart)) { throw new BassException("ChannelPlay failed"); } }
public static void SetChannelAttribute(this BassHandle handle, ChannelAttribute attribute, float value) { if (!handle.BASS_ChannelSetAttribute(attribute, value)) { throw new BassException("ChannelSetAttribute failed"); } }
public static void StopChannel(this BassHandle handle) { if (!handle.BASS_ChannelStop()) { throw new BassException("ChannelStop failed"); } }
public static void PauseChannel(this BassHandle handle) { if (!handle.BASS_ChannelPause()) { throw new BassException("ChannelPause failed"); } }
public static void FreeStream(this BassHandle handle) { if (!handle.BASS_StreamFree()) { throw new BassException("StreamFree failed"); } }
public static float GetChannelAttribute(this BassHandle handle, ChannelAttribute attribute) { if (!handle.BASS_ChannelGetAttribute(attribute, out var value)) { throw new BassException("ChannelGetAttribute failed"); } return(value); }
private static extern ChannelStatus BASS_ChannelIsActive(this BassHandle handle);
private static extern bool BASS_ChannelStop(this BassHandle handle);
private static extern bool BASS_ChannelPause(this BassHandle handle);
private static extern bool BASS_ChannelPlay(this BassHandle handle, bool restart = false);
private static extern bool BASS_StreamFree(this BassHandle handle);
private static extern double BASS_ChannelBytes2Seconds(this BassHandle handle, ulong position);
public static ulong GetChannelPosition(this BassHandle handle, LengthMode mode) { return(handle.BASS_ChannelGetPosition(mode)); }
public static ulong GetChannelLength(this BassHandle handle, LengthMode mode) { return(handle.BASS_ChannelGetLength(mode)); }
private static extern ulong BASS_ChannelGetPosition(this BassHandle handle, LengthMode mode);
private static extern bool BASS_ChannelSetAttribute(this BassHandle handle, ChannelAttribute attribute, float value);
public static ChannelStatus GetChannelStatus(this BassHandle handle) { return(handle.BASS_ChannelIsActive()); }
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"); } }
public static double ConvertBytesToSeconds(this BassHandle handle, ulong position) { return(handle.BASS_ChannelBytes2Seconds(position)); }