public static extern bool BASS_FX_BPM_CallbackSet(int handle, BPMPROC proc, double period, int minMaxBPM, BASSFXBpm flags, IntPtr user);
/// <summary> /// Initializes the player. /// </summary> /// <param name="device">Device output</param> /// <param name="mixerSampleRate">Mixer sample rate (default: 44100 Hz)</param> /// <param name="bufferSize">Buffer size (default: 500 ms)</param> /// <param name="updatePeriod">Update period (default: 10 ms)</param> /// <param name="initializeDevice">Indicates if the device should be initialized</param> private void Initialize(Device device, int mixerSampleRate, int bufferSize, int updatePeriod, bool initializeDevice) { OnPlaylistEnded += () => { }; Player.CurrentPlayer = this; _device = device; _mixerSampleRate = mixerSampleRate; _bufferSize = bufferSize; _updatePeriod = updatePeriod; //_decodingService = new DecodingService(100000, UseFloatingPoint); _playlist = new ShufflePlaylist(); _syncProcs = new List<PlayerSyncProc>(); #if !ANDROID _useFloatingPoint = true; #endif _timerPlayer = new System.Timers.Timer(); _timerPlayer.Elapsed += new System.Timers.ElapsedEventHandler(timerPlayer_Elapsed); _timerPlayer.Interval = 1000; _timerPlayer.Enabled = false; // Initialize BASS library by OS type if (OS.Type == OSType.Windows) { // Load decoding plugins //plugins = Base.LoadPluginDirectory(Path.GetDirectoryName((new Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath)); Tracing.Log("Player init -- Loading plugins..."); //aacPluginHandle = Base.LoadPlugin("bass_aac.dll"); _apePluginHandle = Base.LoadPlugin("bass_ape.dll"); _flacPluginHandle = Base.LoadPlugin("bassflac.dll"); _mpcPluginHandle = Base.LoadPlugin("bass_mpc.dll"); //ofrPluginHandle = Base.LoadPlugin("bass_ofr.dll"); // Requires OptimFrog.DLL //ttaPluginHandle = Base.LoadPlugin("bass_tta.dll"); _wmaPluginHandle = Base.LoadPlugin("basswma.dll"); _wvPluginHandle = Base.LoadPlugin("basswv.dll"); int bassFxVersion = Base.GetFxPluginVersion(); int bassEncVersion = BaseEnc.GetVersion(); //Base.LoadFxPlugin(); } else // Linux or Mac OS X { // Load BASS library Tracing.Log("Player init -- Checking BASS library and plugin versions..."); int bassVersion = Base.GetBASSVersion(); int bassFxVersion = Base.GetFxPluginVersion(); int bassMixVersion = Base.GetMixPluginVersion(); int bassEncVersion = BaseEnc.GetVersion(); Tracing.Log("Player init -- BASS Version: " + bassVersion); Tracing.Log("Player init -- BASS FX Version: " + bassFxVersion); Tracing.Log("Player init -- BASS Mix Version: " + bassMixVersion); Tracing.Log("Player init -- BASS Enc Version: " + bassEncVersion); // Check OS type Console.WriteLine("Player init -- OS is " + OS.Type.ToString()); if (OS.Type == OSType.Linux) { string pluginPath = string.Empty; #if ANDROID pluginPath = PluginDirectoryPath; _aacPluginHandle = Base.LoadPlugin(Path.Combine(pluginPath, "libbass_aac.so")); _alacPluginHandle = Base.LoadPlugin(Path.Combine(pluginPath, "libbass_alac.so")); _apePluginHandle = Base.LoadPlugin(Path.Combine(pluginPath, "libbass_ape.so")); _mpcPluginHandle = Base.LoadPlugin(Path.Combine(pluginPath, "libbass_mpc.so")); _flacPluginHandle = Base.LoadPlugin(Path.Combine(pluginPath, "libbassflac.so")); _wvPluginHandle = Base.LoadPlugin(Path.Combine(pluginPath, "libbasswv.so")); #else // Find plugins either in current directory (i.e. development) or in a system directory (ex: /usr/lib/Sessions or /opt/lib/Sessions) string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); // Check in the current directory first if(!File.Exists(exePath + "/libbassflac.so")) { // Check in /usr/lib/Sessions if(!File.Exists("/usr/lib/Sessions/libbassflac.so")) { // Check in /opt/lib/Sessions if(!File.Exists("/opt/lib/Sessions/libbassflac.so")) { // The plugins could not be found! throw new Exception("The BASS plugins could not be found either in the current directory, in /usr/lib/Sessions or in /opt/lib/Sessions!"); } else { pluginPath = "/opt/lib/Sessions"; } } else { pluginPath = "/usr/lib/Sessions"; } } else { pluginPath = exePath; } // Load decoding plugins _flacPluginHandle = Base.LoadPlugin(Path.Combine(pluginPath, "libbassflac.so")); _wvPluginHandle = Base.LoadPlugin(Path.Combine(pluginPath, "libbasswv.so")); _mpcPluginHandle = Base.LoadPlugin(Path.Combine(pluginPath, "libbass_mpc.so")); #endif } else if (OS.Type == OSType.MacOSX) { #if IOS // Load decoding plugins (http://www.un4seen.com/forum/?topic=13851.msg96559#msg96559) _flacPluginHandle = Base.LoadPlugin("BASSFLAC"); _wvPluginHandle = Base.LoadPlugin("BASSWV"); _apePluginHandle = Base.LoadPlugin("BASS_APE"); _mpcPluginHandle = Base.LoadPlugin("BASS_MPC"); int bassEncVersionOSX = BaseEnc.GetVersion(); Console.WriteLine("Player init -- Configuring IOSNOTIFY delegate..."); _iosNotifyProc = new IOSNOTIFYPROC(IOSNotifyProc); IntPtr ptr = Marshal.GetFunctionPointerForDelegate(_iosNotifyProc); Bass.BASS_SetConfigPtr((BASSConfig)46, ptr); //Bass.BASS_SetConfigPtr(BASSIOSConfig.BASS_CONFIG_IOS_NOTIFY, ptr); Console.WriteLine("Player init -- Configuring AirPlay and remote control..."); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_IOS_MIXAUDIO, 0); // 0 = AirPlay #else // Try to get the plugins in the current path Console.WriteLine("Loading OS X plugins..."); string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string pluginPath = exePath.Replace("MonoBundle", "Resources"); // Check in the current directory first if(!File.Exists(pluginPath + "/libbassflac.dylib")) { // The plugins could not be found! throw new Exception("The BASS plugins could not be found in the current directory!"); } // Load decoding plugins _flacPluginHandle = Base.LoadPlugin(pluginPath + "/libbassflac.dylib"); _wvPluginHandle = Base.LoadPlugin(pluginPath + "/libbasswv.dylib"); _mpcPluginHandle = Base.LoadPlugin(pluginPath + "/libbass_mpc.dylib"); _apePluginHandle = Base.LoadPlugin(pluginPath + "/libbass_ape.dylib"); _ttaPluginHandle = Base.LoadPlugin(pluginPath + "/libbass_tta.dylib"); int bassEncVersion2 = BaseEnc.GetVersion(); //Console.WriteLine("OSX Bassenc.dylib version: {0}", bassEncVersion); #endif } } #if IOS _bpmProc = new BPMPROC(BPMDetectionProcIOS); //bpmBeatProc = new BPMBEATPROC(BPMDetectionBeatProcIOS); #else _bpmProc = new BPMPROC(BPMDetectionProc); //bpmBeatProc = new BPMBEATPROC(BPMDetectionBeatProc); #endif // Create default EQ Tracing.Log("Player init -- Creating default EQ preset..."); _currentEQPreset = new EQPreset(); if (initializeDevice) { Tracing.Log("Player init -- Initializing device..."); InitializeDevice(device, mixerSampleRate); } }
public bool OpenFile(string path) { Stop(); if (ActiveStreamHandle != 0) { ClearRepeatRange(); ChannelPosition = 0; Bass.BASS_StreamFree(ActiveStreamHandle); } if (System.IO.File.Exists(path)) { // Create Stream FileStreamHandle = ActiveStreamHandle = Bass.BASS_StreamCreateFile(path, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN); int streamFX = BassFx.BASS_FX_TempoCreate(FileStreamHandle, BASSFlag.BASS_FX_FREESOURCE); ChannelLength = Bass.BASS_ChannelBytes2Seconds(FileStreamHandle, Bass.BASS_ChannelGetLength(FileStreamHandle, 0)); FileTag = TagLib.File.Create(path); GenerateWaveformData(path); if (ActiveStreamHandle != 0) { _bpmProc = new BPMPROC(MyBPMProc); BassFx.BASS_FX_BPM_CallbackSet(ActiveStreamHandle, _bpmProc, 1.0, Utils.MakeLong(45, 240), BASSFXBpm.BASS_FX_BPM_MULT2, IntPtr.Zero); initEqualizer(); // Obtain the sample rate of the stream BASS_CHANNELINFO info = new BASS_CHANNELINFO(); Bass.BASS_ChannelGetInfo(ActiveStreamHandle, info); sampleFrequency = info.freq; // Set the stream to call Stop() when it ends. int syncHandle = Bass.BASS_ChannelSetSync(ActiveStreamHandle, BASSSync.BASS_SYNC_END, 0, endTrackSyncProc, IntPtr.Zero); if (syncHandle == 0) throw new ArgumentException("Error establishing End Sync on file stream.", "path"); CanPlay = true; return true; } else { ActiveStreamHandle = 0; FileTag = null; CanPlay = false; } } return false; }
public static void BPM_CallbackSet(int handle, BPMPROC proc, double period, int minMaxBPM, BASSFXBpm flags, IntPtr user) { if(!BassFx.BASS_FX_BPM_CallbackSet(handle, proc, period, minMaxBPM, flags, user)) Base.CheckForError(); }