Exemple #1
0
        //设置播放源文件
        public void SelectFile(string fileName)
        {
            this._fileName = fileName;

            if (_stream != 0)
            {
                _updateTimer.Stop();
                Bass.BASS_StreamFree(_stream);
            }

            // create the stream
            _stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN);
            // set dsp
            _myDSPAddr = new DSPPROC(MyDSPGainUnsafe);
            Bass.BASS_ChannelSetDSP(_stream, _myDSPAddr, IntPtr.Zero, 2);

            //if (_stream != 0)
            //{
            //    // get some channel info
            //    //info = new BASS_CHANNELINFO();
            //    //Bass.BASS_ChannelGetInfo(_stream, info);
            //    // get the tags...
            //    //tagInfo = new TAG_INFO(_fileName);
            //}

            GetWaveForm();

        }
Exemple #2
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;
                }
            }
        }