Exemplo n.º 1
0
 public override bool Stop()
 {
     if (this._dspHandle != 0)
     {
         Bass.BASS_ChannelRemoveDSP(base.ChannelHandle, this._dspHandle);
         this._dspHandle   = 0;
         this._dspCallback = null;
     }
     if (base.EncoderHandle != 0)
     {
         BassWma.BASS_WMA_EncodeClose(base.EncoderHandle);
         base.EncoderHandle  = 0;
         this._wmEncoderProc = null;
         this._encoderProc   = null;
     }
     this._byteSend = 0L;
     return(true);
 }
Exemplo n.º 2
0
        private void buttonEncode_Click(object sender, System.EventArgs e)
        {
            buttonPlaySource.Enabled = false;
            this.label1.Text         = "";
            Bass.BASS_StreamFree(_stream);
            if (_fileName != String.Empty)
            {
                this.label1.Text = "Encoding started...";
                // output will be placed to out bin directory
                _fileNameOutput = Path.Combine(Application.StartupPath, Path.ChangeExtension(Path.GetFileName(_fileName), ".wma"));
                // create the encoder...
                _encHandle = BassWma.BASS_WMA_EncodeOpenFile(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT, (int)this.comboBoxRate.SelectedItem, _fileNameOutput);
                // create the stream
                _stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_STREAM_DECODE);
                // update the tags
                _tagInfo = new TAG_INFO(_fileName);
                // now we want to copy our tags from the source to the new destination file...
                if (BassTags.BASS_TAG_GetFromFile(_stream, _tagInfo))
                {
                    bool ok = true;
                    // and set the tags in our output file as well...
                    if (_tagInfo.album != String.Empty)
                    {
                        ok &= BassWma.BASS_WMA_EncodeSetTag(_encHandle, "WM/AlbumTitle", _tagInfo.album);
                    }
                    if (_tagInfo.artist != String.Empty)
                    {
                        ok &= BassWma.BASS_WMA_EncodeSetTag(_encHandle, "Author", _tagInfo.artist);
                    }
                    if (_tagInfo.comment != String.Empty)
                    {
                        ok &= BassWma.BASS_WMA_EncodeSetTag(_encHandle, "Description", _tagInfo.comment);
                    }
                    if (_tagInfo.composer != String.Empty)
                    {
                        ok &= BassWma.BASS_WMA_EncodeSetTag(_encHandle, "WM/Composer", _tagInfo.composer);
                    }
                    if (_tagInfo.copyright != String.Empty)
                    {
                        ok &= BassWma.BASS_WMA_EncodeSetTag(_encHandle, "Copyright", _tagInfo.copyright);
                    }
                    if (_tagInfo.encodedby != String.Empty)
                    {
                        ok &= BassWma.BASS_WMA_EncodeSetTag(_encHandle, "WM/EncodedBy", _tagInfo.encodedby);
                    }
                    if (_tagInfo.genre != String.Empty)
                    {
                        ok &= BassWma.BASS_WMA_EncodeSetTag(_encHandle, "WM/Genre", _tagInfo.genre);
                    }
                    if (_tagInfo.publisher != String.Empty)
                    {
                        ok &= BassWma.BASS_WMA_EncodeSetTag(_encHandle, "WM/Publisher", _tagInfo.publisher);
                    }
                    if (_tagInfo.title != String.Empty)
                    {
                        ok &= BassWma.BASS_WMA_EncodeSetTag(_encHandle, "Title", _tagInfo.title);
                    }
                    if (_tagInfo.track != String.Empty)
                    {
                        ok &= BassWma.BASS_WMA_EncodeSetTag(_encHandle, "WM/TrackNumber", _tagInfo.track);
                    }
                    if (_tagInfo.year != String.Empty)
                    {
                        ok &= BassWma.BASS_WMA_EncodeSetTag(_encHandle, "WM/Year", _tagInfo.year);
                    }
                }
                // finish setting tags is no longer needed!

                // encode the data
                while (Bass.BASS_ChannelIsActive(_stream) == BASSActive.BASS_ACTIVE_PLAYING)
                {
                    // get the decoded sample data
                    int len = Bass.BASS_ChannelGetData(_stream, _encBuffer, 65536);
                    // write the data to the encoder
                    BassWma.BASS_WMA_EncodeWrite(_encHandle, _encBuffer, len);

                    long total = Bass.BASS_ChannelGetLength(_stream);
                    long pos   = Bass.BASS_ChannelGetPosition(_stream);
                    this.label1.Text = String.Format("Encoding : {0:P}", pos / (float)total);
                    this.label1.Refresh();
                }
                // finish
                BassWma.BASS_WMA_EncodeClose(_encHandle);
                Bass.BASS_StreamFree(_stream);
                this.label1.Text         = "Encoding finished!";
                buttonPlaySource.Enabled = true;
            }
        }