Exemple #1
0
        /// <summary>
        /// Stop Lame encoding
        /// </summary>
        /// <returns></returns>
        private byte[] StopLameEncoding()
        {
            lameEncoder.Stop();

            // now you might copy your dynamic arraylist to a flat byte[]
            return((byte[])_lameMemBuffer.ToArray(typeof(byte)));
        }
        public async void SaveToFile(string file, Action finished)
        {
            await Task.Factory.StartNew(() =>
            {
                //从文件中读取解码流
                int strm = Bass.BASS_StreamCreateFile(_file, 0, 0, BASSFlag.BASS_STREAM_DECODE);
                //从strm解码流中创建FX效果器
                strm = BassFx.BASS_FX_TempoCreate(strm, BASSFlag.BASS_STREAM_DECODE);

                //为效果器设置参数  Pitch&Speed
                if (_Pitch != -1024)
                {
                    Bass.BASS_ChannelSetAttribute(strm, BASSAttribute.BASS_ATTRIB_TEMPO_PITCH, _Pitch);
                }
                if (_Speed != -1024)
                {
                    Bass.BASS_ChannelSetAttribute(strm, BASSAttribute.BASS_ATTRIB_TEMPO, _Speed);
                }

                //初始化编码器
                EncoderLAME l           = new EncoderLAME(strm);
                l.InputFile             = null;                                 //STDIN
                l.OutputFile            = file;                                 //输出文件路径
                l.LAME_Bitrate          = (int)EncoderLAME.BITRATE.kbps_128;    //比特率
                l.LAME_Mode             = EncoderLAME.LAMEMode.Default;         //默认模式
                l.LAME_Quality          = EncoderLAME.LAMEQuality.Quality;      //高品质
                l.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_44100; //44100码率

                //解码流开始(并不是播放,也不会有声音输出)
                Bass.BASS_ChannelPlay(strm, false);
                //开始编码
                l.Start(null, IntPtr.Zero, false);

                byte[] encBuffer = new byte[65536]; // our dummy encoder buffer
                while (Bass.BASS_ChannelIsActive(strm) == BASSActive.BASS_ACTIVE_PLAYING)
                {
                    // getting sample data will automatically feed the encoder
                    int len = Bass.BASS_ChannelGetData(strm, encBuffer, encBuffer.Length);
                }
                l.Stop();  // finish
                Bass.BASS_StreamFree(strm);
                finished();
            });
        }
Exemple #3
0
 private void buttonStopRec_Click(object sender, System.EventArgs e)
 {
     Bass.BASS_ChannelStop(_recHandle);
     lame.Stop();
     this.buttonStartRec.Enabled = true;
     this.labelRec.Text          = "Recording stopped!";
     // stop the live recording waveform
     if (WF != null)
     {
         WF.RenderStopRecording();
         //DrawWave();
         // or now draw the wole wave form...
         // Note: to total length is always up to how it was initialized using WF.RenderStartRecording(_recHandle, 5, 2);
         //       This means it is either 5, 7, 9, 11,... etc. seconds long
         //       This is why sometimes the wave form doesn't fill the full pictureBox!
         this.pictureBoxLiveWave.BackgroundImage = WF.CreateBitmap(this.pictureBoxLiveWave.Width, this.pictureBoxLiveWave.Height, -1, -1, true);
     }
     if (checkBoxMonitor.Checked)
     {
         checkBoxMonitor.Checked = false;
     }
 }
Exemple #4
0
        private void convertWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (files.Count > 0)
            {
                Track t             = files.First();
                int   convertStream = 20;
                if (!Program.mainWindow.LoadStream(t.filename, out convertStream, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_MUSIC_DECODE))
                {
                    continue;
                }

                if (Bass.BASS_ErrorGetCode() == 0 && t.length > 0)
                {
                    EncoderLAME l = new EncoderLAME(convertStream);
                    l.InputFile = null;
                    string tryName = Path.GetFileNameWithoutExtension(t.filename) + ".mp3";
                    int    num     = 0;
                    while (File.Exists(Path.Combine(outputPath, tryName)))
                    {
                        tryName = Path.GetFileNameWithoutExtension(t.filename) + "_" + num + ".mp3";
                        num++;
                    }
                    l.OutputFile   = Path.Combine(outputPath, tryName);
                    l.LAME_Bitrate = currentBitrate;
                    l.LAME_Mode    = EncoderLAME.LAMEMode.Default;
                    l.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
                    //if(!Un4seen.Bass.AddOn.Tags.BassTags.BASS_TAG_GetFromFile(convertStream, l.TAGs)) Console.WriteLine("no tags");
                    l.TAGs = Un4seen.Bass.AddOn.Tags.BassTags.BASS_TAG_GetFromFile(t.filename);
                    if (Bass.BASS_ErrorGetCode() != 0)
                    {
                        Console.WriteLine(Bass.BASS_ErrorGetCode());
                    }
                    l.Start(null, IntPtr.Zero, false);
                    byte[] encBuffer = new byte[65536];
                    while (Bass.BASS_ChannelIsActive(convertStream) == BASSActive.BASS_ACTIVE_PLAYING)
                    {
                        // getting sample data will automatically feed the encoder
                        int len = Bass.BASS_ChannelGetData(convertStream, encBuffer, encBuffer.Length);
                        convertWorker.ReportProgress((int)((float)Bass.BASS_ChannelGetPosition(convertStream) / (float)Bass.BASS_ChannelGetLength(convertStream) * 100));
                        if (convertWorker.CancellationPending)
                        {
                            break;
                        }
                    }
                    l.Stop();  // finish
                    Bass.BASS_StreamFree(convertStream);
                    if (convertWorker.CancellationPending)
                    {
                        File.Delete(l.OutputFile);
                    }
                }
                else
                {
                    MessageBox.Show("Error converting: " + Bass.BASS_ErrorGetCode() + Environment.NewLine + t.filename);
                }
                if (convertWorker.CancellationPending)
                {
                    break;
                }
                files.RemoveAt(0);
                convertList.Invoke((MethodInvoker) delegate
                {
                    convertList.Items.RemoveAt(0);
                });
                convertWorker.ReportProgress(0);
            }
        }