示例#1
0
        /// <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;
            }
        }
        public BASSPlayer()
        {
            _VizAGC = new DSP_VizAGC();
              _ReplayGainDSP = new DSP_Gain();
              _ASIOEngine = new AsioEngine();

              _StreamWriteProcDelegate = new STREAMPROC(StreamWriteProc);
              _VizRawStreamWriteProcDelegate = new STREAMPROC(VizRawStreamWriteProc);
              _DSOutputStreamWriteProcDelegate = new STREAMPROC(DSOutputStreamWriteProc);
              _MetaTagSyncProcDelegate = new SYNCPROC(StreamMetaTagSyncProc);
              _WasapiProcDelegate = new WASAPIPROC(WasApiProc);

              // Make sure threads are stopped in case Dispose does not get called.
              Application.ApplicationExit += new EventHandler(Application_ApplicationExit);

              _WakeupMainThread = new AutoResetEvent(false);
              _WakeupMonitorThread = new AutoResetEvent(false);
              _WakeupBufferUpdateThread = new AutoResetEvent(false);
              _BufferUpdated = new ManualResetEvent(false);

              _MainThread = new Thread(new ThreadStart(ThreadMain));
              _MonitorThread = new Thread(new ThreadStart(ThreadMonitor));
              _BufferUpdateThread = new Thread(new ThreadStart(ThreadBufferUpdate));

              _MainThread.Name = "PureAudio.Main";
              _MainThread.Start();

              _BufferUpdateThread.Name = "PureAudio.BufferUpdate";
              _BufferUpdateThread.IsBackground = true;
              _BufferUpdateThread.Start();

              _MonitorThread.Name = "PureAudio.Monitor";
              _MonitorThread.IsBackground = true;
              _MonitorThread.Start();
        }
示例#3
0
    private void trackBarGain_ValueChanged(object sender, EventArgs e)
    {
      if (_gain == null)
      {
        _gain = new DSP_Gain();
      }

      this.textBoxGainDBValue.Text = Convert.ToString(trackBarGain.Value / 1000d);
      buttonSetGain_Click(this, EventArgs.Empty);
    }
示例#4
0
    private void SetDSPGain(double gainDB)
    {
      if (_gain == null)
      {
        _gain = new DSP_Gain();
      }

      if (gainDB == 0.0)
      {
        _gain.SetBypass(true);
      }
      else
      {
        _gain.SetBypass(false);
        _gain.Gain_dBV = gainDB;
      }
    }
示例#5
0
    private void buttonSetGain_Click(object sender, EventArgs e)
    {
      if (_gain == null)
      {
        _gain = new DSP_Gain();
      }

      try
      {
        double gainDB = double.Parse(this.textBoxGainDBValue.Text);
        trackBarGain.Value = (int)(gainDB * 1000d);
        SetDSPGain(gainDB);
      }
      catch {}
    }
示例#6
0
        public void SetGain(double gainDB)
        {
            if (_gain == null)
            {
                _gain = new DSP_Gain();
            }

            if (gainDB > 60.0)
                gainDB = 60.0;

            if (gainDB == 0.0)
            {
                _gain.SetBypass(true);
            }
            else
            {
                _gain.SetBypass(false);
                _gain.Gain_dBV = gainDB;
            }
        }
示例#7
0
    /// <summary>
    /// Sets the parameter for a given Bass effect
    /// </summary>
    /// <param name="id"></param>
    /// <param name="name"></param>
    /// <param name="value"></param>
    /// <param name="format"></param>
    private void setBassDSP(string id, string name, string value)
    {
      switch (id)
      {
        case "Gain":
          if (name == "Gain_dbV")
          {
            double gainDB = double.Parse(value);
            if (_gain == null)
            {
              _gain = new DSP_Gain();
            }

            if (gainDB == 0.0)
            {
              _gain.SetBypass(true);
            }
            else
            {
              _gain.SetBypass(false);
              _gain.Gain_dBV = gainDB;
            }
          }
          break;

        case "DynAmp":
          if (name == "Preset")
          {
            if (_damp == null)
            {
              _damp = new BASS_BFX_DAMP();
            }

            switch (Convert.ToInt32(value))
            {
              case 0:
                _damp.Preset_Soft();
                break;
              case 1:
                _damp.Preset_Medium();
                break;
              case 2:
                _damp.Preset_Hard();
                break;
            }
          }
          break;

        case "Compressor":
          if (name == "Threshold")
          {
            if (_comp == null)
            {
              _comp = new BASS_BFX_COMPRESSOR();
            }

            _comp.Preset_Medium();
            _comp.fThreshold = (float)Un4seen.Bass.Utils.DBToLevel(Convert.ToInt32(value) / 10d, 1.0);
          }
          break;
      }
    }
示例#8
0
        public void SetDSP(int streamFX , int stream)
        {
            StreamFX = streamFX;

            StreamReverse = BassFx.BASS_FX_ReverseCreate(stream, 2f, BASSFlag.BASS_FX_FREESOURCE);

            if (_beforePLM != null)
                _beforePLM.Notification -= new EventHandler(BeforePLMNotification);
            _beforePLM = new DSP_PeakLevelMeter(StreamFX, 2000);
            _beforePLM.CalcRMS = true;
            _beforePLM.Notification += new EventHandler(BeforePLMNotification);

            if (_afterPLM != null)
                _afterPLM.Notification -= new EventHandler(AfterPLMNotification);
            _afterPLM = new DSP_PeakLevelMeter(StreamFX, -2000);
            _afterPLM.CalcRMS = true;
            _afterPLM.Notification += new EventHandler(AfterPLMNotification);

            _gain = new DSP_Gain(StreamFX, 0);
            _mono = new DSP_Mono();
            _mono.ChannelHandle = StreamFX;
            _mono.DSPPriority = 0;
            _mono.Invert = MonoInvert;
            if (MonoChecked)
                _mono.Start();
            else
                _mono.Stop();
            _stereoEnhancer = new DSP_StereoEnhancer(StreamFX, 0);
            _stereoEnhancer.SetBypass(!StereoEnhancerEnabled);
            _delay = new DSP_IIRDelay(StreamFX, 0, 2f);
            _delay.SetBypass(!DelayEnabled);

            foreach (Band band in TempoBands)
            {
                switch (band.Label)
                {
                    case "Tempo":
                        Bass.BASS_ChannelSetAttribute(StreamFX, BASSAttribute.BASS_ATTRIB_TEMPO, band.Value);
                        break;
                    case "TempoPitch":
                        Bass.BASS_ChannelSetAttribute(StreamFX, BASSAttribute.BASS_ATTRIB_TEMPO_PITCH, band.Value);
                        break;
                    case "TempoFreq":
                        Bass.BASS_ChannelSetAttribute(StreamFX, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, band.Value);
                        break;
                }
            }

            foreach (Band band in DSPDelayBands)
            {
                switch (band.Label)
                {
                    case "Samples":
                        _delay.Delay = (int)band.Value;
                        break;
                    case "WetDry":
                        _delay.WetDry = band.Value;
                        break;
                    case "Feedback":
                        _delay.Feedback = band.Value;
                        break;
                }
            }

            foreach (Band band in DSPStereoEnhancerBands)
            {
                switch (band.Label)
                {
                    case "WetDry":
                        _stereoEnhancer.WetDry = band.Value;
                        break;
                    case "WideCoef":
                        _stereoEnhancer.WideCoeff = band.Value;
                        break;
                }
            }

            TempoEnableFunc(TempoEnabled);
        }
示例#9
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();
      }

    }