Beispiel #1
0
        public void SetRepeatFile(int handle, bool repeat)
        {
            lock (m_Mutex)
            {
                if (!m_NotLoops.ContainsKey(handle))
                {
                    return; // file is looped anyway
                }
                if (m_CueOutRepeats.ContainsKey(handle))
                {
                    m_CueOutRepeats[handle] = repeat;
                    return;
                }

                if (repeat)
                {
                    Bass.BASS_ChannelFlags(handle, BASSFlag.BASS_SAMPLE_LOOP, BASSFlag.BASS_SAMPLE_LOOP);
                    Bass.BASS_ChannelRemoveSync(handle, m_NotLoops[handle]);
                }
                else
                {
                    Bass.BASS_ChannelFlags(handle, BASSFlag.BASS_DEFAULT, BASSFlag.BASS_SAMPLE_LOOP);
                    int sync = Bass.BASS_ChannelSetSync(handle, BASSSync.BASS_SYNC_END, 0, m_EndSync, IntPtr.Zero);
                    m_NotLoops[handle] = sync;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// CUE Track End Procedure
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="stream"></param>
        /// <param name="data"></param>
        /// <param name="userData"></param>
        private void CueTrackEndProc(int handle, int stream, int data, IntPtr userData)
        {
            new Thread(() =>
            {
                Log.Debug("BASS: CueTrackEndProc of stream {0}", stream);

                if (Config.CrossFadeIntervalMs > 0)
                {
                    // Only sent GUI_MSG_PLAYBACK_CROSSFADING when gapless/crossfading mode is used
                    GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAYBACK_CROSSFADING, 0, 0,
                                                    0, 0, 0, null);
                    GUIWindowManager.SendThreadMessage(msg);
                }

                bool removed = Bass.BASS_ChannelRemoveSync(stream, handle);
                if (removed)
                {
                    Log.Debug("BassAudio: *** BASS_ChannelRemoveSync in CueTrackEndProc");
                }
            }
                       )
            {
                Name = "BASS CueEnd"
            }.Start();
        }
Beispiel #3
0
        public bool LoadStream(string url)
        {
            string realURL = url;

            if (url.EndsWith(".m3u", StringComparison.OrdinalIgnoreCase))
            {
                using (var client = new System.Net.WebClient())
                {
                    realURL = client.DownloadString(url);
                }
            }
            System.Diagnostics.Debug.WriteLine("Opened: " + url);
            _timer.Stop();
            if (_hSync != -1)
            {
                Bass.BASS_ChannelRemoveSync(_stream, _hSync);
            }
            Bass.BASS_StreamFree(_stream);
            // create the stream
            _stream = Bass.BASS_StreamCreateURL(realURL, 0, BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_SAMPLE_SOFTWARE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_RESTRATE, null, IntPtr.Zero);
            if (_stream != 0)
            {
                _hSync       = Bass.BASS_ChannelSetSync(_stream, BASSSync.BASS_SYNC_META | BASSSync.BASS_SYNC_MIXTIME, 0, _meta_proc, IntPtr.Zero);
                _currentSong = new SongInfo(url, "", "", "", 0, 0, 0, "", "", false);
                meta_sync(1, 1, 1, IntPtr.Zero);
                return(true);
            }
            else
            {
                HandleBassError(false);
                return(false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Sets a SyncPos on the mixer stream
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="timePos"></param>
        public void SetSyncPos(MusicStream stream, double timePos)
        {
            double fadeOutSeconds = Config.CrossFadeIntervalMs / 1000.0;
            double totalStreamLen = Bass.BASS_ChannelBytes2Seconds(stream.BassStream, Bass.BASS_ChannelGetLength(stream.BassStream, BASSMode.BASS_POS_BYTES));
            long   mixerPos       = Bass.BASS_ChannelGetPosition(_mixer, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODE);
            long   syncPos        = mixerPos + Bass.BASS_ChannelSeconds2Bytes(_mixer, totalStreamLen - timePos - fadeOutSeconds);

            if (_syncProc != 0)
            {
                Bass.BASS_ChannelRemoveSync(_mixer, _syncProc);
            }

            // We might have stored the pinned object already, because we are skipping
            // Only store object it, when it doesn't exist
            if (!_pinnedObjects.ContainsKey(stream.BassStream))
            {
                Log.Debug("BASS: Updating Dictionary for GCHandle for stream {0}", stream.BassStream);
                // Add the pinned object to the global dictionary, so that we can free it later in the Sync End Proc
                _pinnedObjects.Add(stream.BassStream, GCHandle.Alloc(stream));
            }

            _syncProc = Bass.BASS_ChannelSetSync(_mixer,
                                                 BASSSync.BASS_SYNC_ONETIME | BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME,
                                                 syncPos, _playbackEndProcDelegate,
                                                 new IntPtr(stream.BassStream));
        }
Beispiel #5
0
        public void Dispose()
        {
            if (_handle == 0)
            {
                return;
            }

            try
            {
                // Make sure handle never points to a non-existing handle (multithreading)
                int h = _handle;
                _handle = 0;

                // Free sync procs first
                foreach (int syncProcHandle in _syncProcHandles)
                {
                    Bass.BASS_ChannelRemoveSync(h, syncProcHandle);
                }

                _syncProcHandles.Clear();

                // Ignore error
                Bass.BASS_StreamFree(h);
            }
            catch (Exception ex)
            {
                Log.Error("Exception disposing stream", ex);
            }
        }
Beispiel #6
0
 private void ClearRepeatRange()
 {
     if (repeatSyncId != 0)
     {
         Bass.BASS_ChannelRemoveSync(ActiveStreamHandle, repeatSyncId);
         repeatSyncId = 0;
     }
 }
Beispiel #7
0
        public void destroy()
        {
            Bass.BASS_ChannelStop(voiceHandle);
            Bass.BASS_StreamFree(voiceHandle);

            if (rootBuffer.looped)
            {
                Bass.BASS_ChannelRemoveSync(voiceHandle, syncHandle);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Set the end position of a song inside a CUE file
        /// </summary>
        /// <param name="startPos"></param>
        /// <param name="endPos"></param>
        public void SetCueTrackEndPos(float startPos, float endPos)
        {
            if (_cueTrackEndEventHandler != 0)
            {
                Bass.BASS_ChannelRemoveSync(_stream, _cueTrackEndEventHandler);
            }

            Bass.BASS_ChannelSetPosition(_stream, Bass.BASS_ChannelSeconds2Bytes(_stream, startPos));
            if (endPos > startPos)
            {
                _cueTrackEndEventHandler = RegisterCueTrackEndEvent(Bass.BASS_ChannelSeconds2Bytes(_stream, endPos));
            }
        }
Beispiel #9
0
        public void Dispose()
        {
            if (!Valid)
            {
                throw new InvalidOperationException($"The sync is already disposed or invalid. Channel handle {ChannelHandle.Handle.ToString("X8")}, file name {ChannelHandle.FileName}.");
            }

            if (!ChannelHandle.Valid)
            {
                throw new InvalidOperationException($"The channel handle for this sync was disposed. Channel handle {ChannelHandle.Handle.ToString("X8")}, file name {ChannelHandle.FileName}.");
            }

            Bass.BASS_ChannelRemoveSync(ChannelHandle.Handle, Handle);
        }
 /// <summary>
 ///   Stop Playback of Stream
 /// </summary>
 public void Stop()
 {
     log.Debug("Player: Stop Playback");
     if (Bass.BASS_ChannelIsActive(_stream) == BASSActive.BASS_ACTIVE_PLAYING ||
         Bass.BASS_ChannelIsActive(_stream) == BASSActive.BASS_ACTIVE_PAUSED)
     {
         Bass.BASS_ChannelStop(_stream);
         Bass.BASS_ChannelRemoveSync(_stream, _syncHandleEnd);
     }
     pictureBoxPlayPause.Image = _imgPlay;
     playBackSlider.Value      = 0;
     playBackSlider.Enabled    = false;
     _currentSongPlaying       = "";
 }
Beispiel #11
0
        public void Dispose() // Let the object dispose.
        {
            if (!fading)
            {
                Stop();                       // If it's being collected, stop it first.

                Bass.BASS_StreamFree(handle); // Then finally, we can free the stream, as the sound is no longer used in any way.
            }
            // Let the GC do its thing, i guess.
            if (looping) // If it loops
            {
                // We need to deallocate the sync proc
                Bass.BASS_ChannelRemoveSync(handle, syncHandle);
            }
        }
Beispiel #12
0
        //开始
        public void Start()
        {
            if (_fileName != String.Empty)
            {
                if (_stream != 0)
                {
                    playPause = false;
                    // used in RMS
                    _30mslength = (int)Bass.BASS_ChannelSeconds2Bytes(_stream, 0.03); // 30ms window                                                                                 // latency from milliseconds to bytes
                    _deviceLatencyBytes = (int)Bass.BASS_ChannelSeconds2Bytes(_stream, _deviceLatencyMS / 1000.0);

                    if (WF2 != null && WF2.IsRendered)
                    {
                        // make sure playback and wave form are in sync, since
                        // we rended with 16-bit but play here with 32-bit
                        WF2.SyncPlayback(_stream);

                        //long cuein = WF2.GetMarker("CUE");
                        long cueout = WF2.GetMarker("END");

                        //int cueinFrame = WF2.Position2Frames(cuein);
                        //int cueoutFrame = WF2.Position2Frames(cueout);
                        //Console.WriteLine("CueIn at {0}sec.; CueOut at {1}sec.", WF2.Frame2Seconds(cueinFrame), WF2.Frame2Seconds(cueoutFrame));

                        //if (cuein >= 0)
                        //{
                        //    Bass.BASS_ChannelSetPosition(_stream, cuein);
                        //}
                        if (cueout >= 0)
                        {
                            Bass.BASS_ChannelRemoveSync(_stream, _syncer);
                            _syncer = Bass.BASS_ChannelSetSync(_stream, BASSSync.BASS_SYNC_POS, cueout, _sync, IntPtr.Zero);
                        }
                    }

                    if (_stream != 0 && Bass.BASS_ChannelPlay(_stream, false))
                    {
                        _updateTimer.Start();
                    }
                    else
                    {
                        Console.WriteLine("Error={0}", Bass.BASS_ErrorGetCode());
                    }

                }

            }
        }
Beispiel #13
0
        // callback that handles end of measure
        private void LoopEnd(int handle, int c, int data, IntPtr user)
        {
            // switch to random measure if not on hold
            if (!form.GetHold(nr))
            {
                measure = random.Next(0, length + 1);
                form.SetTrackbar(nr, measure);

                // set end pos callback
                Bass.BASS_ChannelRemoveSync(channel, synchandle);
                synchandle = Bass.BASS_ChannelSetSync(channel, BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME, MeasuresToBytes(measure + 1), sync, IntPtr.Zero);
            }

            // move to start point
            Bass.BASS_ChannelSetPosition(channel, MeasuresToBytes(measure), BASSMode.BASS_POS_BYTE);

            //Console.WriteLine("Channel: " + channel + " Measure: " + measure);
        }
Beispiel #14
0
        /// <summary>
        /// Sets a SyncPos on the mixer stream
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="timePos"></param>
        public void SetSyncPos(MusicStream stream, double timePos)
        {
            double fadeOutSeconds = Config.CrossFadeIntervalMs / 1000.0;
            double totalStreamLen = Bass.BASS_ChannelBytes2Seconds(stream.BassStream, Bass.BASS_ChannelGetLength(stream.BassStream, BASSMode.BASS_POS_BYTES));
            long   mixerPos       = Bass.BASS_ChannelGetPosition(_mixer, BASSMode.BASS_POS_BYTES | BASSMode.BASS_POS_DECODE);
            long   syncPos        = mixerPos + Bass.BASS_ChannelSeconds2Bytes(_mixer, totalStreamLen - timePos - fadeOutSeconds);

            if (_syncProc != 0)
            {
                Bass.BASS_ChannelRemoveSync(_mixer, _syncProc);
            }

            GCHandle pFilePath = GCHandle.Alloc(stream);

            _syncProc = Bass.BASS_ChannelSetSync(_mixer,
                                                 BASSSync.BASS_SYNC_ONETIME | BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME,
                                                 syncPos, _playbackEndProcDelegate,
                                                 GCHandle.ToIntPtr(pFilePath));
        }
Beispiel #15
0
        public void ChangeSpeed(float newValue)
        {
            speed = newValue;
            if (lysnc != 0)
            {
                Bass.BASS_ChannelRemoveSync(chan, lysnc);
            }

            chan = bass.ChangeSpeed(chan, SelectedSong.FilePath, newValue);

            if (lysnc != 0)
            {
                lysnc = Bass.BASS_ChannelSetSync(chan, BASSSync.BASS_SYNC_POS, endPos, LoopSync, (IntPtr)0);
            }

            if (this.PlayPause == "Pause")
            {
                Bass.BASS_ChannelPlay(chan, false);
            }
        }
Beispiel #16
0
        /// <summary>
        /// CUE Track End Procedure
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="stream"></param>
        /// <param name="data"></param>
        /// <param name="userData"></param>
        private void CueTrackEndProc(int handle, int stream, int data, IntPtr userData)
        {
            new Thread(() =>
            {
                Log.Debug("BASS: CueTrackEndProc of stream {0}", stream);

                if (MusicStreamMessage != null)
                {
                    MusicStreamMessage(this, StreamAction.Crossfading);
                }

                bool removed = Bass.BASS_ChannelRemoveSync(stream, handle);
                if (removed)
                {
                    Log.Debug("BassAudio: *** BASS_ChannelRemoveSync in CueTrackEndProc");
                }
            }
                       )
            {
                Name = "BASS CueEnd"
            }.Start();
        }
Beispiel #17
0
        private void SetRepeatRange(TimeSpan startTime, TimeSpan endTime)
        {
            if (repeatSyncId != 0)
            {
                Bass.BASS_ChannelRemoveSync(ActiveStreamHandle, repeatSyncId);
            }

            if ((endTime - startTime) > TimeSpan.FromMilliseconds(repeatThreshold))
            {
                long channelLength = Bass.BASS_ChannelGetLength(ActiveStreamHandle);
                long endPosition   = (long)((endTime.TotalSeconds / ChannelLength) * channelLength);
                repeatSyncId = Bass.BASS_ChannelSetSync(ActiveStreamHandle,
                                                        BASSSync.BASS_SYNC_POS,
                                                        (long)endPosition,
                                                        repeatSyncProc,
                                                        IntPtr.Zero);
                ChannelPosition = SelectionBegin.TotalSeconds;
            }
            else
            {
                ClearRepeatRange();
            }
        }
Beispiel #18
0
        protected override void OnLoopEndUpdated()
        {
            if (this.BassHandle.HasValue)
            {
                if (loopSyncHandle > 0)
                {
                    Bass.BASS_ChannelRemoveSync(this.BassHandle.Value, loopSyncHandle);
                    _mySyncProc = null;
                }

                _mySyncProc = new SYNCPROC(LoopEndReached);

                long end;
                if (this.LoopEnd == 0)
                {
                    end = Bass.BASS_ChannelSeconds2Bytes(this.BassHandle.Value, this.Length);
                }
                else
                {
                    end = Bass.BASS_ChannelSeconds2Bytes(this.BassHandle.Value, this.LoopEnd);
                }
                loopSyncHandle = Bass.BASS_ChannelSetSync(this.BassHandle.Value, BASSSync.BASS_SYNC_POS | BASSSync.BASS_SYNC_MIXTIME, end, _mySyncProc, IntPtr.Zero);
            }
        }
Beispiel #19
0
        public void Loop(Preset preset)
        {
            this.Pause();

            startPos = Bass.BASS_ChannelSeconds2Bytes(chan, preset.Begin);
            endPos   = Bass.BASS_ChannelSeconds2Bytes(chan, preset.End);

            LoopSync = new SYNCPROC(ProcSync);
            if (lysnc != 0)
            {
                Bass.BASS_ChannelRemoveSync(chan, lysnc);
            }

            lysnc = Bass.BASS_ChannelSetSync(chan, BASSSync.BASS_SYNC_POS, endPos, LoopSync, (IntPtr)0);

            long curPos = Bass.BASS_ChannelGetPosition(chan);

            if (curPos < startPos || curPos >= endPos)
            {
                Bass.BASS_ChannelSetPosition(chan, startPos, BASSMode.BASS_POS_BYTES);
            }

            this.Play();
        }
Beispiel #20
0
 private static void FadeCollect(int syncHandle, int channel, int data, IntPtr user)
 {
     Bass.BASS_ChannelRemoveSync(channel, syncHandle);
     Bass.BASS_StreamFree(channel);
     //Console.Write("Dealloc {0}", channel);
 }
Beispiel #21
0
        private void btnPlay_Click(object sender, EventArgs e)
        {
            updateTimer.Stop();
            Bass.BASS_StreamFree(stream);
            if (filename != string.Empty)
            {
                stream = Bass.BASS_StreamCreateFile(filename, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
                if (stream != 0)
                {
                    mslength           = (int)Bass.BASS_ChannelSeconds2Bytes(stream, 0.03);
                    deviceLatencyBytes = (int)Bass.BASS_ChannelSeconds2Bytes(stream, deviceLatencyMS / 1000.0);

                    myDSPAddr = new DSPPROC(MyDSPGain);
                    Bass.BASS_ChannelSetDSP(stream, myDSPAddr, IntPtr.Zero, 2);

                    if (WF2 != null && WF2.IsRendered)
                    {
                        WF2.SyncPlayback(stream);

                        long cuein  = WF2.GetMarker("CUE");
                        long cueout = WF2.GetMarker("END");

                        int cueinFrame  = WF2.Position2Frames(cuein);
                        int cueoutFrame = WF2.Position2Frames(cueout);

                        if (cuein >= 0)
                        {
                            Bass.BASS_ChannelSetPosition(stream, cuein);
                        }
                        if (cueout >= 0)
                        {
                            Bass.BASS_ChannelRemoveSync(stream, syncer);
                            syncer = Bass.BASS_ChannelSetSync(stream, BASSSync.BASS_SYNC_POS, cueout, sync, IntPtr.Zero);
                        }
                    }
                }

                if (stream != 0 && Bass.BASS_ChannelPlay(stream, false))
                {
                    textBox1.Text = "";
                    updateTimer.Start();

                    BASS_CHANNELINFO info = new BASS_CHANNELINFO();
                    Bass.BASS_ChannelGetInfo(stream, info);

                    textBox1.Text += "Info: " + info.ToString() + Environment.NewLine;

                    TAG_INFO tagInfo = new TAG_INFO();
                    if (BassTags.BASS_TAG_GetFromFile(stream, tagInfo))
                    {
                        textBoxAlbum.Text   = tagInfo.album;
                        textBoxArtist.Text  = tagInfo.artist;
                        textBoxTitle.Text   = tagInfo.title;
                        textBoxComment.Text = tagInfo.comment;
                        textBoxGenre.Text   = tagInfo.genre;
                        textBoxYear.Text    = tagInfo.year;
                        textBoxTrack.Text   = tagInfo.track;
                    }

                    btnStop.Enabled = true;
                    btnPlay.Enabled = false;
                }
            }
        }