Exemplo n.º 1
0
        private void Encoder_Load(object sender, System.EventArgs e)
        {
            //BassNet.Registration("your email", "your regkey");

            if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, this.Handle))
            {
                BASS_INFO info = new BASS_INFO();
                Bass.BASS_GetInfo(info);
                Console.WriteLine(info.ToString());

                _wmaPlugIn = Bass.BASS_PluginLoad("basswma.dll");
                // all fine
                int[] rates = BassWma.BASS_WMA_EncodeGetRates(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_RATES_CBR);
                foreach (int rate in rates)
                {
                    this.comboBoxRate.Items.Add(rate);
                }
                this.comboBoxRate.SelectedIndex = 0;
            }
            else
            {
                MessageBox.Show(this, "Bass_Init error!");
            }

            // init your recording device (we use the default device)
            if (!Bass.BASS_RecordInit(-1))
            {
                MessageBox.Show(this, "Bass_RecordInit error!");
            }
        }
Exemplo n.º 2
0
        public void LoadSample(Sample sample)
        {
            if (sample.FileName == null)
            {
                return;
            }
            if (sample.FileName.EndsWith(".wma"))
            {
                sample.Channel = BassWma.BASS_WMA_StreamCreateFile(sample.FileName, 0L, 0L,
                                                                   BASSFlag.BASS_STREAM_DECODE |
                                                                   BASSFlag.BASS_SAMPLE_FLOAT);
            }
            else
            {
                sample.Channel = Bass.BASS_StreamCreateFile(sample.FileName, 0L, 0L,
                                                            BASSFlag.BASS_STREAM_DECODE |
                                                            BASSFlag.BASS_SAMPLE_FLOAT);
            }

            BassMix.BASS_Mixer_StreamAddChannel(SoundEffectMixerChannel, sample.Channel,
                                                BASSFlag.BASS_MIXER_PAUSE);
            Bass.BASS_ChannelSetSync(sample.Channel, BASSSync.BASS_SYNC_END, 0, endSync, IntPtr.Zero);

            //sample.Weight = 1;

            if (CurrentSample == null)
            {
                CurrentSample = sample;
            }
            SetLoop();
        }
Exemplo n.º 3
0
        // the recording callback
        private unsafe bool MyRecoring(int handle, IntPtr buffer, int length, IntPtr user)
        {
            // user will contain our encoding handle
            if (length > 0 && buffer != IntPtr.Zero)
            {
                if (checkBoxMonitor.Checked)
                {
                    monBuffer.Write(buffer, length);
                }

                if (!this.buttonStartRec.Enabled)
                {
                    // if recording started...write the data to the encoder
                    BassWma.BASS_WMA_EncodeWrite(user.ToInt32(), buffer, length);
                }
                // get and draw our live recording waveform
                WF.RenderRecording(buffer, length);
                //WF.RenderRecording();  // old style

                // get the rec level...
                int    maxL = 0;
                int    maxR = 0;
                short *data = (short *)buffer;
                for (int a = 0; a < length / 2; a++)
                {
                    // decide on L/R channel
                    if (a % 2 == 0)
                    {
                        // L channel
                        if (data[a] > maxL)
                        {
                            maxL = data[a];
                        }
                    }
                    else
                    {
                        // R channel
                        if (data[a] > maxR)
                        {
                            maxR = data[a];
                        }
                    }
                }
                // limit the maximum peak levels to 0bB = 32768
                // the peak levels will be int values, where 32768 = 0dB!
                if (maxL > 32768)
                {
                    maxL = 32768;
                }
                if (maxR > 32768)
                {
                    maxR = 32768;
                }

                this.BeginInvoke(new UpdateDelegate(UpdateDisplay), new object[] { maxL, maxR });
                // you might instead also use "this.Invoke(...)", which would call the delegate synchron!
            }
            return(true);            // always continue recording
        }
Exemplo n.º 4
0
 public override int GetListeners(string password)
 {
     if (this.IsConnected)
     {
         return(BassWma.BASS_WMA_EncodeGetClients(base.Encoder.EncoderHandle));
     }
     return(-1);
 }
Exemplo n.º 5
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.º 6
0
 private void EncodingDSPHandler(int handle, int channel, IntPtr buffer, int length, IntPtr user)
 {
     if (this._paused)
     {
         return;
     }
     if (base.EncoderHandle != 0)
     {
         if (!BassWma.BASS_WMA_EncodeWrite(base.EncoderHandle, buffer, length))
         {
             ThreadPool.QueueUserWorkItem(new WaitCallback(this.DoNotify));
         }
         try
         {
             this._byteSend += (long)length;
         }
         catch
         {
             this._byteSend = (long)length;
         }
     }
 }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Frees all resources used by the writer.
 /// </summary>
 public void Dispose() => BassWma.EncodeClose(_handle);
Exemplo n.º 9
0
 /// <summary>
 /// Write data from a float[].
 /// </summary>
 /// <param name="Buffer">float[] to write from.</param>
 /// <param name="Length">No of bytes to write, i.e. (No of floats) * 4.</param>
 public bool Write(float[] Buffer, int Length)
 {
     lock (_syncLock)
         return(BassWma.EncodeWrite(_handle, Buffer, Length));
 }
Exemplo n.º 10
0
        public void init()
        {
            if (WinPOP.init_ok)
            {
                return;
            }
            _myUserAgentPtr = Marshal.StringToHGlobalAnsi(_myUserAgent);

            //BassNet.Registration("your email", "your regkey");

            // check the version..
            try
            {
                if (Utils.HighWord(Bass.BASS_GetVersion()) != Bass.BASSVERSION)
                {
                    System.Windows.MessageBox.Show("Ошибка bass.dll");
                    while (true)
                    {
                        Thread.Sleep(5000);
                    }
                }
            }
            catch
            {
                System.Windows.MessageBox.Show("Ошибка bass.dll");
                while (true)
                {
                    Thread.Sleep(5000);
                }
            }

            // stupid thing here as well, just to demo...
            //string userAgent = Bass.BASS_GetConfigString(BASSConfig.BASS_CONFIG_NET_AGENT);

            Bass.BASS_SetConfigPtr(BASSConfig.BASS_CONFIG_NET_AGENT, _myUserAgentPtr);

            Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_PREBUF, 0); // so that we can display the buffering%
            Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_PLAYLIST, 1);

            if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
            {
                // Some words about loading add-ons:
                // In order to set an add-on option with BASS_SetConfig, we need to make sure, that the
                // library (in this case basswma.dll) is actually loaded!
                // However, an external library is dynamically loaded in .NET with the first call
                // to one of it's methods...
                // As BASS will only know about additional config options once the lib has been loaded,
                // we need to make sure, that the lib is loaded before we make the following call.
                // 1) Loading a lib manually :
                BassWma.LoadMe();                   // basswma.dll must be in same directory
                // 2) Using the BASS PlugIn system (recommended):
                //_wmaPlugIn = Bass.BASS_PluginLoad( "basswma.dll" );
                // 3) ALTERNATIVLY you might call any 'dummy' method to load the lib!
                //int[] cbrs = BassWma.BASS_WMA_EncodeGetRates(44100, 2, BASSWMAEncode.BASS_WMA_ENCODE_RATES_CBR);
                // now basswma.dll is loaded and the additional config options are available...

                if (Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_WMA_PREBUF, 0) == false)
                {
                    System.Windows.MessageBox.Show("Ошибка Bass_Init " + Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode()));
                }
                // we alraedy create the user callback methods...
                myStreamCreateURL = new DOWNLOADPROC(MyDownloadProc);
                WinPOP.init_ok    = true;
            }
            else
            {
                System.Windows.MessageBox.Show("Bass_Init error!");
            }
        }
Exemplo n.º 11
0
        public override bool Start(ENCODEPROC proc, IntPtr user, bool paused)
        {
            if (base.EncoderHandle != 0 || (proc != null && !this.SupportsSTDOUT))
            {
                return(false);
            }
            this._paused      = paused;
            this._encoderProc = null;
            this._byteSend    = 0L;
            BASSWMAEncode basswmaencode = BASSWMAEncode.BASS_WMA_ENCODE_DEFAULT;

            if (this.WMA_ForceStandard)
            {
                basswmaencode |= BASSWMAEncode.BASS_WMA_ENCODE_STANDARD;
            }
            else
            {
                if (this.WMA_UsePro)
                {
                    basswmaencode |= BASSWMAEncode.BASS_WMA_ENCODE_PRO;
                }
                if (this.WMA_Use24Bit)
                {
                    basswmaencode |= BASSWMAEncode.BASS_WMA_ENCODE_24BIT;
                    basswmaencode |= BASSWMAEncode.BASS_WMA_ENCODE_PRO;
                }
            }
            this._channel             = base.ChannelHandle;
            this.WMA_TargetNumChans   = base.ChannelNumChans;
            this.WMA_TargetSampleRate = base.ChannelSampleRate;
            if (base.InputFile != null)
            {
                this._channel = Bass.BASS_StreamCreateFile(base.InputFile, 0L, 0L, BASSFlag.BASS_STREAM_DECODE | (this.WMA_Use24Bit ? BASSFlag.BASS_SAMPLE_FLOAT : BASSFlag.BASS_DEFAULT));
                if (this._channel == 0)
                {
                    return(false);
                }
                if (this.WMA_Use24Bit)
                {
                    basswmaencode |= BASSWMAEncode.BASS_SAMPLE_FLOAT;
                }
            }
            else if (base.ChannelBitwidth == 32)
            {
                basswmaencode |= BASSWMAEncode.BASS_SAMPLE_FLOAT;
            }
            else if (base.ChannelBitwidth == 8)
            {
                basswmaencode |= BASSWMAEncode.BASS_SAMPLE_8BITS;
            }
            if (this.WMA_UseNetwork)
            {
                basswmaencode |= BASSWMAEncode.BASS_WMA_ENCODE_SCRIPT;
            }
            int bitrate = this.WMA_Bitrate * 1000;

            if (this.WMA_UseVBR && this.WMA_VBRQuality > 0 && this.WMA_VBRQuality <= 100)
            {
                bitrate = this.WMA_VBRQuality;
            }
            if (proc != null && !this.WMA_UseNetwork)
            {
                this._encoderProc   = proc;
                this._wmEncoderProc = new WMENCODEPROC(this.EncodingWMAHandler);
            }
            if (base.OutputFile == null)
            {
                if (this.WMA_UseNetwork && !this.WMA_UsePublish)
                {
                    if (this.WMA_MultiBitrate != null && this.WMA_MultiBitrate.Length != 0)
                    {
                        int[] array = new int[this.WMA_MultiBitrate.Length];
                        for (int i = 0; i < this.WMA_MultiBitrate.Length; i++)
                        {
                            array[i] = this.WMA_MultiBitrate[i] * 1000;
                        }
                        base.EncoderHandle = BassWma.BASS_WMA_EncodeOpenNetworkMulti(this.WMA_TargetSampleRate, this.WMA_TargetNumChans, basswmaencode, array, this.WMA_NetworkPort, this.WMA_NetworkClients);
                    }
                    else
                    {
                        if (this.WMA_MultiBitrate != null)
                        {
                            bitrate = this.WMA_MultiBitrate[0];
                        }
                        base.EncoderHandle = BassWma.BASS_WMA_EncodeOpenNetwork(this.WMA_TargetSampleRate, this.WMA_TargetNumChans, basswmaencode, bitrate, this.WMA_NetworkPort, this.WMA_NetworkClients);
                    }
                }
                else if (this.WMA_UseNetwork && this.WMA_UsePublish)
                {
                    if (this.WMA_MultiBitrate != null && this.WMA_MultiBitrate.Length > 1)
                    {
                        int[] array2 = new int[this.WMA_MultiBitrate.Length];
                        for (int j = 0; j < this.WMA_MultiBitrate.Length; j++)
                        {
                            array2[j] = this.WMA_MultiBitrate[j] * 1000;
                        }
                        base.EncoderHandle = BassWma.BASS_WMA_EncodeOpenPublishMulti(this.WMA_TargetSampleRate, this.WMA_TargetNumChans, basswmaencode, array2, this.WMA_PublishUrl, this.WMA_PublishUsername, this.WMA_PublishPassword);
                    }
                    else
                    {
                        base.EncoderHandle = BassWma.BASS_WMA_EncodeOpenPublish(this.WMA_TargetSampleRate, this.WMA_TargetNumChans, basswmaencode, bitrate, this.WMA_PublishUrl, this.WMA_PublishUsername, this.WMA_PublishPassword);
                    }
                }
                else if (proc != null)
                {
                    base.EncoderHandle = BassWma.BASS_WMA_EncodeOpen(this.WMA_TargetSampleRate, this.WMA_TargetNumChans, basswmaencode, bitrate, this._wmEncoderProc, user);
                }
            }
            else
            {
                base.EncoderHandle = BassWma.BASS_WMA_EncodeOpenFile(this.WMA_TargetSampleRate, this.WMA_TargetNumChans, basswmaencode, bitrate, base.OutputFile);
                if (base.TAGs != null)
                {
                    if (!string.IsNullOrEmpty(base.TAGs.title))
                    {
                        this.SetTag("Title", base.TAGs.title);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.artist))
                    {
                        this.SetTag("Author", base.TAGs.artist);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.album))
                    {
                        this.SetTag("WM/AlbumTitle", base.TAGs.album);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.albumartist))
                    {
                        this.SetTag("WM/AlbumArtist", base.TAGs.albumartist);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.year))
                    {
                        this.SetTag("WM/Year", base.TAGs.year);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.track))
                    {
                        this.SetTag("WM/TrackNumber", base.TAGs.track);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.disc))
                    {
                        this.SetTag("WM/PartOfSet", base.TAGs.disc);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.genre))
                    {
                        this.SetTag("WM/Genre", base.TAGs.genre);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.comment))
                    {
                        this.SetTag("Description", base.TAGs.comment);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.composer))
                    {
                        this.SetTag("WM/Composer", base.TAGs.composer);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.conductor))
                    {
                        this.SetTag("WM/Conductor", base.TAGs.conductor);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.lyricist))
                    {
                        this.SetTag("WM/Writer", base.TAGs.lyricist);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.remixer))
                    {
                        this.SetTag("WM/ModifiedBy", base.TAGs.remixer);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.producer))
                    {
                        this.SetTag("WM/Producer", base.TAGs.producer);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.encodedby))
                    {
                        this.SetTag("WM/EncodedBy", base.TAGs.encodedby);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.copyright))
                    {
                        this.SetTag("Copyright", base.TAGs.copyright);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.publisher))
                    {
                        this.SetTag("WM/Publisher", base.TAGs.publisher);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.bpm))
                    {
                        this.SetTag("WM/BeatsPerMinute", base.TAGs.bpm);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.grouping))
                    {
                        this.SetTag("WM/ContentGroupDescription", base.TAGs.grouping);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.rating))
                    {
                        this.SetTag("WM/Rating", base.TAGs.rating);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.mood))
                    {
                        this.SetTag("WM/Mood", base.TAGs.mood);
                    }
                    if (!string.IsNullOrEmpty(base.TAGs.isrc))
                    {
                        this.SetTag("WM/ISRC", base.TAGs.isrc);
                    }
                    if (base.TAGs.replaygain_track_peak >= 0f)
                    {
                        this.SetTag("replaygain_track_peak", base.TAGs.replaygain_track_peak.ToString("R", CultureInfo.InvariantCulture));
                    }
                    if (base.TAGs.replaygain_track_gain >= -60f && base.TAGs.replaygain_track_gain <= 60f)
                    {
                        this.SetTag("replaygain_track_gain", base.TAGs.replaygain_track_gain.ToString("R", CultureInfo.InvariantCulture) + " dB");
                    }
                }
            }
            if (base.EncoderHandle == 0)
            {
                return(false);
            }
            this._dspCallback = new DSPPROC(this.EncodingDSPHandler);
            this._dspHandle   = Bass.BASS_ChannelSetDSP(base.ChannelHandle, this._dspCallback, IntPtr.Zero, Bass.BASS_GetConfig(BASSConfig.BASS_CONFIG_ENCODE_PRIORITY));
            if (this._dspHandle == 0)
            {
                this.Stop();
                return(false);
            }
            if (base.InputFile != null)
            {
                Utils.DecodeAllData(this._channel, true);
            }
            this._channel = 0;
            return(base.EncoderHandle != 0);
        }
Exemplo n.º 12
0
        private void setup()
        {
            streamRef = 0;

            controller.RequestAction(QActionType.Resumed);

            int maxLoops = 4;

            for (int i = 0; (i < maxLoops) && (streamRef == 0); i++)
            {
                streamRef = Bass.BASS_StreamCreateURL(station.URL, 0, BASSFlag.BASS_STREAM_STATUS | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT, myStreamCreateURL, IntPtr.Zero);

                if (closing)
                {
                    controller.RequestAction(QActionType.Stop);
                    return;
                }

                if (streamRef == 0)
                {
                    isWMA     = true;
                    streamRef = BassWma.BASS_WMA_StreamCreateURL(station.URL, 0, 0, BASSFlag.BASS_STREAM_STATUS | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
                }

                if (closing)
                {
                    controller.RequestAction(QActionType.Stop);
                    return;
                }

                if (streamRef == 0 && i < maxLoops - 1)
                {
                    System.Threading.Thread.Sleep(500);
                }
            }

            if (streamRef == 0)
            {
                Radio.PlayingStation = null;
                controller.RequestAction(QActionType.RadioFailed);
                return;
            }

            setupChannelFromStream();

            if (Frequency != presumedFreq)
            {
                frequencyMismatchDelegate();
            }

            syncEvent = new SYNCPROC(MetaSync);
            Bass.BASS_ChannelSetSync(streamRef, BASSSync.BASS_SYNC_META, 0, syncEvent, IntPtr.Zero);
            Bass.BASS_ChannelSetSync(streamRef, BASSSync.BASS_SYNC_WMA_CHANGE, 0, syncEvent, IntPtr.Zero);

            myStreamCreateURL = new DOWNLOADPROC(MyDownloadProc);

            try
            {
                // might throw up on certains chars
                tagInfo = new TAG_INFO(station.URL);
            }
            catch
            {
            }

            prebuffer();

            buffered = true;

            Radio.PlayingStation  = station;
            controller.RadioTrack = null;

            readStreamTags();

            if (station.StreamType == StationStreamType.None)
            {
                setStationStreamType();
            }

            controller.RequestAction(QActionType.RadioStreamStarted);
        }
Exemplo n.º 13
0
 public void Dispose()
 {
     BassWma.EncodeClose(EncoderHandle);
 }
Exemplo n.º 14
0
 public void Write(IntPtr Buffer, int Length)
 {
     BassWma.EncodeWrite(EncoderHandle, Buffer, Length);
 }
Exemplo n.º 15
0
 public WmaFileWriter(string FilePath, int NoOfChannels = 2, int SampleRate = 44100, int BitRate = 128000)
 {
     EncoderHandle = BassWma.EncodeOpenFile(SampleRate, NoOfChannels, WMAEncodeFlags.Float, BitRate, FilePath);
 }
Exemplo n.º 16
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            Bass.BASS_StreamFree(_Stream);
            this.textBox1.Text = "";
            _url = this.comboBoxURL.Text;
            // test BASS_StreamCreateURL

            bool isWMA = false;

            if (_url != String.Empty)
            {
                this.textBox1.Text += "URL: " + _url + Environment.NewLine;
                // create the stream
                _Stream = Bass.BASS_StreamCreateURL(_url, 0, BASSFlag.BASS_STREAM_STATUS, myStreamCreateURL, IntPtr.Zero);
                if (_Stream == 0)
                {
                    // try WMA streams...
                    _Stream = BassWma.BASS_WMA_StreamCreateFile(_url, 0, 0, BASSFlag.BASS_DEFAULT);
                    if (_Stream != 0)
                    {
                        isWMA = true;
                    }
                    else
                    {
                        // error
                        this.statusBar1.Text = "ERROR...";
                        return;
                    }
                }
                _tagInfo = new TAG_INFO(_url);
                BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(_Stream);
                if (info.ctype == BASSChannelType.BASS_CTYPE_STREAM_WMA)
                {
                    isWMA = true;
                }
                // ok, do some pre-buffering...
                this.statusBar1.Text = "Buffering...";
                if (!isWMA)
                {
                    // display buffering for MP3, OGG...
                    while (true)
                    {
                        long len = Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_END);
                        if (len == -1)
                        {
                            break;                             // typical for WMA streams
                        }
                        // percentage of buffer filled
                        float progress = (
                            Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD) -
                            Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_CURRENT)
                            ) * 100f / len;

                        if (progress > 75f)
                        {
                            break;                             // over 75% full, enough
                        }

                        this.statusBar1.Text = String.Format("Buffering... {0}%", progress);
                    }
                }
                else
                {
                    // display buffering for WMA...
                    while (true)
                    {
                        long len = Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_WMA_BUFFER);
                        if (len == -1L)
                        {
                            break;
                        }
                        // percentage of buffer filled
                        if (len > 75L)
                        {
                            break;                             // over 75% full, enough
                        }

                        this.statusBar1.Text = String.Format("Buffering... {0}%", len);
                    }
                }

                // get the meta tags (manually - will not work for WMA streams here)
                string[] icy = Bass.BASS_ChannelGetTagsICY(_Stream);
                if (icy == null)
                {
                    // try http...
                    icy = Bass.BASS_ChannelGetTagsHTTP(_Stream);
                }
                if (icy != null)
                {
                    foreach (string tag in icy)
                    {
                        this.textBox1.Text += "ICY: " + tag + Environment.NewLine;
                    }
                }
                // get the initial meta data (streamed title...)
                icy = Bass.BASS_ChannelGetTagsMETA(_Stream);
                if (icy != null)
                {
                    foreach (string tag in icy)
                    {
                        this.textBox1.Text += "Meta: " + tag + Environment.NewLine;
                    }
                }
                else
                {
                    // an ogg stream meta can be obtained here
                    icy = Bass.BASS_ChannelGetTagsOGG(_Stream);
                    if (icy != null)
                    {
                        foreach (string tag in icy)
                        {
                            this.textBox1.Text += "Meta: " + tag + Environment.NewLine;
                        }
                    }
                }

                // alternatively to the above, you might use the TAG_INFO (see BassTags add-on)
                // This will also work for WMA streams here ;-)
                if (BassTags.BASS_TAG_GetFromURL(_Stream, _tagInfo))
                {
                    // and display what we get
                    this.textBoxAlbum.Text   = _tagInfo.album;
                    this.textBoxArtist.Text  = _tagInfo.artist;
                    this.textBoxTitle.Text   = _tagInfo.title;
                    this.textBoxComment.Text = _tagInfo.comment;
                    this.textBoxGenre.Text   = _tagInfo.genre;
                    this.textBoxYear.Text    = _tagInfo.year;
                }

                // set a sync to get the title updates out of the meta data...
                mySync = new SYNCPROC(MetaSync);
                Bass.BASS_ChannelSetSync(_Stream, BASSSync.BASS_SYNC_META, 0, mySync, IntPtr.Zero);
                Bass.BASS_ChannelSetSync(_Stream, BASSSync.BASS_SYNC_WMA_CHANGE, 0, mySync, IntPtr.Zero);

                // start recording...
                int rechandle = 0;
                if (Bass.BASS_RecordInit(-1))
                {
                    _byteswritten = 0;
                    myRecProc     = new RECORDPROC(MyRecoring);
                    rechandle     = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, myRecProc, IntPtr.Zero);
                }
                this.statusBar1.Text = "Playling...";
                // play the stream
                Bass.BASS_ChannelPlay(_Stream, false);
                // record the stream
                Bass.BASS_ChannelPlay(rechandle, false);
            }
        }
Exemplo n.º 17
0
        public void create_stream(string nm, bool moderad, Window header)
        {
            _Stream = 0;
            Bass.BASS_StreamFree(_Stream);
            _url = nm;

            // create the stream
            _Stream = Bass.BASS_StreamCreateURL(_url, 0, BASSFlag.BASS_STREAM_STATUS, myStreamCreateURL, IntPtr.Zero);
            if (_Stream == 0)
            {
                // try WMA streams...
                _Stream = BassWma.BASS_WMA_StreamCreateFile(_url, 0, 0, BASSFlag.BASS_DEFAULT);
                if (_Stream != 0)
                {
                    isWMA = true;
                }
                else
                {
                    if (moderad)
                    {
                        dialog.Show("Поток не поддерживается", header);
                    }
                    return;
                }
            }

            init_tag();

            if (header == null)
            {
                return;
            }

            // ok, do some pre-buffering...
            data.buff = "Buffering ...";
            if (!isWMA)
            {
                // display buffering for MP3, OGG...
                while (true)
                {
                    long len = Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_END);
                    if (len == -1)
                    {
                        break; // typical for WMA streams
                    }
                    // percentage of buffer filled
                    float progress = (
                        Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD) -
                        Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_CURRENT)
                        ) * 100f / len;

                    if (progress > 75f)
                    {
                        break; // over 75% full, enough
                    }

                    data.buff = String.Format("Buffering ... {0}%", progress);
                }
            }
            else
            {
                // display buffering for WMA...
                while (true)
                {
                    long len = Bass.BASS_StreamGetFilePosition(_Stream, BASSStreamFilePosition.BASS_FILEPOS_WMA_BUFFER);
                    if (len == -1L)
                    {
                        break;
                    }
                    // percentage of buffer filled
                    if (len > 75L)
                    {
                        break; // over 75% full, enough
                    }
                    data.buff = String.Format("Buffering... {0}%", len);
                }
            }
        }
Exemplo n.º 18
0
 public bool SetTag(string tag, string value)
 {
     return(base.EncoderHandle != 0 && BassWma.BASS_WMA_EncodeSetTag(base.EncoderHandle, tag, value));
 }
Exemplo n.º 19
0
 /// <summary>
 /// Creates a new instance of <see cref="WmaFileWriter"/>.
 /// </summary>
 /// <param name="FileName">The path to the file to write to.</param>
 /// <param name="WaveFormat"><see cref="WaveFormat"/> of the input data.</param>
 /// <param name="BitRate">BitRate of the written file.</param>
 public WmaFileWriter(string FileName, WaveFormat WaveFormat, int BitRate = 128000)
 {
     _handle = BassWma.EncodeOpenFile(WaveFormat.SampleRate, WaveFormat.Channels, ToWmaEncodeFlags(WaveFormat.Encoding, WaveFormat.BitsPerSample), BitRate, FileName);
 }
Exemplo n.º 20
0
        /// <summary>
        /// Open the song, specified in the Path property
        /// </summary>
        public void Open()
        {
            switch (Output)
            {
            case OutputMode.DirectSound:
                int newStreamHandle = Bass.BASS_StreamCreateFile(Path, 0, 0,
                                                                 BASSFlag.BASS_MUSIC_AUTOFREE | BASSFlag.BASS_MUSIC_FLOAT
                                                                 );
                if (Config.ReactorFade & _handle != 0)
                {
                    Bass.BASS_ChannelSetAttribute(Handle, BASSAttribute.BASS_ATTRIB_VOL, 0);
                }
                if (newStreamHandle != 0)
                {
                    Stopped = false;
                    _handle = newStreamHandle;
                    OnPropertyChanged("StreamStatus");

                    OnPropertyChanged("ActiveStreamHandle");
                    Valid = true;
                    ended = false;
                }
                else
                {
                    ErrorMessage = "Stream handle returned is zero ";
                    OnPropertyChanged("Error");
                }

                break;

            case OutputMode.WASAPI:
                break;

            case OutputMode.ASIO:
                break;

            case OutputMode.NetStream:
                newStreamHandle = Bass.BASS_StreamCreateURL(Path, 0, BASSFlag.BASS_STREAM_STATUS, null, IntPtr.Zero);
                if (newStreamHandle == 0)
                {
                    // try WMA streams...
                    newStreamHandle = BassWma.BASS_WMA_StreamCreateFile(Path, 0, 0, BASSFlag.BASS_DEFAULT);
                    if (newStreamHandle != 0)
                    {
                        isWMA = true;
                    }
                    else
                    {
                        // error
                        ErrorMessage = "Stream handle returned is zero ";
                        OnPropertyChanged("Error");
                    }
                }
                if (Config.ReactorFade & _handle != 0)
                {
                    Bass.BASS_ChannelSetAttribute(Handle, BASSAttribute.BASS_ATTRIB_VOL, 0);
                }
                if (newStreamHandle != 0)
                {
                    Stopped = false;
                    _handle = newStreamHandle;
                    OnPropertyChanged("StreamStatus");
                    OnPropertyChanged("NetStreamHandle");
                    Valid = true;
                    ended = false;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException("_output");
            }
        }