//设置播放源文件 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(); }
public bool Start() { if (this.IsAssigned) { return(true); } this._dspHandle = Bass.BASS_ChannelSetDSP(this._channel, this._dspProc, this._user, this._dspPriority); this.OnStarted(); return(this._dspHandle != 0); }
private void button1_Click(object sender, EventArgs e) { _updateTimer.Stop(); Bass.BASS_StreamFree(stream); if (favorites.Count > 0 && playFavorites.Checked) { song = int.Parse(favorites[favoriteIndex]); favoriteIndex++; if (favoriteIndex >= favorites.Count) { favoriteIndex = 0; } } else { song = rand.Next(1, 189357); } isFavorite.Checked = isFavorited(song); using (var client = new WebClient()) { client.DownloadFile($@"https://api.modarchive.org/downloads.php?moduleid={song}", "song.tmp"); } lblSong.Text = $"Mod Archive #{song}"; lblSong.Tag = song; stream = Bass.BASS_StreamCreateFile(@"song.tmp", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN); myDSPAddr = new DSPPROC(MyDSPGainUnsafe); Bass.BASS_ChannelSetDSP(stream, myDSPAddr, IntPtr.Zero, 2); Bass.BASS_ChannelPlay(stream, true); _updateTimer.Start(); }
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; } } }
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); }
private void ReAssign(int oldChannel, int newChannel) { Bass.BASS_ChannelRemoveDSP(oldChannel, this._dspHandle); this._dspHandle = Bass.BASS_ChannelSetDSP(newChannel, this._dspProc, this._user, this._dspPriority); }