Esempio n. 1
0
        private void buttonStartRec_Click(object sender, System.EventArgs e)
        {
            this.buttonStartRec.Enabled = false;
            this.labelRec.Text          = "Recording...";

            // start recording paused
            _myRecProc = new RECORDPROC(MyRecoring);
            _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, new IntPtr(_encHandle));

            // needs 'lame.exe' !
            // the recorded data will be written to a file called rectest.mp3
            // create the encoder...192kbps, stereo
            // MP3 encoder setup
            lame                       = new EncoderLAME(_recHandle);
            lame.InputFile             = null;  //STDIN
            lame.OutputFile            = "rectest.mp3";
            lame.LAME_Bitrate          = (int)EncoderLAME.BITRATE.kbps_192;
            lame.LAME_Mode             = EncoderLAME.LAMEMode.Default;
            lame.LAME_TargetSampleRate = (int)EncoderLAME.SAMPLERATE.Hz_44100;
            lame.LAME_Quality          = EncoderLAME.LAMEQuality.Quality;

            monBuffer.Clear();
            checkBoxMonitor.Checked = false;

            // create a live recording WaveForm
            WF = new WaveForm();
            WF.FrameResolution = 0.01f;             // 10ms are nice
            // start a live recording waveform with 5sec. init size and 2sec. next size
            WF.RenderStartRecording(_recHandle, 5f, 2f);

            // really start recording
            lame.Start(null, IntPtr.Zero, false);
            Bass.BASS_ChannelPlay(_recHandle, false);
        }
Esempio n. 2
0
        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();
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Initialize MP3 encoding whith LAME
        /// </summary>
        /// <param name="_rechandle"></param>
        /// <returns></returns>
        private bool StartLameEncoding(int _rechandle)
        {
            /* Voir si en utilisant "lameEncoder.OutputFile =  outFile"
             * on pourrait créer un fichier au lieu d'un buffer
             * */
            _lameMemBuffer.Clear();
            _LameEncProc = new ENCODEPROC(LameEncCallback); // Callback function

            lameEncoder = new EncoderLAME(_rechandle);


            if (lameEncoder.EncoderExists == false)
            {
                Console.Write("Encoder does not exists ?\r");
            }


            lameEncoder.InputFile = null;       //STDIN

            if (bSaveToDisk)
            {
                lameEncoder.OutputFile = strSaveFile;
            }
            else
            {
                lameEncoder.OutputFile = null;  //STDOUT - adding file name will prevent the callback from working instead will saving to disk
            }
            lameEncoder.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_64;
            lameEncoder.LAME_Mode    = EncoderLAME.LAMEMode.Default;
            lameEncoder.LAME_Quality = EncoderLAME.LAMEQuality.Quality;

            bool bret = lameEncoder.Start(_LameEncProc, IntPtr.Zero, false);

            BASSError txt = Bass.BASS_ErrorGetCode();

            Msg(txt.ToString());

            return(bret);
        }
Esempio n. 4
0
        private void buttonStart_Click(object sender, System.EventArgs e)
        {
            asio = new BassAsioHandler(true, 0, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_16BIT, 44100);

            // set a mirror on output channel 0 (for monitoring)
            asio.SetMirror(0);
            this.checkBoxMonitor.Checked = true;

            // start ASIO (actually starts recording/playing)
            BASS_ASIO_INFO info = BassAsio.BASS_ASIO_GetInfo();
            bool           ok   = asio.Start(info.bufmax);

            if (!ok)
            {
                MessageBox.Show("Could not start ASIO : " + BassAsio.BASS_ASIO_ErrorGetCode().ToString());
            }

            // now setup the encoder on the provided asio bass channel (which will be created by the above SetFullDuplex call)
            if (radioButtonLAME.Checked)
            {
                lame              = new EncoderLAME(asio.InputChannel);
                lame.InputFile    = null;               //STDIN
                lame.OutputFile   = "test.mp3";
                lame.LAME_Bitrate = (int)EncoderLAME.BITRATE.kbps_128;
                lame.LAME_Mode    = EncoderLAME.LAMEMode.Default;
                lame.LAME_Quality = EncoderLAME.LAMEQuality.Quality;
                lame.Start(null, IntPtr.Zero, false);
                enc = lame;
            }
            else if (radioButtonOGG.Checked)
            {
                ogg                    = new EncoderOGG(asio.InputChannel);
                ogg.InputFile          = null;          //STDIN
                ogg.OutputFile         = "test.ogg";
                ogg.OGG_UseQualityMode = true;
                ogg.OGG_Quality        = 4.0f;
                ogg.Start(null, IntPtr.Zero, false);
                enc = ogg;
            }
            else if (radioButtonAAC.Checked)
            {
                aac              = new EncoderNeroAAC(asio.InputChannel);
                aac.InputFile    = null;                //STDIN
                aac.OutputFile   = "test.mp4";
                aac.NERO_Bitrate = 64;
                aac.Start(null, IntPtr.Zero, false);
                enc = aac;
            }
            else if (radioButtonWAVE.Checked)
            {
                // writing 16-bit wave file here (even if we use a float asio channel)
                wav            = new EncoderWAV(asio.InputChannel);
                wav.InputFile  = null;                 // STDIN
                wav.OutputFile = "test.wav";
                wav.Start(null, IntPtr.Zero, false);
                enc = wav;
            }

            this.buttonStart.Enabled = false;

            // display the level
            plm               = new DSP_PeakLevelMeter(asio.InputChannel, 0);
            plm.UpdateTime    = 0.1f;          // 100ms
            plm.Notification += new EventHandler(plm_Notification);
        }
Esempio n. 5
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);
            }
        }