/// <summary> /// Set Equalizer Settings /// </summary> /// <param name="frequencyList">10 Band Float list</param> public void setEqualizer(float[] frequencyList) { if (frequencyList == null) return; for (int i = 0; i < 10; i++) { _equalizerTmp[i] = frequencyList[i]; if (!_stopped &&_toggleEq) { var eq = new BASS_BFX_PEAKEQ {lBand = i}; // get values of the selected band Bass.BASS_FXGetParameters(_fxEq, eq); eq.fGain = frequencyList[i]+Eqstart; Bass.BASS_FXSetParameters(_fxEq, eq); } } _changeEq = true; Notify(); _changeEq = false; if (Bass.BASS_ErrorGetCode() != BASSError.BASS_OK && Bass.BASS_ErrorGetCode() != BASSError.BASS_ERROR_HANDLE) { var e = new BassWrapperException(Bass.BASS_ErrorGetCode(),"Error in Bass.dll; Error Code: " + Bass.BASS_ErrorGetCode()) {Source = "BassWrapper"}; throw e; } }
/// <summary> /// Sets Single Equalizer Band /// </summary> /// <param name="band">Band to set</param> /// <param name="freq">Gain to set</param> public void setEqualizerBand(int band, float freq) { _equalizerTmp[band] = freq; if (!_stopped && _toggleEq) { var eq = new BASS_BFX_PEAKEQ {lBand = band}; // get values of the selected band Bass.BASS_FXGetParameters(_fxEq, eq); eq.fGain = freq+Eqstart; Bass.BASS_FXSetParameters(_fxEq, eq); } _changeEq = true; Notify(); _changeEq = false; if (Bass.BASS_ErrorGetCode() != BASSError.BASS_OK && Bass.BASS_ErrorGetCode() != BASSError.BASS_ERROR_HANDLE) { var e = new BassWrapperException(Bass.BASS_ErrorGetCode(),"Error in Bass.dll; Error Code: " + Bass.BASS_ErrorGetCode()) {Source = "BassWrapper"}; throw e; } }
/// <summary> /// Set The Balace /// </summary> /// <param name="bal">-1 left / +1 right</param> public void setBalance(float bal) { TmpBalance = bal; if(bal>0) { _matrix[0, 0] = 1-bal; _matrix[1, 1] = 1; _matrix[2, 0] = 1-bal; _matrix[2, 1] = 1; _matrix[3, 0] = 1-bal; _matrix[3, 1] = 1; _matrix[4, 0] = 1-bal; _matrix[5, 1] = 1; //_matrix[5] } else if (bal == 0) { _matrix[0,0] = 1; _matrix[1,1] = 1; _matrix[2, 0] = 1; _matrix[2, 1] = 1; _matrix[3, 0] = 1; _matrix[3, 1] = 1; _matrix[4,0] = 1; _matrix[5,1] = 1; } else { _matrix[0, 0] = 1; _matrix[1,1] = 1 + bal; _matrix[2, 0] = 1; _matrix[2, 1] = 1+bal; _matrix[3, 0] = 1; _matrix[3, 1] = 1+bal; _matrix[4, 0] = 1; _matrix[5,1] = 1 + bal; } BassMix.BASS_Mixer_ChannelSetMatrix(_rawstream, _matrix); // apply the _matrix if (Bass.BASS_ErrorGetCode() != BASSError.BASS_OK && Bass.BASS_ErrorGetCode() != BASSError.BASS_ERROR_HANDLE) { var e = new BassWrapperException(Bass.BASS_ErrorGetCode(), "Balance Error") {Source = "BassWrapper"}; throw e; } Notify(); }
/// <summary> /// The Play Method plays a song by his path with the Bass Lib. /// </summary> /// <param name="songPath">Song Path to Play</param> /// <param name="validSong">returns if song is playable by plugin or bass</param> public void play(string songPath, ref bool validSong) { Bass.BASS_StreamFree(_streamId); Bass.BASS_StreamFree(_rawstream); _paused = false; _stopped = false; //Check if a plugin can playback the file bool pluginPlayback = false; foreach (AvailablePlugin plugin in aPluginManager.AvailablePlugins) { if (plugin.Instance.isAbleToPlayback(songPath)) { _rawstream = plugin.Instance.getBassStream(songPath); pluginPlayback = true; validSong = true; break; } } //If there were no plugin for playback, use the normal playback function if (pluginPlayback == false) { validSong = true; if (!File.Exists(songPath)) validSong = false; _rawstream = Bass.BASS_StreamCreateFile(songPath, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT); } _etimeClock = new System.Windows.Threading.DispatcherTimer {Interval = new TimeSpan(0, 0, 0, 1, 0)}; _etimeClock.Tick += EtimeClockTick; _etimeClock.IsEnabled = true; BASS_CHANNELINFO info= Bass.BASS_ChannelGetInfo(_rawstream); // get source info _streamId = BassMix.BASS_Mixer_StreamCreate(info.freq, 6, BASSFlag.BASS_DEFAULT); // create 6 channel mixer with same rate BassMix.BASS_Mixer_StreamAddChannel(_streamId, _rawstream, BASSFlag.BASS_MIXER_MATRIX | BASSFlag.BASS_MIXER_DOWNMIX); // add source with _matrix mixing BassMix.BASS_Mixer_ChannelSetMatrix(_rawstream, _matrix); // apply the _matrix EqualizerInit(); // Initiate Eq _gain = new DSP_Gain(_rawstream, 10) {Gain_dBV = -5f}; if (_toggleEq) setEqualizer(_equalizerTmp); //set last Values else { settoggleEQ(false); } setVolume(_volume); //set _gain if (!pluginPlayback) Bass.BASS_ChannelPlay(_streamId, false); if (Bass.BASS_ErrorGetCode() != BASSError.BASS_OK && Bass.BASS_ErrorGetCode() != BASSError.BASS_ERROR_HANDLE) { var e = new BassWrapperException(Bass.BASS_ErrorGetCode(),"Error while trying to Play " + songPath + ". Error Code: " + Bass.BASS_ErrorGetCode()) {Source = "BassWrapper"}; validSong = false; throw e; } }
/// <summary> /// Pause the Playing stream or if it is paused Play it aggain /// </summary> public void pause() { if (_paused) { float vol=_volume; setVolume(0); Bass.BASS_ChannelPlay(_streamId, false); _etimeClock = new System.Windows.Threading.DispatcherTimer {Interval = new TimeSpan(0, 0, 0, 1, 0)}; _etimeClock.Tick += EtimeClockTick; _etimeClock.IsEnabled = true; setVolume(vol); _paused = false; } else { _etimeClock.IsEnabled = false; Bass.BASS_ChannelPause(_streamId); _paused = true; } Notify(); if (Bass.BASS_ErrorGetCode() != BASSError.BASS_OK && Bass.BASS_ErrorGetCode() != BASSError.BASS_ERROR_HANDLE) { var e = new BassWrapperException(Bass.BASS_ErrorGetCode(),"Error in Bass.dll; Error Code: " + Bass.BASS_ErrorGetCode()) {Source = "BassWrapper"}; throw e; } }
/// <summary> /// Method to Read Music Tags from Files /// </summary> /// <param name="songPath">Filepath</param> /// <returns>Tags /// tags[0]=album /// tags[1]=artist /// tags[2]=title /// /// </returns> public static string[] GetTags(String songPath) { var tags = new string[3]; var tagInfo = new TAG_INFO(); int stream = Bass.BASS_StreamCreateFile(songPath, 0, 0, BASSFlag.BASS_STREAM_DECODE); BassTags.BASS_TAG_GetFromFile(stream, tagInfo); Bass.BASS_StreamFree(stream); // and display what we get tags[0] = tagInfo.album; tags[1] = tagInfo.artist.Trim(); tags[2] = tagInfo.title.Trim(); /* tags[3] = tagInfo.comment; tags[4] = tagInfo.genre; tags[5] = tagInfo.year; tags[6] = tagInfo.track; * */ if (Bass.BASS_ErrorGetCode() != BASSError.BASS_OK && Bass.BASS_ErrorGetCode() != BASSError.BASS_ERROR_HANDLE) { var e = new BassWrapperException(Bass.BASS_ErrorGetCode(), "Tag Error") {Source = "BassWrapperTags"}; throw e; } return tags; }
/// <summary> /// Constructor for the Bass Wrapper Class /// </summary> /// <param name="handle">Window Handle</param> public BassWrapper(IntPtr handle) { //############### BASS - REGISTRATION ##################### //BassNet.Registration("*****@*****.**", "key"); //############### BASS - INITIATION ####################### Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_CPSPEAKERS, handle, null); Console.WriteLine(Bass.BASS_PluginLoad("basswma.dll")); //############### BASS - SYNCPROC INITIATION (End of Song Procedure) TmpBalance = 0f; _volume = 100f; _fftBuffer = new float[2048]; _etimeClock = new System.Windows.Threading.DispatcherTimer {Interval = new TimeSpan(0, 0, 0, 1, 0)}; _etimeClock.Tick += EtimeClockTick; _stopped = true; _changeEq = false; _toggleEq = false; if (Bass.BASS_ErrorGetCode() != BASSError.BASS_OK) { var e = new BassWrapperException(Bass.BASS_ErrorGetCode(),"Error while initialising Sound. Error Code: "+ Bass.BASS_ErrorGetCode()) {Source = "BassWrapper"}; throw e; } }