Example #1
0
        /// <summary>
        /// Sets the ReplayGain Value, which is read from the Tag of the file
        /// </summary>
        private void SetReplayGain()
        {
            _replayGainInfo.AlbumGain = null;
            _replayGainInfo.AlbumPeak = null;
            _replayGainInfo.TrackGain = null;
            _replayGainInfo.TrackPeak = null;

            _replayGainInfo.AlbumGain = ParseReplayGainTagValue(_musicTag.ReplayGainAlbum);
            _replayGainInfo.AlbumPeak = ParseReplayGainTagValue(_musicTag.ReplayGainAlbumPeak);
            _replayGainInfo.TrackGain = ParseReplayGainTagValue(_musicTag.ReplayGainTrack);
            _replayGainInfo.TrackPeak = ParseReplayGainTagValue(_musicTag.ReplayGainTrackPeak);

            if (_replayGainInfo.TrackGain.HasValue || _replayGainInfo.AlbumGain.HasValue)
            {
                Log.Debug("BASS: Replay Gain Data: Track Gain={0}dB, Track Peak={1}, Album Gain={2}dB, Album Peak={3}",
                          _replayGainInfo.TrackGain,
                          _replayGainInfo.TrackPeak,
                          _replayGainInfo.AlbumGain,
                          _replayGainInfo.AlbumPeak);
            }
            else
            {
                Log.Debug("BASS: No Replay Gain Information found in stream tags");
            }

            float?gain = null;

            if (Config.EnableAlbumReplayGain && _replayGainInfo.AlbumGain.HasValue)
            {
                gain = _replayGainInfo.AlbumGain;
            }
            else if (_replayGainInfo.TrackGain.HasValue)
            {
                gain = _replayGainInfo.TrackGain;
            }

            if (gain.HasValue)
            {
                Log.Debug("BASS: Setting Replay Gain to {0}dB", gain.Value);
                _gain = new DSP_Gain();
                _gain.ChannelHandle = _stream;
                _gain.Gain_dBV      = gain.Value;
                _gain.Start();
            }
        }
Example #2
0
        /// <summary>
        /// Attach the various DSP Plugins and effects to the stream
        /// </summary>
        private void AttachDspToStream()
        {
            bool dspActive = Config.DSPActive;

            // BASS DSP/FX
            foreach (BassEffect basseffect in Player.DSP.Settings.Instance.BassEffects)
            {
                dspActive = true;
                foreach (BassEffectParm parameter in basseffect.Parameter)
                {
                    setBassDSP(basseffect.EffectName, parameter.Name, parameter.Value);
                }
            }

            // Attach active DSP effects to the Stream
            if (dspActive)
            {
                // BASS effects
                if (_gain != null)
                {
                    Log.Debug("BASS: Enabling Gain Effect.");
                    _gain.ChannelHandle = _stream;
                    _gain.Start();
                }
                if (_damp != null)
                {
                    Log.Debug("BASS: Enabling Dynamic Amplifier Effect.");
                    int dampHandle = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_BFX_DAMP, _dampPrio);
                    Bass.BASS_FXSetParameters(dampHandle, _damp);
                }
                if (_comp != null)
                {
                    Log.Debug("BASS: Enabling Compressor Effect.");
                    int compHandle = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_BFX_COMPRESSOR, _compPrio);
                    Bass.BASS_FXSetParameters(compHandle, _comp);
                }

                // VST Plugins
                foreach (string plugin in Config.VstPlugins)
                {
                    Log.Debug("BASS: Enabling VST Plugin: {0}", plugin);
                    int vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream, plugin, BASSVSTDsp.BASS_VST_DEFAULT, 1);
                    // Copy the parameters of the plugin as loaded on from the settings
                    int vstParm = Config.VstHandles[plugin];
                    BassVst.BASS_VST_SetParamCopyParams(vstParm, vstHandle);
                }

                // Init Winamp DSP only if we got a winamp plugin actiavtes
                int waDspPluginHandle = 0;
                if (Player.DSP.Settings.Instance.WinAmpPlugins.Count > 0)
                {
                    foreach (WinAmpPlugin plugins in Player.DSP.Settings.Instance.WinAmpPlugins)
                    {
                        Log.Debug("BASS: Enabling Winamp DSP Plugin: {0}", plugins.PluginDll);
                        waDspPluginHandle = BassWaDsp.BASS_WADSP_Load(plugins.PluginDll, 5, 5, 100, 100, null);
                        if (waDspPluginHandle > 0)
                        {
                            _waDspPlugins[plugins.PluginDll] = waDspPluginHandle;
                            BassWaDsp.BASS_WADSP_Start(waDspPluginHandle, 0, 0);
                        }
                        else
                        {
                            Log.Debug("Couldn't load WinAmp Plugin {0}. Error code: {1}", plugins.PluginDll,
                                      Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
                        }
                    }
                }

                foreach (int waPluginHandle in _waDspPlugins.Values)
                {
                    BassWaDsp.BASS_WADSP_ChannelSetDSP(waPluginHandle, _stream, 1);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Play the selected Music File
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btPlay_Click(object sender, EventArgs e)
        {
            if (File.Exists(textBoxMusicFile.Text))
            {
                // Init BASS
                BassAudioEngine bassEngine = BassMusicPlayer.Player;
                if (bassEngine.BassFreed)
                {
                    bassEngine.InitBass();
                }

                _stream = Bass.BASS_StreamCreateFile(textBoxMusicFile.Text, 0, 0,
                                                     BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_AUTOFREE |
                                                     BASSFlag.BASS_SAMPLE_SOFTWARE);
                if (_stream != 0)
                {
                    // Attach the BASS DSP Effects to the stream
                    if (_gain != null)
                    {
                        _gain.ChannelHandle = _stream;
                        _gain.Start();
                    }

                    if (checkBoxDAmp.Checked)
                    {
                        _dampHandle = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_BFX_DAMP, _dampPrio);
                        Bass.BASS_FXSetParameters(_dampHandle, _damp);
                    }

                    if (checkBoxCompressor.Checked)
                    {
                        _compHandle = Bass.BASS_ChannelSetFX(_stream, BASSFXType.BASS_FX_BFX_COMPRESSOR, _compPrio);
                        Bass.BASS_FXSetParameters(_compHandle, _comp);
                    }

                    // Attach the plugins to the stream
                    foreach (DSPPluginInfo dsp in listBoxSelectedPlugins.Items)
                    {
                        if (dsp.DSPPluginType == DSPPluginInfo.PluginType.VST)
                        {
                            _vstHandle = BassVst.BASS_VST_ChannelSetDSP(_stream, dsp.FilePath, BASSVSTDsp.BASS_VST_DEFAULT, 1);
                            // Copy the parameters of the old handle
                            int vstold = _vstHandles[dsp.Name];
                            BassVst.BASS_VST_SetParamCopyParams(vstold, _vstHandle);
                            // Now find out to which stream the old handle was assigned and free it
                            BASS_VST_INFO bassvstinfo = new BASS_VST_INFO();
                            BassVst.BASS_VST_GetInfo(vstold, bassvstinfo);
                            BassVst.BASS_VST_ChannelRemoveDSP(bassvstinfo.channelHandle, vstold);
                            _vstHandles[dsp.Name] = _vstHandle;
                        }
                        else
                        {
                            _waDspPlugin = _waDspPlugins[dsp.FilePath];
                            BassWaDsp.BASS_WADSP_Start(_waDspPlugin, 0, 0);
                            BassWaDsp.BASS_WADSP_ChannelSetDSP(_waDspPlugin, _stream, 1);
                        }
                    }
                    btPlay.Enabled = false;
                    btStop.Enabled = true;
                    Bass.BASS_ChannelPlay(_stream, false);
                }
                else
                {
                    MessageBox.Show("Can't play file. Probably not a valid music file");
                }
            }
            else
            {
                MessageBox.Show("File specified does not exist");
            }
        }