예제 #1
0
파일: Audio.cs 프로젝트: Foohy/OlegEngine
 private Audio( int handle, string filename )
 {
     Handle = handle;
     Filename = filename;
     Info = Bass.BASS_ChannelGetInfo(handle);
     Volume = 1.0f;
 }
예제 #2
0
        private void BassPlayerLoad(string url)
        {
            Un4seen.Bass.BASSActive isActive = default(Un4seen.Bass.BASSActive);

            isActive = Bass.BASS_ChannelIsActive(stream);
            if (isActive == Un4seen.Bass.BASSActive.BASS_ACTIVE_PLAYING)
            {
                Bass.BASS_ChannelStop(stream);
            }

            // If ofd.FileName = "" Then Exit Sub
            stream = Bass.BASS_StreamCreateFile(url, 0, 0, BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_STREAM_PRESCAN);
            //stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);

            //  stream = Bass.BASS_Stream
            Bass.BASS_ChannelPlay(stream, false);
            Un4seen.Bass.BASS_CHANNELINFO    CI = new Un4seen.Bass.BASS_CHANNELINFO();
            Un4seen.Bass.AddOn.Tags.TAG_INFO TI = new Un4seen.Bass.AddOn.Tags.TAG_INFO();

            // WF = New Un4seen.Bass.Misc.WaveForm(ofd.FileName, New Un4seen.Bass.Misc.WAVEFORMPROC(AddressOf MyWaveFormCallback), Me)
            // WF.RenderStart(True, BASSFlag.BASS_DEFAULT)

            tmrUpdateControls.Start();
            tmrVisuals.Start();

            TagLib.File f = TagLib.File.Create(url);
            lblTrackInfo.Text       = f.Tag.Artists[0] + " - " + f.Tag.Title;
            cmdPlay.BackgroundImage = pbPausePick.BackgroundImage;

            currentPlayingTrackFile = url;
            tmrUpdateControls_Tick(null, null);
        }
예제 #3
0
        public static BASS_CHANNELINFO BASS_ChannelGetInfo(int handle)
        {
            BASS_CHANNELINFO info = new BASS_CHANNELINFO();

            if (BASS_ChannelGetInfo(handle, info))
            {
                return(info);
            }
            return(null);
        }
예제 #4
0
 public BaseDSP()
 {
     _bitwidth = 0x10;
     _samplerate = 0xac44;
     _numchans = 2;
     _channelInfo = new BASS_CHANNELINFO();
     _user = IntPtr.Zero;
     _dspProc = new DSPPROC(DSPCallback);
     if (Un4seen.Bass.Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_FLOATDSP) == 1)
     {
         _bitwidth = 0x20;
     }
 }
예제 #5
0
 /// <summary>
 /// 播放当前流
 /// </summary>
 private void PlayCurrentStream()
 {
     // Play Stream
     if (ActiveStreamHandle != 0 && Un4seen.Bass.Bass.BASS_ChannelPlay(ActiveStreamHandle, false))
     {
         Un4seen.Bass.BASS_CHANNELINFO info = new Un4seen.Bass.BASS_CHANNELINFO();
         Un4seen.Bass.Bass.BASS_ChannelGetInfo(ActiveStreamHandle, info);
     }
     else
     {
         Debug.WriteLine("Error={0}", Un4seen.Bass.Bass.BASS_ErrorGetCode());
     }
 }
예제 #6
0
        /// <summary>
        /// 打开文件
        /// </summary>
        /// <param name="filename">文件名</param>
        public void OpenFile(string filename)
        {
            openningFile = filename;
            Stop();
            pendingOperation = PendingOperation.None;
            int handle = CreateLocalFileStream(filename);

            handle = SetEQ(handle);
            if (handle != 0)
            {
                ActiveStreamHandle = handle;
                ChannelLength      = TimeSpan.FromSeconds(Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(ActiveStreamHandle, Un4seen.Bass.Bass.BASS_ChannelGetLength(ActiveStreamHandle, 0)));
                Un4seen.Bass.BASS_CHANNELINFO info = new Un4seen.Bass.BASS_CHANNELINFO();
                Un4seen.Bass.Bass.BASS_ChannelGetInfo(ActiveStreamHandle, info);
                sampleFrequency = info.freq;

                int syncHandle = Un4seen.Bass.Bass.BASS_ChannelSetSync(ActiveStreamHandle,
                                                                       Un4seen.Bass.BASSSync.BASS_SYNC_END, 0, endTrackSyncProc, IntPtr.Zero);

                if (syncHandle == 0)
                {
                    throw new ArgumentException("Error establishing End Sync on file stream.", "path");
                }

                CanPlay = true;
                RaiseOpenSucceededEvent();

                switch (pendingOperation)
                {
                case PendingOperation.None:
                    break;

                case PendingOperation.Play:
                    Play();
                    break;

                case PendingOperation.Pause:
                    Pause();
                    break;

                default:
                    break;
                }
            }
            else
            {
                RaiseOpenFailedEvent();
            }
        }
예제 #7
0
파일: TagReadOnly.cs 프로젝트: zoi/YAMP
 public Bass_TagReadOnly(string FileName)
 {
     _bitrate               = BassTags.BASS_TAG_GetFromFile(FileName).bitrate;
     _channelinfo           = BassTags.BASS_TAG_GetFromFile(FileName).channelinfo;
     _copyright             = BassTags.BASS_TAG_GetFromFile(FileName).copyright;
     _duration              = BassTags.BASS_TAG_GetFromFile(FileName).duration;
     _encodedby             = BassTags.BASS_TAG_GetFromFile(FileName).encodedby;
     _filename              = BassTags.BASS_TAG_GetFromFile(FileName).filename;
     _grouping              = BassTags.BASS_TAG_GetFromFile(FileName).grouping;
     _isrc                  = BassTags.BASS_TAG_GetFromFile(FileName).isrc;
     _mood                  = BassTags.BASS_TAG_GetFromFile(FileName).mood;
     _replaygain_track_gain = BassTags.BASS_TAG_GetFromFile(FileName).replaygain_track_gain;
     _replaygain_track_peak = BassTags.BASS_TAG_GetFromFile(FileName).replaygain_track_peak;
     _tagType               = BassTags.BASS_TAG_GetFromFile(FileName).tagType;
 }
예제 #8
0
        public static bool BASS_ChannelGetInfo(int handle, BASS_CHANNELINFO info)
        {
            bool flag = BASS_ChannelGetInfoInternal(handle, ref info._internal);

            if (flag)
            {
                info.chans   = info._internal.chans;
                info.ctype   = info._internal.ctype;
                info.flags   = info._internal.flags;
                info.freq    = info._internal.freq;
                info.origres = info._internal.origres;
                info.plugin  = info._internal.plugin;
                info.sample  = info._internal.sample;
                if ((info.flags & (BASSFlag.BASS_DEFAULT | BASSFlag.BASS_UNICODE)) != BASSFlag.BASS_DEFAULT)
                {
                    info.filename = Marshal.PtrToStringUni(info._internal.filename);
                    return(flag);
                }
                info.filename = Marshal.PtrToStringAnsi(info._internal.filename);
            }
            return(flag);
        }
예제 #9
0
 public TAG_INFO(string FileName)
 {
     title = string.Empty;
     artist = string.Empty;
     album = string.Empty;
     albumartist = string.Empty;
     year = string.Empty;
     comment = string.Empty;
     genre = string.Empty;
     track = string.Empty;
     copyright = string.Empty;
     encodedby = string.Empty;
     composer = string.Empty;
     publisher = string.Empty;
     bpm = string.Empty;
     filename = string.Empty;
     pictures = new ArrayList();
     nativetags = new ArrayList();
     channelinfo = new BASS_CHANNELINFO();
     filename = FileName;
     title = Path.GetFileNameWithoutExtension(FileName);
 }
        public bool OpenFile(string path)
        {
            Stop();

            if (ActiveStreamHandle != 0)
                Bass.BASS_StreamFree(ActiveStreamHandle);

            if (System.IO.File.Exists(path))
            {
                // Create Stream
                int newStreamHandle = Bass.BASS_StreamCreateFile(path, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
                if (newStreamHandle != 0)
                {
                    ActiveStreamHandle = newStreamHandle;
                    BASS_CHANNELINFO info = new BASS_CHANNELINFO();
                    Bass.BASS_ChannelGetInfo(ActiveStreamHandle, info);
                    sampleFrequency = info.freq;
                    this.FileTag = TagLib.File.Create(path);
                    this.ChannelLength = Bass.BASS_ChannelGetLength(ActiveStreamHandle, 0);
                    this.CanPlay = true;
                    return true;
                }
                else
                {
                    this.ActiveStreamHandle = 0;
                    this.FileTag = null;
                    this.CanPlay = false;
                }
            }
            return false;
        }
 private void PlayCurrentStream()
 {
     // Play Stream
     if (ActiveStreamHandle != 0 && Bass.BASS_ChannelPlay(ActiveStreamHandle, false))
     {
         BASS_CHANNELINFO info = new BASS_CHANNELINFO();
         Bass.BASS_ChannelGetInfo(ActiveStreamHandle, info);
     }
     else
     {
     #if DEBUG
         Debug.WriteLine("Error={0}", Bass.BASS_ErrorGetCode());
     #endif
     }
 }
예제 #12
0
        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;
        }
예제 #13
0
    /// <summary>
    /// Starts Playback of the given file
    /// </summary>
    /// <param name="filePath"></param>
    /// <returns></returns>
    public override bool Play(string filePath)
    {
      if (!_Initialized)
      {
        return false;
      }

      int stream = GetCurrentStream();

      bool doFade = false;
      bool result = true;
      Speed = 1; // Set playback Speed to normal speed

      try
      {
        if (filePath.ToLower().CompareTo(FilePath.ToLower()) == 0 && stream != 0)
        {
          // Selected file is equal to current stream
          if (_State == PlayState.Paused)
          {
            // Resume paused stream
            if (_SoftStop)
            {
              Bass.BASS_ChannelSlideAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, 1, 500);
            }
            else
            {
              Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, 1);
            }

            result = Bass.BASS_Start();

            if (_useASIO)
            {
              result = BassAsio.BASS_ASIO_Start(0);
            }

            if (result)
            {
              _State = PlayState.Playing;

              if (PlaybackStateChanged != null)
              {
                PlaybackStateChanged(this, PlayState.Paused, _State);
              }
            }

            return result;
          }
        }
        else
        {
          // Cue support
          cueTrackStartPos = 0;
          cueTrackEndPos = 0;
          if (CueUtil.isCueFakeTrackFile(filePath))
          {
            Log.Debug("BASS: Playing CUE Track: {0}", filePath);
            currentCueFakeTrackFileName = filePath;
            CueFakeTrack cueFakeTrack = CueUtil.parseCueFakeTrackFileName(filePath);
            if (!cueFakeTrack.CueFileName.Equals(currentCueFileName))
            {
              // New CUE. Update chached cue.
              currentCueSheet = new CueSheet(cueFakeTrack.CueFileName);
              currentCueFileName = cueFakeTrack.CueFileName;
            }

            // Get track start position
            Track track = currentCueSheet.Tracks[cueFakeTrack.TrackNumber - currentCueSheet.Tracks[0].TrackNumber];
            Index index = track.Indices[0];
            cueTrackStartPos = CueUtil.cueIndexToFloatTime(index);

            // If single audio file and is not last track, set track end position.
            if (currentCueSheet.Tracks[currentCueSheet.Tracks.Length - 1].TrackNumber > track.TrackNumber)
            {
              Track nextTrack =
                currentCueSheet.Tracks[cueFakeTrack.TrackNumber - currentCueSheet.Tracks[0].TrackNumber + 1];
              if (nextTrack.DataFile.Filename.Equals(track.DataFile.Filename))
              {
                Index nindex = nextTrack.Indices[0];
                cueTrackEndPos = CueUtil.cueIndexToFloatTime(nindex);
              }
            }

            // If audio file is not changed, just set new start/end position and reset pause
            string audioFilePath = System.IO.Path.GetDirectoryName(cueFakeTrack.CueFileName) +
                                   System.IO.Path.DirectorySeparatorChar + track.DataFile.Filename;
            if (audioFilePath.CompareTo(FilePath) == 0 /* && StreamIsPlaying(stream)*/)
            {
              setCueTrackEndPosition(stream);
              return true;
            }
            filePath = audioFilePath;
          }
          else
          {
            currentCueFileName = null;
            currentCueSheet = null;
          }
        }

        if (stream != 0 && StreamIsPlaying(stream))
        {
          int oldStream = stream;
          double oldStreamDuration = GetTotalStreamSeconds(oldStream);
          double oldStreamElapsedSeconds = GetStreamElapsedTime(oldStream);
          double crossFadeSeconds = (double)_CrossFadeIntervalMS;

          if (crossFadeSeconds > 0)
            crossFadeSeconds = crossFadeSeconds / 1000.0;

          if ((oldStreamDuration - (oldStreamElapsedSeconds + crossFadeSeconds) > -1))
          {
            FadeOutStop(oldStream);
          }
          else
          {
            Bass.BASS_ChannelStop(oldStream);
          }

          doFade = true;
          stream = GetNextStream();

          if (stream != 0 || StreamIsPlaying(stream))
          {
            FreeStream(stream);
          }
        }

        if (stream != 0)
        {
          if (!Stopped) // Check if stopped already to avoid that Stop() is called two or three times
          {
            Stop();
          }
          FreeStream(stream);
        }

        _State = PlayState.Init;

        // Make sure Bass is ready to begin playing again
        Bass.BASS_Start();

        float crossOverSeconds = 0;

        if (_CrossFadeIntervalMS > 0)
        {
          crossOverSeconds = (float)_CrossFadeIntervalMS / 1000f;
        }

        if (filePath != string.Empty)
        {
          // Turn on parsing of ASX files
          Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_PLAYLIST, 2);

          // We need different flags for standard BASS and ASIO / Mixing
          BASSFlag streamFlags;
          if (_useASIO || _Mixing)
          {
            streamFlags = BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT;
            // Don't use the BASS_STREAM_AUTOFREE flag on a decoding channel. will produce a BASS_ERROR_NOTAVAIL
          }
          else
          {
            streamFlags = BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_AUTOFREE;
          }

          FilePath = filePath;

          // create the stream
          _isCDDAFile = false;
          _isRadio = false;
          _isLastFMRadio = false;
          if (Util.Utils.IsCDDA(filePath))
          {
            _isCDDAFile = true;

            // StreamCreateFile causes problems with Multisession disks, so use StreamCreate with driveindex and track index
            int driveindex = _cdDriveLetters.IndexOf(filePath.Substring(0, 1));
            int tracknum = Convert.ToInt16(filePath.Substring(filePath.IndexOf(".cda") - 2, 2));
            stream = BassCd.BASS_CD_StreamCreate(driveindex, tracknum - 1, streamFlags);
            if (stream == 0)
              Log.Error("BASS: CD: {0}.", Enum.GetName(typeof (BASSError), Bass.BASS_ErrorGetCode()));
          }
          else if (filePath.ToLower().Contains(@"http://") || filePath.ToLower().Contains(@"https://") ||
                   filePath.ToLower().StartsWith("mms") || filePath.ToLower().StartsWith("rtsp"))
          {
            // We're playing Internet Radio Stream
            _isLastFMRadio = Util.Utils.IsLastFMStream(filePath);
            if (!_isLastFMRadio)
            {
              // We're playing Internet Radio Stream, but not LastFM
              _isRadio = true;
            }

            stream = Bass.BASS_StreamCreateURL(filePath, 0, streamFlags, null, IntPtr.Zero);

            if (stream != 0)
            {
              // Get the Tags and set the Meta Tag SyncProc
              _tagInfo = new TAG_INFO(filePath);
              SetStreamTags(stream);

              if (BassTags.BASS_TAG_GetFromURL(stream, _tagInfo))
              {
                GetMetaTags();
              }

              Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_META, 0, MetaTagSyncProcDelegate, IntPtr.Zero);
            }
            Log.Debug("BASSAudio: Webstream found - trying to fetch stream {0}", Convert.ToString(stream));
          }
          else if (IsMODFile(filePath))
          {
            // Load a Mod file
            stream = Bass.BASS_MusicLoad(filePath, 0, 0,
                                         BASSFlag.BASS_SAMPLE_SOFTWARE | BASSFlag.BASS_SAMPLE_FLOAT |
                                         BASSFlag.BASS_MUSIC_AUTOFREE | BASSFlag.BASS_MUSIC_PRESCAN |
                                         BASSFlag.BASS_MUSIC_RAMP, 0);
          }
          else
          {
            // Create a Standard Stream
            stream = Bass.BASS_StreamCreateFile(filePath, 0, 0, streamFlags);
          }

          // Is Mixing / ASIO enabled, then we create a mixer channel and assign the stream to the mixer
          if ((_Mixing || _useASIO) && stream != 0)
          {
            // Do an upmix of the stereo according to the matrix.
            // Now Plugin the stream to the mixer and set the mixing matrix
            BassMix.BASS_Mixer_StreamAddChannel(_mixer, stream,
                                                BASSFlag.BASS_MIXER_MATRIX | BASSFlag.BASS_STREAM_AUTOFREE |
                                                BASSFlag.BASS_MIXER_NORAMPIN | BASSFlag.BASS_MIXER_BUFFER);
            BassMix.BASS_Mixer_ChannelSetMatrix(stream, _MixingMatrix);
          }

          Streams[CurrentStreamIndex] = stream;

          if (stream != 0)
          {
            // When we have a MIDI file, we need to assign the sound banks to the stream
            if (IsMidiFile(filePath) && soundFonts != null)
            {
              BassMidi.BASS_MIDI_StreamSetFonts(stream, soundFonts, soundFonts.Length);
            }

            StreamEventSyncHandles[CurrentStreamIndex] = RegisterPlaybackEvents(stream, CurrentStreamIndex);

            if (doFade && CrossFadeIntervalMS > 0)
            {
              _CrossFading = true;
              // Reduce the stream volume to zero so we can fade it in...
              Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, 0);

              // Fade in from 0 to 1 over the _CrossFadeIntervalMS duration
              Bass.BASS_ChannelSlideAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, 1, _CrossFadeIntervalMS);
            }

            // Attach active DSP effects to the Stream
            if (_dspActive)
            {
              // BASS effects
              if (_gain != null)
              {
                _gain.ChannelHandle = stream;
                _gain.Start();
              }
              if (_damp != null)
              {
                int dampHandle = Bass.BASS_ChannelSetFX(stream, BASSFXType.BASS_FX_BFX_DAMP, _dampPrio);
                Bass.BASS_FXSetParameters(dampHandle, _damp);
              }
              if (_comp != null)
              {
                int compHandle = Bass.BASS_ChannelSetFX(stream, BASSFXType.BASS_FX_BFX_COMPRESSOR, _compPrio);
                Bass.BASS_FXSetParameters(compHandle, _comp);
              }

              // VST Plugins
              foreach (string plugin in _VSTPlugins)
              {
                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 = _vstHandles[plugin];
                BassVst.BASS_VST_SetParamCopyParams(vstParm, vstHandle);
              }

              // Init Winamp DSP only if we got a winamp plugin actiavtes
              int waDspPlugin = 0;
              if (DSP.Settings.Instance.WinAmpPlugins.Count > 0 && !_waDspInitialised)
              {
                BassWaDsp.BASS_WADSP_Init(GUIGraphicsContext.ActiveForm);
                _waDspInitialised = true;
                foreach (WinAmpPlugin plugins in DSP.Settings.Instance.WinAmpPlugins)
                {
                  waDspPlugin = BassWaDsp.BASS_WADSP_Load(plugins.PluginDll, 5, 5, 100, 100, null);
                  if (waDspPlugin > 0)
                  {
                    _waDspPlugins[plugins.PluginDll] = waDspPlugin;
                    BassWaDsp.BASS_WADSP_Start(waDspPlugin, 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);
              }
            }
          }
          else
          {
            Log.Error("BASS: Unable to create Stream for {0}.  Reason: {1}.", filePath,
                      Enum.GetName(typeof (BASSError), Bass.BASS_ErrorGetCode()));
          }

          bool playbackStarted = false;
          if (_Mixing)
          {
            if (Bass.BASS_ChannelIsActive(_mixer) == BASSActive.BASS_ACTIVE_PLAYING)
            {
              setCueTrackEndPosition(stream);
              playbackStarted = true;
            }
            else
            {
              playbackStarted = Bass.BASS_ChannelPlay(_mixer, false);
              setCueTrackEndPosition(stream);
            }
          }
          else if (_useASIO)
          {
            // Get some information about the stream
            BASS_CHANNELINFO info = new BASS_CHANNELINFO();
            Bass.BASS_ChannelGetInfo(stream, info);

            // In order to provide data for visualisation we need to clone the stream
            _streamcopy = new StreamCopy();
            _streamcopy.ChannelHandle = stream;
            _streamcopy.StreamFlags = BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT;
            // decode the channel, so that we have a Streamcopy

            _asioHandler.Pan = _asioBalance;
            _asioHandler.Volume = (float)_StreamVolume / 100f;

            // Set the Sample Rate from the stream
            _asioHandler.SampleRate = (double)info.freq;
            // try to set the device rate too (saves resampling)
            BassAsio.BASS_ASIO_SetRate((double)info.freq);

            try
            {
              _streamcopy.Start(); // start the cloned stream
            }
            catch (Exception)
            {
              Log.Error("Captured an error on StreamCopy start");
            }

            if (BassAsio.BASS_ASIO_IsStarted())
            {
              setCueTrackEndPosition(stream);
              playbackStarted = true;
            }
            else
            {
              BassAsio.BASS_ASIO_Stop();
              playbackStarted = BassAsio.BASS_ASIO_Start(0);
              setCueTrackEndPosition(stream);
            }
          }
          else
          {
            setCueTrackEndPosition(stream);
            playbackStarted = Bass.BASS_ChannelPlay(stream, false);
          }

          if (stream != 0 && playbackStarted)
          {
            Log.Info("BASS: playback started");

            GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAYBACK_STARTED, 0, 0, 0, 0, 0, null);
            msg.Label = FilePath;
            GUIWindowManager.SendThreadMessage(msg);
            NotifyPlaying = true;

            NeedUpdate = true;
            _IsFullScreen = GUIGraphicsContext.IsFullScreenVideo;
            _VideoPositionX = GUIGraphicsContext.VideoWindow.Left;
            _VideoPositionY = GUIGraphicsContext.VideoWindow.Top;
            _VideoWidth = GUIGraphicsContext.VideoWindow.Width;
            _VideoHeight = GUIGraphicsContext.VideoWindow.Height;

            // Re-Add the Viswindow to the Mainform Control (It got removed on a manual Stop)
            SetVisualizationWindow();
            SetVideoWindow();

            PlayState oldState = _State;
            _State = PlayState.Playing;

            if (oldState != _State && PlaybackStateChanged != null)
            {
              PlaybackStateChanged(this, oldState, _State);
            }

            if (PlaybackStart != null)
            {
              PlaybackStart(this, GetTotalStreamSeconds(stream));
            }
          }

          else
          {
            Log.Error("BASS: Unable to play {0}.  Reason: {1}.", filePath,
                      Enum.GetName(typeof (BASSError), Bass.BASS_ErrorGetCode()));

            // Release all of the sync proc handles
            if (StreamEventSyncHandles[CurrentStreamIndex] != null)
            {
              UnregisterPlaybackEvents(stream, StreamEventSyncHandles[CurrentStreamIndex]);
            }

            result = false;
          }
        }
      }
      catch (Exception ex)
      {
        result = false;
        Log.Error("BASS: Play caused an exception:  {0}.", ex);
      }

      return result;
    }
예제 #14
0
        /// <summary>Initialize the base ASIO streams, and actually start ASIO running.</summary>
        /// <remarks>[MainThread]</remarks>
        internal void StartASIO()
        {
            // not playing anything via BASS, so don't need an update thread
            CheckError(Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 0));

            // setup BASS - "no sound" device but SampleFrequencyHz (default for ASIO)
            CheckError(Bass.BASS_Init(0, Clock.TimepointRateHz, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero));
            CheckError(BassAsio.BASS_ASIO_Init(AsioDeviceId, BASSASIOInit.BASS_ASIO_THREAD));

            CheckError(BassFx.LoadMe());

            if (UseVst) {
                CheckError(BassVst.LoadMe());

                // testing scaffolding; retain for reference
                TempFrobBassVst();
            }

            // register all effects once VST is set up
            EffectRegistrar.RegisterAll();

            ////////////////////// DEVICE SETUP

            CheckError(BassAsio.BASS_ASIO_SetDevice(AsioDeviceId));

            BASS_ASIO_DEVICEINFO info = new BASS_ASIO_DEVICEINFO();
            System.Text.StringBuilder b = new System.Text.StringBuilder();
            for (int n = 0; BassAsio.BASS_ASIO_GetDeviceInfo(n, info); n++) {
                b.AppendLine("device #" + n + ": " + info.ToString());
            }
            b.AppendLine("done");
            string all = b.ToString();
            b.Clear();

            for (int chan = 0; chan < 16; chan++) {
                BASS_ASIO_CHANNELINFO cinfo = BassAsio.BASS_ASIO_ChannelGetInfo(true, chan);
                if (cinfo != null) {
                    b.AppendLine(cinfo.ToString());
                }
                cinfo = BassAsio.BASS_ASIO_ChannelGetInfo(false, chan);
                if (cinfo != null) {
                    b.AppendLine(cinfo.ToString());
                }
            }
            all = b.ToString();

            CheckError(BassAsio.BASS_ASIO_SetRate(Clock.TimepointRateHz));

            BASS_ASIO_INFO asioInfo = BassAsio.BASS_ASIO_GetInfo();
            int inputLatency = BassAsio.BASS_ASIO_GetLatency(IsInputChannel);
            int outputLatency = BassAsio.BASS_ASIO_GetLatency(IsOutputChannel);

            m_asioBufferPreferredSize = 128; // B4CKIN: asioInfo.bufpref;

            ////////////////////// OUTPUT SETUP

            // converted away from BassAsioHandler, to enable better viewing of intermediate data
            // (and full control over API use, allocation, etc.)

            m_mixerHStream = (StreamHandle)BassMix.BASS_Mixer_StreamCreate(
                Clock.TimepointRateHz,
                StereoChannels,
                BASSFlag.BASS_MIXER_RESUME | BASSFlag.BASS_MIXER_NONSTOP | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);

            BASS_CHANNELINFO mixerInfo = new BASS_CHANNELINFO();
            CheckError(Bass.BASS_ChannelGetInfo((int)m_mixerHStream, mixerInfo));

            // connect to ASIO output channel
            CheckError(BassAsio.BASS_ASIO_ChannelEnable(IsOutputChannel, AsioOutputChannelId, m_mixerToOutputAsioProc, new IntPtr((int)m_mixerHStream)));

            // Join second mixer channel (right stereo channel).
            CheckError(BassAsio.BASS_ASIO_ChannelJoin(IsOutputChannel, 1, AsioOutputChannelId));

            CheckError(BassAsio.BASS_ASIO_ChannelSetFormat(IsOutputChannel, AsioOutputChannelId, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT));
            CheckError(BassAsio.BASS_ASIO_ChannelSetRate(IsOutputChannel, AsioOutputChannelId, Clock.TimepointRateHz));

            ////////////////////// INPUT SETUP

            CheckError(BassAsio.BASS_ASIO_SetDevice(HolofunkBassAsio.AsioDeviceId));

            m_input0 = new HolofunkBassAsioInput(this, 0, m_bass.AudioAllocator);
            m_input1 = new HolofunkBassAsioInput(this, 1, m_bass.AudioAllocator);

            ////////////////////// ASIO LAUNCH

            CheckError(BassAsio.BASS_ASIO_Start(m_asioBufferPreferredSize));

            // get the info again, see if latency has changed
            asioInfo = BassAsio.BASS_ASIO_GetInfo();
            inputLatency = BassAsio.BASS_ASIO_GetLatency(IsInputChannel);
            outputLatency = BassAsio.BASS_ASIO_GetLatency(IsOutputChannel);
        }
예제 #15
0
        public bool OpenFile(string path, long offset = 0, long length = 0)
        {
            Stop();

            if (ActiveStreamHandle != 0) {
                ClearRepeatRange();
                ChannelPosition = 0;
                Bass.BASS_StreamFree(ActiveStreamHandle);
                Bass.BASS_StreamFree(decodedStream);
            }

            if (System.IO.File.Exists(path)) {
                // Create Stream
                decodedStream = Bass.BASS_StreamCreateFile(path, offset, length, BASSFlag.BASS_SAMPLE_MONO |
                    BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_STREAM_DECODE);

                FileStreamHandle = ActiveStreamHandle = BassFx.BASS_FX_TempoCreate(decodedStream, BASSFlag.BASS_FX_FREESOURCE);
                ChannelLength = Bass.BASS_ChannelBytes2Seconds(FileStreamHandle, Bass.BASS_ChannelGetLength(FileStreamHandle, 0));
                FileTag = TagLib.File.Create(path);
                GenerateWaveformData(path);
                if (ActiveStreamHandle != 0) {
                    // 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;
                    filePath = path;
                    return true;
                } else {
                    ActiveStreamHandle = 0;
                    FileTag = null;
                    CanPlay = false;
                }
            }
            return false;
        }
예제 #16
0
        protected void NC_OnMediaPacket(object sender, TimeSpan timeStamp, byte[] data)
        {
            NetStreamHelper netStreamHelper = FindNetStreamHelper(sender as NetStream);
            if (netStreamHelper != null)
            {
                /*
                 * Test code to check for byte perfect copy
                 * 
                private System.IO.FileStream _FileStream = null; // put this in the class

                 * 
                if (netStreamHelper.Item.MediaFile == "JK142176-0002")
                {
                    if (_FileStream == null)
                    {
                        Console.WriteLine("!!!!!WRITING!!!!!!!!");
                        _FileStream = new System.IO.FileStream(netStreamHelper.Item.MediaFile + ".MP3", System.IO.FileMode.Create, System.IO.FileAccess.Write);
                    }
                    _FileStream.Write(data, 0, data.Length);
                }
                else if (_FileStream != null)
                {
                    Console.WriteLine("!!!!!CLOSEING!!!!!!!!");
                    _FileStream.Close();
                    _FileStream = null;
                }
                */

                // Store data in buffer
                if (netStreamHelper.Buffer != null)
                {
                    netStreamHelper.Buffer.Write(data);

                    // When index > 0 we are buffering but not playing. Make sure we don't buffer to much data
                    if (netStreamHelper.IndexNumberInList > 0 && !netStreamHelper.NetStream.PauseIsActive)
                    {
                        // Prebuffer
                        // 15 seconds of data? (default for "ContentBufferTime")
                        //if (netStreamHelper.Buffer.UsedBytes >= (128 * 1024 * 8 * 10))
                        if (netStreamHelper.Buffer.UsedBytes >= (MP3_BITRATE * 8 * PREBUFFERTIME_IN_SECOND))
                        {
                            // pause stream! (otherwise stream will take to much memory)
                            netStreamHelper.NetStream.Pause(true);
                            DoEvent_MP_OnPreBuffer(OnPreBuffer, this, (MediaItem)netStreamHelper.Item.Clone(), PreBufferState.PrebufferingReady);
                        }
                    }
                }
                //Console.Write("\r" + netStreamHelper.Item.MediaFile + " ; UsedBytes=" + netStreamHelper.Buffer.UsedBytes.ToString());

                // When no bass channel has been created create it (but there must be enough data in the buffer!)
                if (netStreamHelper.BassHandle == 0 && netStreamHelper.Buffer != null && netStreamHelper.Buffer.UsedBytes >= BASS_MIN_INITIAL_FILLED_BUFFER)
                {
                    // bass needs for mp3 atleast 4000 bytes before is can play
                    // Startup new bassChannel we have enough data in the buffer to start playing
                    netStreamHelper.BassHandle = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_BUFFERPUSH, BASSFlag.BASS_DEFAULT, bassFileProcs, GCHandle.ToIntPtr((GCHandle)gcHandle));
                    if (netStreamHelper.BassHandle != 0)
                    {
                        // Set volume for this channel
                        float volume = 100.0f;
                        lock (lockVAR)
                        {
                            volume = Convert.ToSingle(bassVolume) / 100.0f;
                        }
                        Bass.BASS_ChannelSetAttribute(netStreamHelper.BassHandle, BASSAttribute.BASS_ATTRIB_VOL, volume);

                        BASS_CHANNELINFO info = new BASS_CHANNELINFO();
                        Bass.BASS_ChannelGetInfo(netStreamHelper.BassHandle, info);
                        netStreamHelper.SampleRate = info.freq;
                        netStreamHelper.Channels = info.chans;
                        netStreamHelper.SampleSize = 16;
                        if ((info.flags & BASSFlag.BASS_SAMPLE_FLOAT) != 0) // 32-bit floating-point
                        {
                            netStreamHelper.SampleSize = 32;
                        }
                        else if ((info.flags & BASSFlag.BASS_SAMPLE_8BITS) != 0) // 8-bit
                        {
                            netStreamHelper.SampleSize = 8;
                        }

                        // make sure event funcs are called
                        Bass.BASS_ChannelSetSync(netStreamHelper.BassHandle, BASSSync.BASS_SYNC_STALL, 0, bassStalledSync, GCHandle.ToIntPtr((GCHandle)gcHandle));
                        Bass.BASS_ChannelSetSync(netStreamHelper.BassHandle, BASSSync.BASS_SYNC_END, 0, bassEndSync, GCHandle.ToIntPtr((GCHandle)gcHandle));

                        // Make sure the bass buffer is filled with enough data to start playing uninterrupted
                        // lock to make sure "netStreams" is protected (we're here on the thread of NetConnection not of MediaPlayer)
                        lock (lockVAR)
                        {
                            MPThread_FillBassAudioBuffer();
                        }
                    }
                }


                // -------------------------------------------------------------------------------------------------------------
                // Startup playing the sound if it is needed
                StartPlayingAudioChannel();
            }
        }
예제 #17
0
        public void PlayStream()
        {
            if(BassInit == false)
            {
                Console.WriteLine("PlayBarBASSVM: PlayStream: Bass not initialized");
                return;
            }

            if(SelectedSong==null)
            {
                Console.WriteLine("PlayBarBASSVM: PlayStream: No selected song");
                return;
            }

            if(!System.IO.File.Exists(SelectedSong.FilePath))
            {
                Console.WriteLine("PlayBarBASSVM: PlayStream: Songpath doesn't exists - file not found");
                return;
            }

            //indien een vorig lied nog aan het spelen is, stream vrijmaken voor volgend lied
            if(Bass.BASS_ChannelIsActive(_stream) == BASSActive.BASS_ACTIVE_PLAYING)
                Bass.BASS_StreamFree(_stream);

            _stream = Bass.BASS_StreamCreateFile(SelectedSong.FilePath, 0, 0, BASSFlag.BASS_DEFAULT); /* BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN */
            if (_stream != 0)
            {
                Bass.BASS_ChannelPlay(_stream, false); // play the channel
                //bij iedere nieuwe stream moet de volume herzet worden, reset standaard
                float volume = (float)_sldVolume / 100;
                if (!Bass.BASS_ChannelSetAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, volume))
                    Console.WriteLine("PlayBarBASSVM: Error trying to set volume: {0}", Bass.BASS_ErrorGetCode().ToString());
                Messenger.Default.Send(new NotificationMessage<Song>(SelectedSong, MVVMMessages.Messages.MUSIC_NEW_SONG)); //bericht zenden dat nieuw lied speelt voor titlebar
                _updateTimer.Start();
                //channelinfo
                BASS_CHANNELINFO info = new BASS_CHANNELINFO();
                Bass.BASS_ChannelGetInfo(_stream, info);
                //filetags (id3v1 v2 ...)
                TAG_INFO tagInfo = new TAG_INFO(SelectedSong.FilePath);
                if (BassTags.BASS_TAG_GetFromFile(_stream, tagInfo))
                {
                    Console.WriteLine("PlayBarBASSVM: PlayStream: Playing:{0} - {1}", tagInfo.albumartist, tagInfo.title);
                }
                this.BtnPauseEnabled = true; this.BtnStopEnabled = true; this.BtnPlayEnabled = false;

                //sends event when track is finished om volgende track af te spelen
                Bass.BASS_ChannelSetSync(_stream, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME,0, _mySync, IntPtr.Zero);
            }
            else
            {
                Console.WriteLine("PlayBarBASSVM: PlayStream: Stream error: {0}", Bass.BASS_ErrorGetCode());  // error
                return;
            }
        }
예제 #18
0
        /// <summary>
        /// 播放当前流
        /// </summary>
        private void PlayCurrentStream()
        {
            if (this.ActiveStreamHandle != 0 && Bass.BASS_ChannelPlay(this.ActiveStreamHandle, false))
            {
                BASS_CHANNELINFO info = new Un4seen.Bass.BASS_CHANNELINFO();
                Bass.BASS_ChannelGetInfo(this.ActiveStreamHandle, info);
            }
#if DEBUG
            else
            {

                Debug.WriteLine("Error={0}", Un4seen.Bass.Bass.BASS_ErrorGetCode());

            }
#endif
        }
예제 #19
0
        private void FileAction(object sender, EventArgs e)
        {
            if (!this.isAllreadyClicked)
            {
                this.graphics.ToggleFullScreen();
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "All Audio Files |*.mp3;*.wma;*.aiff;*.ogg;*.wav;*.mp4;*.aac;*.flac|MPEG-1 Audio Layer 3 (*.mp3)|*.mp3|Windows Media Audio (.wma)|*.wma|Audio Interchange File Format (*.aiff)|*.aiff|OGG Vorbis (*.ogg)|*.ogg|Audio for Windows (*.wav)|*.wav|AAC/MP4 (*.aac,*.mp4)|*.aac;*.mp4|Free Lossless Audio Codec (*.flac) |*.flac";
                openFileDialog.FileName = this.track;
                if (DialogResult.OK == openFileDialog.ShowDialog())
                {
                    if (File.Exists(openFileDialog.FileName))
                    {
                        this.track = openFileDialog.FileName;
                        ////load the desired track to the stream
                        if (this.track != String.Empty)
                        {
                            Bass.BASS_ChannelStop(this.streamTempo);
                            Bass.BASS_StreamFree(this.streamTempo);
                            Bass.BASS_StreamFree(this.streamDirection);
                            Bass.BASS_StreamFree(this.stream);
                            this.framePos = 0;
                            this.ResetLoopOut();
                            this.ResetLoopIn();
                            this.scratchAngle = 0;
                            this.trackinfo = new FileInfo(this.track);
                            if (this.trackinfo.Extension.ToLower() == ".wma")
                            {
                                this.stream = BassWma.BASS_WMA_StreamCreateFile(this.track, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);
                            }
                            else if (this.trackinfo.Extension.ToLower() == ".mp4")
                            {
                                this.stream = BassAac.BASS_MP4_StreamCreateFile(this.track, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);
                            }
                            else if (this.trackinfo.Extension.ToLower() == ".aac")
                            {
                                this.stream = BassAac.BASS_AAC_StreamCreateFile(this.track, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);
                            }
                            else if (this.trackinfo.Extension.ToLower() == ".flac")
                            {
                                this.stream = BassFlac.BASS_FLAC_StreamCreateFile(this.track, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);
                            }
                            else
                            {
                                this.stream = Bass.BASS_StreamCreateFile(this.track, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN);
                            }

                            this.streamDirection = BassFx.BASS_FX_ReverseCreate(this.stream, 1, BASSFlag.BASS_STREAM_DECODE);
                            this.streamTempo = BassFx.BASS_FX_TempoCreate(this.streamDirection, BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_SAMPLE_LOOP);

                            Bass.BASS_ChannelSetAttribute(this.streamDirection, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, (float)BASSFXReverse.BASS_FX_RVS_FORWARD);
                            Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 40);
                            Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 5);

                            ////we need to retrieve the samplerate of the track
                            ////because we change it during scratching and afterwards we set it back
                            ////not every track has a samplerate of 44100
                            this.info = Bass.BASS_ChannelGetInfo(this.streamTempo);

                            this.currentFreq = this.info.freq;
                            ////get the waveform
                            this.GetWave();

                            this.len = this.wf.Wave.data.Length;
                            int frames_per_picture = (int)Math.Ceiling((double)this.len / (double)this.totalTextures);
                            double duration = Bass.BASS_ChannelBytes2Seconds(this.streamTempo, Bass.BASS_ChannelGetLength(this.streamTempo)) * 1000;

                            this.state.Play = true;
                        }
                        else
                        {
                            this.track = String.Empty;
                        }
                    }
                }

                this.graphics.ToggleFullScreen();
            }
        }
예제 #20
0
        /// <summary>
        /// 打开文件
        /// </summary>
        /// <param name="filename"></param>
        public void OpenFile(string filename)
        {
            this.CurrentSoundUrl = filename;
            this.Stop();
            int handle = Un4seen.Bass.Bass.BASS_StreamCreateFile(filename, 0, 0, Un4seen.Bass.BASSFlag.BASS_DEFAULT);

            if (handle != 0)
            {
                this.ActiveStreamHandle = handle;
                ChannelLength = Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(ActiveStreamHandle, Un4seen.Bass.Bass.BASS_ChannelGetLength(ActiveStreamHandle, 0));
                Un4seen.Bass.BASS_CHANNELINFO info = new Un4seen.Bass.BASS_CHANNELINFO();
                Un4seen.Bass.Bass.BASS_ChannelGetInfo(ActiveStreamHandle, info);
                this.SampleFrequency = info.freq;
                this.TotalTime = TimeSpan.FromSeconds(Bass.BASS_ChannelBytes2Seconds(this.ActiveStreamHandle, Bass.BASS_ChannelGetLength(ActiveStreamHandle, 0)));
                int syncHandle = Un4seen.Bass.Bass.BASS_ChannelSetSync(ActiveStreamHandle,
                     Un4seen.Bass.BASSSync.BASS_SYNC_END,
                     0,
                     this.EndTrackSyncProc,
                     IntPtr.Zero);

                if (syncHandle == 0)
                    throw new ArgumentException("Error establishing End Sync on file stream.", "path");
                //this.GenerateWaveformData(filename);
                this.CanPlay = true;
                this.Process = 1;
                this.Play();
            }
        }
예제 #21
0
파일: Form1.cs 프로젝트: Windozer/Reverb
        //Lejátszás gomb, Click event
        private void playlist_play_Click(object sender, EventArgs e)
        {
            //Ha már elindult a dal csak Pause-olva vagyunk
            if (paused)
            {
                paused = false;
                _updateTimer.Start();
                Bass.BASS_ChannelPlay(_stream, false);
                Bass.BASS_ChannelSlideAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, 1, 300);

                if (this.InvokeRequired) this.Invoke((MethodInvoker)delegate
                {
                    playlist_play.Visible = false; playlist_pause.Visible = true;
                });
                else
                {
                    playlist_play.Visible = false; playlist_pause.Visible = true;
                }
            }
            else
            {
                //Ha lejátszás folyamatban van, akkor azt kilőjjük
                if (0 != _stream || Bass.BASS_ChannelIsActive(_stream) != BASSActive.BASS_ACTIVE_STOPPED)
                {
                    playlist_stop_Click(null, EventArgs.Empty);
                }

                //Van kijelölve egyáltalán valami lejátszanivaló?
                if (0 != playlist.SelectedRows.Count)
                {
                    // create the stream
                    _stream = Bass.BASS_StreamCreateFile(trackList[playlist.SelectedRows[0].Index].filename, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);

                    if (0 != _stream && Bass.BASS_ChannelPlay(_stream, false))
                    {
                        Bass.BASS_ChannelSetAttribute(_stream, BASSAttribute.BASS_ATTRIB_VOL, volumeBar.Value / 100F); //Induljunk a hangerőszabályozó hangerejével
                        Bass.BASS_ChannelSetSync(_stream, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_ONETIME, 0, nexttrack, IntPtr.Zero); //Következő számra ugrás sync

                        _updateTimer.Start();

                        // get some channel info
                        BASS_CHANNELINFO info = new BASS_CHANNELINFO();
                        Bass.BASS_ChannelGetInfo(_stream, info);

                        if (this.InvokeRequired) this.Invoke((MethodInvoker)delegate
                        {
                            playlist_play.Visible = false; playlist_pause.Visible = true;
                        });
                        else
                        {
                            playlist_play.Visible = false; playlist_pause.Visible = true;
                        }
                    }
                    else
                    {
                        Console.WriteLine("Error={0}", Bass.BASS_ErrorGetCode());
                    }
                }
            }
        }
예제 #22
0
        public bool SliceSample()
        {
            Stop();
            int stream = Bass.BASS_StreamCreateFile(filePath, 0, 0, BASSFlag.BASS_SAMPLE_MONO | BASSFlag.BASS_STREAM_DECODE);

            long tLength = Bass.BASS_ChannelGetLength(stream);
            double seconds = (SelectionEnd - SelectionBegin).TotalSeconds;

            /* byte lengths */

            int boffset = (int)Bass.BASS_ChannelSeconds2Bytes(stream, SelectionBegin.TotalSeconds);
            int blength = (int)Bass.BASS_ChannelSeconds2Bytes(stream, seconds);

            Bass.BASS_ChannelSetPosition(stream, boffset, BASSMode.BASS_POS_BYTES);

            BASS_CHANNELINFO info = new BASS_CHANNELINFO();
            Bass.BASS_ChannelGetInfo(stream, info);
            // create the sample
            short[] data = new short[blength]; //, putdata = new byte[blength];
            Bass.BASS_ChannelGetData(stream, data, blength);

            string f = filePath.Substring(0, filePath.LastIndexOf("\\") + 1) + "temp.wav";

            WaveWriter w = new WaveWriter(f, stream, 16, true);
            w.Write(data, blength);
            w.Close();

            return OpenFile(f);
        }
예제 #23
0
        /// <summary>
        /// Set the media type based on values from BASS.DLL
        /// </summary>
        /// <param name="psc">The IGenericSampleConfig onto which we set the mediatype</param>
        public override void SetMediaType(IGenericSampleConfig psc)
        {
            int lFrequency = 0;
            int lVolume = 0;
            int lPan = 0;

            WaveFormatEx w = new WaveFormatEx();
            BASS_CHANNELINFO lInfo = new BASS_CHANNELINFO();

            Bass.BASS_ChannelGetInfo(m_fChan, lInfo);
            if ((lInfo.flags & (int)BASSStream.BASS_SAMPLE_8BITS) == (int)BASSStream.BASS_SAMPLE_8BITS)
            {
                w.wBitsPerSample = 8;
            }
            else
            {
                w.wBitsPerSample = 16;
            }
            Bass.BASS_ChannelGetAttributes(m_fChan, ref lFrequency, ref lVolume, ref lPan);

            w.cbSize = (short)Marshal.SizeOf(typeof(WaveFormatEx));
            w.nChannels = (short)lInfo.chans;
            w.nSamplesPerSec = lFrequency;
            w.wFormatTag = 1;
            w.nAvgBytesPerSec = w.nSamplesPerSec * w.nBlockAlign;
            m_BytesPerSample = (short)(w.nChannels * (w.wBitsPerSample / 8));
            m_Frequency = lFrequency;
            m_Channels = lInfo.chans;
            w.nBlockAlign = (short)m_BytesPerSample;
            w.nAvgBytesPerSec = w.nSamplesPerSec * w.nBlockAlign;

            AMMediaType amt = new AMMediaType();
            amt.majorType = MediaType.Audio;
            amt.subType = MediaSubType.PCM;
            amt.formatType = FormatType.WaveEx;
            amt.formatPtr = Marshal.AllocCoTaskMem(w.cbSize);
            amt.formatSize = w.cbSize;
            Marshal.StructureToPtr(w, amt.formatPtr, false);

            int hr = psc.SetMediaTypeEx(amt, BUFSIZE);
            DsError.ThrowExceptionForHR(hr);

            DsUtils.FreeAMMediaType(amt);
        }
예제 #24
0
        /// <summary>
        /// 打开网络地址
        /// </summary>
        /// <param name="url">URL地址</param>
        public void OpenUrlAsync(string url)
        {
            openningFile = url;
            //Debug.WriteLine("已调用BassEngine.OpenUrlAsync()");

            Stop();
            pendingOperation = PendingOperation.None;

            onlineFileWorker = new Thread(new ThreadStart(() =>
            {
                int handle = Un4seen.Bass.Bass.BASS_StreamCreateURL(url, 0, Un4seen.Bass.BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);

                Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                {
                    if (handle != 0)
                    {
                        if (openningFile == url)                                                        //该文件为正在打开的文件
                        {
                            ActiveStreamHandle = handle;
                            ChannelLength      = TimeSpan.FromSeconds(Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(ActiveStreamHandle, Un4seen.Bass.Bass.BASS_ChannelGetLength(ActiveStreamHandle, 0)));
                            Un4seen.Bass.BASS_CHANNELINFO info = new Un4seen.Bass.BASS_CHANNELINFO();
                            Un4seen.Bass.Bass.BASS_ChannelGetInfo(ActiveStreamHandle, info);
                            sampleFrequency = info.freq;

                            int syncHandle = Un4seen.Bass.Bass.BASS_ChannelSetSync(ActiveStreamHandle,
                                                                                   Un4seen.Bass.BASSSync.BASS_SYNC_END,
                                                                                   0,
                                                                                   endTrackSyncProc,
                                                                                   IntPtr.Zero);

                            if (syncHandle == 0)
                            {
                                throw new ArgumentException("Error establishing End Sync on file stream.", "path");
                            }

                            CanPlay = true;
                            RaiseOpenSucceededEvent();

                            switch (pendingOperation)
                            {
                            case PendingOperation.None:
                                break;

                            case PendingOperation.Play:
                                Play();
                                break;

                            case PendingOperation.Pause:
                                Pause();
                                break;

                            default:
                                break;
                            }
                        }
                        else                                                    //该文件不是正在打开的文件(即文件已过时,可能的原因是UI线程较忙,调用onlineFileWorker.Abort()时BeginInvoke的内容已提交,但还未执行)
                        {
                            if (!Un4seen.Bass.Bass.BASS_StreamFree(handle))
                            {
                                Debug.WriteLine("BASS_StreamFree失败:" + Un4seen.Bass.Bass.BASS_ErrorGetCode());
                            }
                            //Debug.WriteLine("已调用BASS_StreamFree()");
                        }
                    }
                    else
                    {
                        Debug.WriteLine(Un4seen.Bass.Bass.BASS_ErrorGetCode());
                        RaiseOpenFailedEvent();
                    }
                }));
                onlineFileWorker = null;
            }));
            onlineFileWorker.IsBackground = true;
            onlineFileWorker.Start();
        }
예제 #25
0
    /// <summary>
    /// Initializes a new instance.
    /// </summary>
    private void Initialize()
    {
      _info = Bass.BASS_ChannelGetInfo(_handle);
      Log.Debug("Stream type: {0}", _info.ctype);

      if (_info.ctype != BASSChannelType.BASS_CTYPE_STREAM &&
          _info.ctype != BASSChannelType.BASS_CTYPE_STREAM_MIXER)
      {
        Log.Info("Stream info: {0}", _info.ToString());

        UpdateLocalFields();
        _streamContentType = GetStreamContentType();

        Log.Info("Stream content: {0}", _streamContentType);
      }
    }
예제 #26
0
        private static IntPtr BASS_TAG_GetIntPtr(int stream, BASS_CHANNELINFO info, out BASSTag tagType)
        {
            IntPtr zero = IntPtr.Zero;
            tagType = BASSTag.BASS_TAG_UNKNOWN;
            if ((stream == 0) || (info == null))
            {
                return zero;
            }
            BASSChannelType ctype = info.ctype;
            if ((ctype & BASSChannelType.BASS_CTYPE_STREAM_WAV) > BASSChannelType.BASS_CTYPE_UNKNOWN)
            {
                ctype = BASSChannelType.BASS_CTYPE_STREAM_WAV;
            }
            switch (ctype)
            {
                case BASSChannelType.BASS_CTYPE_STREAM_WMA:
                case BASSChannelType.BASS_CTYPE_STREAM_WMA_MP3:
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_WMA);
                    tagType = BASSTag.BASS_TAG_WMA;
                    return zero;

                case BASSChannelType.BASS_CTYPE_STREAM_WINAMP:
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ID3V2);
                    if (!(zero == IntPtr.Zero))
                    {
                        tagType = BASSTag.BASS_TAG_ID3V2;
                        return zero;
                    }
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_APE);
                    if (!(zero == IntPtr.Zero))
                    {
                        tagType = BASSTag.BASS_TAG_APE;
                        return zero;
                    }
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_OGG);
                    if (zero == IntPtr.Zero)
                    {
                        zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ID3);
                        if (zero != IntPtr.Zero)
                        {
                            tagType = BASSTag.BASS_TAG_ID3;
                        }
                        return zero;
                    }
                    tagType = BASSTag.BASS_TAG_OGG;
                    return zero;

                case BASSChannelType.BASS_CTYPE_STREAM_OGG:
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_OGG);
                    if (!(zero == IntPtr.Zero))
                    {
                        tagType = BASSTag.BASS_TAG_OGG;
                        return zero;
                    }
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_APE);
                    tagType = BASSTag.BASS_TAG_APE;
                    return zero;

                case BASSChannelType.BASS_CTYPE_STREAM_MP1:
                case BASSChannelType.BASS_CTYPE_STREAM_MP2:
                case BASSChannelType.BASS_CTYPE_STREAM_MP3:
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ID3V2);
                    if (!(zero == IntPtr.Zero))
                    {
                        tagType = BASSTag.BASS_TAG_ID3V2;
                        return zero;
                    }
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ID3);
                    tagType = BASSTag.BASS_TAG_ID3;
                    return zero;

                case BASSChannelType.BASS_CTYPE_STREAM_AIFF:
                case BASSChannelType.BASS_CTYPE_STREAM_WAV:
                case BASSChannelType.BASS_CTYPE_STREAM_WAV_PCM:
                case BASSChannelType.BASS_CTYPE_STREAM_WAV_FLOAT:
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_RIFF_INFO);
                    if (zero != IntPtr.Zero)
                    {
                        tagType = BASSTag.BASS_TAG_RIFF_INFO;
                    }
                    return zero;

                case BASSChannelType.BASS_CTYPE_MUSIC_MO3:
                case BASSChannelType.BASS_CTYPE_MUSIC_MOD:
                case BASSChannelType.BASS_CTYPE_MUSIC_MTM:
                case BASSChannelType.BASS_CTYPE_MUSIC_S3M:
                case BASSChannelType.BASS_CTYPE_MUSIC_XM:
                case BASSChannelType.BASS_CTYPE_MUSIC_IT:
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_MUSIC_NAME);
                    if (zero != IntPtr.Zero)
                    {
                        tagType = BASSTag.BASS_TAG_MUSIC_NAME;
                    }
                    return zero;

                case BASSChannelType.BASS_CTYPE_STREAM_WV:
                case BASSChannelType.BASS_CTYPE_STREAM_WV_H:
                case BASSChannelType.BASS_CTYPE_STREAM_WV_L:
                case BASSChannelType.BASS_CTYPE_STREAM_WV_LH:
                case BASSChannelType.BASS_CTYPE_STREAM_OFR:
                case BASSChannelType.BASS_CTYPE_STREAM_APE:
                case BASSChannelType.BASS_CTYPE_STREAM_FLAC:
                case BASSChannelType.BASS_CTYPE_STREAM_SPX:
                case BASSChannelType.BASS_CTYPE_STREAM_MPC:
                case BASSChannelType.BASS_CTYPE_STREAM_TTA:
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_APE);
                    if (zero == IntPtr.Zero)
                    {
                        zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_OGG);
                        if (zero == IntPtr.Zero)
                        {
                            zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ID3V2);
                            if (zero == IntPtr.Zero)
                            {
                                zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ID3);
                                if (zero != IntPtr.Zero)
                                {
                                    tagType = BASSTag.BASS_TAG_ID3;
                                }
                                return zero;
                            }
                            tagType = BASSTag.BASS_TAG_ID3V2;
                            return zero;
                        }
                        tagType = BASSTag.BASS_TAG_OGG;
                        return zero;
                    }
                    tagType = BASSTag.BASS_TAG_APE;
                    return zero;

                case BASSChannelType.BASS_CTYPE_STREAM_MIDI:
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_MIDI_TRACK);
                    if (zero == IntPtr.Zero)
                    {
                        zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_RIFF_INFO);
                        tagType = BASSTag.BASS_TAG_RIFF_INFO;
                        return zero;
                    }
                    tagType = BASSTag.BASS_TAG_MIDI_TRACK;
                    return zero;

                case BASSChannelType.BASS_CTYPE_STREAM_AAC:
                case BASSChannelType.BASS_CTYPE_STREAM_MP4:
                case BASSChannelType.BASS_CTYPE_STREAM_ALAC:
                    zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_MP4);
                    if (zero == IntPtr.Zero)
                    {
                        zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ID3V2);
                        if (zero == IntPtr.Zero)
                        {
                            zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_APE);
                            if (zero == IntPtr.Zero)
                            {
                                zero = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_OGG);
                                if (zero != IntPtr.Zero)
                                {
                                    tagType = BASSTag.BASS_TAG_OGG;
                                }
                                return zero;
                            }
                            tagType = BASSTag.BASS_TAG_APE;
                            return zero;
                        }
                        tagType = BASSTag.BASS_TAG_ID3V2;
                        return zero;
                    }
                    tagType = BASSTag.BASS_TAG_MP4;
                    return zero;
            }
            return IntPtr.Zero;
        }
예제 #27
0
        /// <summary>Add track to mixer.</summary>
        /// <remarks>[MainThread]
        /// 
        /// This is safe provided that m_samplePool is thread-safe (which it is) and 
        /// provided that trackSyncProc is prepared to be called immediately.</remarks>
        /// <param name="trackHStream">HSTREAM of the track to add.</param>
        /// <param name="trackUserData">Track's user data.</param>
        /// <param name="trackSync">the syncproc that will push more track data</param>
        internal void AddStreamToMixer(int trackHStream)
        {
            bool ok;

            BASS_CHANNELINFO trackInfo = new BASS_CHANNELINFO();
            Bass.BASS_ChannelGetInfo(trackHStream, trackInfo);
            BASS_CHANNELINFO mixerInfo = new BASS_CHANNELINFO();
            Bass.BASS_ChannelGetInfo((int)m_mixerHStream, mixerInfo);

            ok = BassMix.BASS_Mixer_StreamAddChannel(
                (int)m_mixerHStream,
                trackHStream,
                BASSFlag.BASS_MIXER_DOWNMIX | BASSFlag.BASS_MIXER_NORAMPIN);

            // try setting to 40% volume to reduce over-leveling
            ok = Bass.BASS_ChannelSetAttribute(trackHStream, BASSAttribute.BASS_ATTRIB_VOL, (float)TopMixVolume);

            ok = BassMix.BASS_Mixer_ChannelPlay(trackHStream);
        }
예제 #28
0
    /// <summary>
    /// Create the stream for the file assigned to the Musicstream
    /// </summary>
    private void CreateStream()
    {
      if (!_temporaryStream)
      {
        Log.Info("BASS: ---------------------------------------------");
        Log.Info("BASS: Creating BASS audio stream");
      }

      BASSFlag streamFlags = BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE;

      _fileType = Utils.GetFileType(_filePath);

      switch (_fileType.FileMainType)
      {
        case FileMainType.Unknown:
          return;

        case FileMainType.AudioFile:
        case FileMainType.MidiFile:
          _stream = Bass.BASS_StreamCreateFile(_filePath, 0, 0, streamFlags);

          if (!_temporaryStream)
          {
            // Read the Tag
            _musicTag = TagReader.TagReader.ReadTag(_filePath);
          }
          break;

        case FileMainType.CDTrack:
          // StreamCreateFile causes problems with Multisession disks, so use StreamCreate with driveindex and track index
          int driveindex = Config.CdDriveLetters.IndexOf(_filePath.Substring(0, 1));
          int tracknum = Convert.ToInt16(_filePath.Substring(_filePath.IndexOf(".cda") - 2, 2));
          _stream = BassCd.BASS_CD_StreamCreate(driveindex, tracknum - 1, streamFlags);
          break;

        case FileMainType.MODFile:
          _stream = Bass.BASS_MusicLoad(_filePath, 0, 0,
                             BASSFlag.BASS_SAMPLE_SOFTWARE | BASSFlag.BASS_SAMPLE_FLOAT |
                             BASSFlag.BASS_MUSIC_DECODE | BASSFlag.BASS_MUSIC_PRESCAN |
                             BASSFlag.BASS_MUSIC_RAMP, 0);
          break;

        case FileMainType.WebStream:
          // Turn on parsing of ASX files
          Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_PLAYLIST, 2);
          _stream = Bass.BASS_StreamCreateURL(_filePath, 0, streamFlags, null, IntPtr.Zero);
          if (_stream != 0 && !_temporaryStream)
          {
            // Get the Tags and set the Meta Tag SyncProc
            _tagInfo = new TAG_INFO(_filePath);
            SetStreamTags(_stream);
            if (BassTags.BASS_TAG_GetFromURL(_stream, _tagInfo))
            {
              GetMetaTags();
            }
            Bass.BASS_ChannelSetSync(_stream, BASSSync.BASS_SYNC_META, 0, _metaTagSyncProcDelegate, IntPtr.Zero);
            Log.Debug("BASS: Webstream found - fetching stream {0}", Convert.ToString(_stream));
          }
          break;
      }

      if (_stream == 0)
      {
        Log.Error("BASS: Unable to create Stream for {0}.  Reason: {1}.", _filePath,
                      Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
        return;
      }

      // When we have a MIDI file, we need to assign the sound banks to the stream
      if (_fileType.FileMainType == FileMainType.MidiFile && Config.SoundFonts != null)
      {
        BassMidi.BASS_MIDI_StreamSetFonts(_stream, Config.SoundFonts, Config.SoundFonts.Length);
      }

      _channelInfo = Bass.BASS_ChannelGetInfo(_stream);
      if (Bass.BASS_ErrorGetCode() != BASSError.BASS_OK)
      {
        Log.Error("BASS: Unable to get information for stream {0}.  Reason: {1}.", _filePath,
                      Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
        return;
      }

      // This stream has just been created to check upfront, the sample rate
      // We don't need further processing of this stream
      if (_temporaryStream)
      {
        return;
      }

      Log.Info("BASS: Stream Information");
      Log.Info("BASS: ---------------------------------------------");
      Log.Info("BASS: File: {0}", _filePath);
      Log.Debug("BASS: Type of Stream: {0}", _channelInfo.ctype);
      Log.Info("BASS: Number of Channels: {0}", _channelInfo.chans);
      Log.Info("BASS: Stream Samplerate: {0}", _channelInfo.freq);
      Log.Debug("BASS: Stream Flags: {0}", _channelInfo.flags);
      Log.Info("BASS: ---------------------------------------------");

      Log.Debug("BASS: Registering stream playback events");
      RegisterPlaybackEvents();

      AttachDspToStream();

      if (Config.EnableReplayGain && _musicTag != null)
      {
        SetReplayGain();
      }
      Log.Info("BASS: Successfully created BASS audio stream");
      Log.Info("BASS: ---------------------------------------------");
    }
예제 #29
0
 public static bool BASS_TAG_GetFromURL(int stream, TAG_INFO tags)
 {
     if ((stream == 0) || (tags == null))
     {
         return false;
     }
     bool flag = false;
     BASS_CHANNELINFO info = new BASS_CHANNELINFO();
     if (Un4seen.Bass.Bass.BASS_ChannelGetInfo(stream, info))
     {
         tags.channelinfo = info;
     }
     IntPtr data = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_ICY);
     if (data == IntPtr.Zero)
     {
         data = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_HTTP);
     }
     if (data != IntPtr.Zero)
     {
         flag = tags.UpdateFromMETA(data, false);
     }
     data = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_META);
     if (data != IntPtr.Zero)
     {
         flag = tags.UpdateFromMETA(data, false);
     }
     else
     {
         data = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_OGG);
         if (data == IntPtr.Zero)
         {
             data = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_APE);
         }
         if (data == IntPtr.Zero)
         {
             data = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, BASSTag.BASS_TAG_WMA);
         }
         if (data != IntPtr.Zero)
         {
             flag = tags.UpdateFromMETA(data, true);
         }
     }
     tags.duration = Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(stream, Un4seen.Bass.Bass.BASS_ChannelGetLength(stream));
     return flag;
 }
예제 #30
0
        public static bool BASS_TAG_GetFromFile(int stream, TAG_INFO tags)
        {
            if ((stream == 0) || (tags == null))
            {
                return false;
            }
            bool flag = false;
            BASS_CHANNELINFO bass_channelinfo = new BASS_CHANNELINFO();
            if (!Un4seen.Bass.Bass.BASS_ChannelGetInfo(stream, bass_channelinfo))
            {
                return flag;
            }
            tags.channelinfo = bass_channelinfo;
            BASSTag tagType = BASSTag.BASS_TAG_UNKNOWN;
            IntPtr p = BASS_TAG_GetIntPtr(stream, bass_channelinfo, out tagType);
            if (p != IntPtr.Zero)
            {
                switch (tagType)
                {
                    case BASSTag.BASS_TAG_MUSIC_NAME:
                        tags.title = Un4seen.Bass.Bass.BASS_ChannelGetMusicName(stream);
                        tags.artist = Un4seen.Bass.Bass.BASS_ChannelGetMusicMessage(stream);
                        flag = true;
                        goto Label_0229;

                    case BASSTag.BASS_TAG_MIDI_TRACK:
                    {
                        int num = 0;
                        while (true)
                        {
                            IntPtr data = Un4seen.Bass.Bass.BASS_ChannelGetTags(stream, (BASSTag) (0x11000 + num));
                            if (!(data != IntPtr.Zero))
                            {
                                if (!flag && (tags.NativeTags.Length > 0))
                                {
                                    flag = true;
                                    if (tags.NativeTags.Length > 0)
                                    {
                                        tags.title = tags.NativeTags[0].Trim();
                                    }
                                    if (tags.NativeTags.Length > 1)
                                    {
                                        tags.artist = tags.NativeTags[1].Trim();
                                    }
                                }
                                goto Label_0229;
                            }
                            flag |= tags.UpdateFromMETA(data, false);
                            num++;
                        }
                    }
                    case BASSTag.BASS_TAG_ID3:
                        flag = ReadID3v1(p, tags);
                        goto Label_0229;

                    case BASSTag.BASS_TAG_ID3V2:
                        flag = ReadID3v2(p, tags);
                        goto Label_0229;

                    case BASSTag.BASS_TAG_OGG:
                        flag = tags.UpdateFromMETA(p, true);
                        goto Label_0229;

                    case BASSTag.BASS_TAG_HTTP:
                    case BASSTag.BASS_TAG_ICY:
                    case BASSTag.BASS_TAG_META:
                        goto Label_0229;

                    case BASSTag.BASS_TAG_APE:
                        flag = tags.UpdateFromMETA(p, true);
                        goto Label_0229;

                    case BASSTag.BASS_TAG_MP4:
                        flag = tags.UpdateFromMETA(p, true);
                        goto Label_0229;

                    case BASSTag.BASS_TAG_RIFF_INFO:
                        flag = tags.UpdateFromMETA(p, false);
                        goto Label_0229;
                }
            }
            Label_0229:
            tags.duration = Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(stream, Un4seen.Bass.Bass.BASS_ChannelGetLength(stream));
            if (tags.bitrate == 0)
            {
                long num2 = Un4seen.Bass.Bass.BASS_StreamGetFilePosition(stream, BASSStreamFilePosition.BASS_FILEPOS_END);
                tags.bitrate = (int) ((((double) num2) / (125.0 * tags.duration)) + 0.5);
            }
            return flag;
        }
예제 #31
0
파일: Utils.cs 프로젝트: safawu/project2006
 public static bool DetectCuePoints(string filename, float blockSize, ref double cueInPos, ref double cueOutPos,
                                    double dBIn, double dBOut, int findZeroCrossing)
 {
     int handle =
         Bass.BASS_StreamCreateFile(filename, 0L, 0L, BASSFlag.BASS_MUSIC_DECODE | BASSFlag.BASS_SAMPLE_OVER_POS);
     if (handle == 0)
     {
         return false;
     }
     BASS_CHANNELINFO info = new BASS_CHANNELINFO();
     if (!Bass.BASS_ChannelGetInfo(handle, info))
     {
         return false;
     }
     if (dBIn > 0.0)
     {
         dBIn = 0.0;
     }
     else if (dBIn < -90.0)
     {
         dBIn = -90.0;
     }
     if (dBOut > 0.0)
     {
         dBOut = 0.0;
     }
     else if (dBOut < -90.0)
     {
         dBOut = -90.0;
     }
     if (blockSize > 30f)
     {
         blockSize = 30f;
     }
     else if (blockSize < 0.1f)
     {
         blockSize = 0.1f;
     }
     short num2 = (short) DBToLevel(dBIn, 0x7fff);
     short num3 = (short) DBToLevel(dBOut, 0x7fff);
     long num4 = Bass.BASS_ChannelGetLength(handle);
     long pos = 0L;
     long num6 = num4;
     int length = (int) Bass.BASS_ChannelSeconds2Bytes(handle, (double) blockSize);
     short[] buffer = new short[length/2];
     int num8 = 0;
     int num9 = 0;
     long num10 = 0L;
     bool flag = false;
     while (!flag && (num10 < num4))
     {
         num9 = Bass.BASS_ChannelGetData(handle, buffer, length);
         pos = num10;
         num8 = 0;
         while (!flag && (num8 < num9))
         {
             if (ScanSampleLevel(buffer, num8, info.chans) < num2)
             {
                 num8 += info.chans;
             }
             else
             {
                 flag = true;
                 pos = num10 + num8;
             }
         }
         if (!flag)
         {
             num10 += num9;
             if (num9 == 0)
             {
                 num10 = num4;
                 pos = num10;
             }
         }
     }
     if (flag && (pos < num4))
     {
         if (findZeroCrossing == 1)
         {
             while ((num8 > 0) && !IsZeroCrossingPos(buffer, num8, num8 - info.chans, info.chans))
             {
                 num8 -= info.chans;
                 pos -= info.chans;
             }
             if (pos < 0L)
             {
                 pos = 0L;
             }
         }
         else if (findZeroCrossing == 2)
         {
             while ((num8 > 0) && (ScanSampleLevel(buffer, num8, info.chans) > (num2/2)))
             {
                 num8 -= info.chans;
                 pos -= info.chans;
             }
             if (pos < 0L)
             {
                 pos = 0L;
             }
         }
     }
     else
     {
         pos = 0L;
     }
     num9 = 0;
     num10 = num4;
     flag = false;
     while (!flag && (num10 > 0L))
     {
         Bass.BASS_ChannelSetPosition(handle, ((num10 - length) >= 0L) ? (num10 - length) : 0L);
         num9 = Bass.BASS_ChannelGetData(handle, buffer, length);
         num6 = num10;
         num8 = num9;
         while (!flag && (num8 > 0))
         {
             if (ScanSampleLevel(buffer, num8 - info.chans, info.chans) < num3)
             {
                 num8 -= info.chans;
             }
             else
             {
                 flag = true;
                 num6 = num10 - num8;
             }
         }
         if (!flag)
         {
             num10 -= num9;
             if (num9 == 0)
             {
                 num10 = 0L;
                 num6 = num4;
             }
         }
     }
     if (flag && (num6 > 0L))
     {
         if (findZeroCrossing == 1)
         {
             while ((num8 < num9) && !IsZeroCrossingPos(buffer, num8, num8 + info.chans, info.chans))
             {
                 num8 += info.chans;
                 num6 += info.chans;
             }
         }
         else if (findZeroCrossing == 2)
         {
             while ((num8 < num9) && (ScanSampleLevel(buffer, num8, info.chans) > (num3/2)))
             {
                 num8 += info.chans;
                 num6 += info.chans;
             }
         }
     }
     else
     {
         num6 = num4;
     }
     cueInPos = Bass.BASS_ChannelBytes2Seconds(handle, pos);
     cueOutPos = Bass.BASS_ChannelBytes2Seconds(handle, num6);
     Bass.BASS_StreamFree(handle);
     return true;
 }
예제 #32
0
        /// <summary>
        /// 打开网络地址
        /// </summary>
        /// <param name="url">URL地址</param>
        public void OpenUrlAsync(string url)
        {
            openningFile = url;
            //Debug.WriteLine("已调用BassEngine.OpenUrlAsync()");

            Stop();
            pendingOperation = PendingOperation.None;

            onlineFileWorker = new Thread(new ThreadStart(() =>
                {
                    int handle = Un4seen.Bass.Bass.BASS_StreamCreateURL(url, 0, Un4seen.Bass.BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);

                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            if (handle != 0)
                            {
                                if (openningFile == url)		//该文件为正在打开的文件
                                {
                                    ActiveStreamHandle = handle;
                                    ChannelLength = TimeSpan.FromSeconds(Un4seen.Bass.Bass.BASS_ChannelBytes2Seconds(ActiveStreamHandle, Un4seen.Bass.Bass.BASS_ChannelGetLength(ActiveStreamHandle, 0)));
                                    Un4seen.Bass.BASS_CHANNELINFO info = new Un4seen.Bass.BASS_CHANNELINFO();
                                    Un4seen.Bass.Bass.BASS_ChannelGetInfo(ActiveStreamHandle, info);
                                    sampleFrequency = info.freq;
                                    this.downloadTimer.IsEnabled = true;
                                    int syncHandle = Un4seen.Bass.Bass.BASS_ChannelSetSync(ActiveStreamHandle,
                                         Un4seen.Bass.BASSSync.BASS_SYNC_END,
                                         0,
                                         endTrackSyncProc,
                                         IntPtr.Zero);

                                    if (syncHandle == 0)
                                        throw new ArgumentException("Error establishing End Sync on file stream.", "path");

                                    CanPlay = true;
                                    RaiseOpenSucceededEvent();

                                    switch (pendingOperation)
                                    {
                                        case PendingOperation.None:
                                            break;
                                        case PendingOperation.Play:
                                            Play();
                                            break;
                                        case PendingOperation.Pause:
                                            Pause();
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                else		//该文件不是正在打开的文件(即文件已过时,可能的原因是UI线程较忙,调用onlineFileWorker.Abort()时BeginInvoke的内容已提交,但还未执行)
                                {
                                    if (!Un4seen.Bass.Bass.BASS_StreamFree(handle))
                                    {
                                        Debug.WriteLine("BASS_StreamFree失败:" + Un4seen.Bass.Bass.BASS_ErrorGetCode());
                                    }
                                    //Debug.WriteLine("已调用BASS_StreamFree()");
                                }
                            }
                            else
                            {
                                Debug.WriteLine(Un4seen.Bass.Bass.BASS_ErrorGetCode());
                                RaiseOpenFailedEvent();
                            }
                        }));
                    onlineFileWorker = null;
                }));
            onlineFileWorker.IsBackground = true;
            onlineFileWorker.Start();
        }
예제 #33
0
파일: Bass.cs 프로젝트: safawu/project2006
 public static BASS_CHANNELINFO BASS_ChannelGetInfo(int handle)
 {
     BASS_CHANNELINFO info = new BASS_CHANNELINFO();
     if (BASS_ChannelGetInfo(handle, info))
     {
         return info;
     }
     return null;
 }
예제 #34
0
파일: Bass.cs 프로젝트: safawu/project2006
 public static bool BASS_ChannelGetInfo(int handle, BASS_CHANNELINFO info)
 {
     bool flag = BASS_ChannelGetInfoInternal(handle, ref info._internal);
     if (flag)
     {
         info.chans = info._internal.chans;
         info.ctype = info._internal.ctype;
         info.flags = info._internal.flags;
         info.freq = info._internal.freq;
         info.origres = info._internal.origres;
         info.plugin = info._internal.plugin;
         info.sample = info._internal.sample;
         if ((info.flags & (BASSFlag.BASS_DEFAULT | BASSFlag.BASS_UNICODE)) != BASSFlag.BASS_DEFAULT)
         {
             info.filename = Marshal.PtrToStringUni(info._internal.filename);
             return flag;
         }
         info.filename = Marshal.PtrToStringAnsi(info._internal.filename);
     }
     return flag;
 }
예제 #35
0
    /// <summary>
    /// Creates a Musicstream object
    /// </summary>
    /// <param name="filePath">The Path of the song</param>
    /// <param name="temporaryStream">Indicates that the stream is just temporary</param>
    public MusicStream(string filePath, bool temporaryStream)
    {
      _temporaryStream = temporaryStream;
      _fileType.FileMainType = FileMainType.Unknown;
      _channelInfo = new BASS_CHANNELINFO();
      _filePath = filePath;

      _playbackCrossFadeProcDelegate = new SYNCPROC(PlaybackCrossFadeProc);
      _cueTrackEndProcDelegate = new SYNCPROC(CueTrackEndProc);
      _metaTagSyncProcDelegate = new SYNCPROC(MetaTagSyncProc);
      _streamFreedDelegate = new SYNCPROC(StreamFreedProc);

      CreateStream();
    }
예제 #36
-1
 public TAG_INFO()
 {
     title = string.Empty;
     artist = string.Empty;
     album = string.Empty;
     albumartist = string.Empty;
     year = string.Empty;
     comment = string.Empty;
     genre = string.Empty;
     track = string.Empty;
     copyright = string.Empty;
     encodedby = string.Empty;
     composer = string.Empty;
     publisher = string.Empty;
     bpm = string.Empty;
     filename = string.Empty;
     pictures = new ArrayList();
     nativetags = new ArrayList();
     channelinfo = new BASS_CHANNELINFO();
 }