public static void LoadAudio(AudioStream audioStream) { // abort if audio data already loaded if (audioStream.IsAudioLoaded()) { return; } AudioDataHelper.LoadAudioData(audioStream); var channel = Bass.BASS_StreamCreateFile(audioStream.AudioData.DataPointer, 0, audioStream.AudioData.Data.Length, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN); audioStream.AddChannel(channel); if (audioStream.ChannelId == 0) { throw new Exception("Cannot load " + audioStream.Filename + ". Error code: " + Bass.BASS_ErrorGetCode()); } // DebugHelper.WriteLine("Creating reverse FX stream " + audioStream.Description + "..."); audioStream.AddChannel(BassFx.BASS_FX_ReverseCreate(audioStream.ChannelId, 1, BASSFlag.BASS_STREAM_DECODE)); if (audioStream.ChannelId == 0) { throw new Exception("Cannot load " + audioStream.Filename + ". Error code: " + Bass.BASS_ErrorGetCode()); } Bass.BASS_ChannelSetAttribute(audioStream.ChannelId, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, (float)BASSFXReverse.BASS_FX_RVS_FORWARD); // DebugHelper.WriteLine("Creating tempo FX stream " + audioStream.Description + "..."); audioStream.AddChannel(BassFx.BASS_FX_TempoCreate(audioStream.ChannelId, BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_STREAM_DECODE)); if (audioStream.ChannelId == 0) { throw new Exception("Cannot load " + audioStream.Filename + ". Error code: " + Bass.BASS_ErrorGetCode()); } // DebugHelper.WriteLine("Calculating track length " + audioStream.Description + "..."); audioStream.Length = Bass.BASS_ChannelGetLength(audioStream.ChannelId); audioStream.DefaultSampleRate = GetSampleRate(audioStream.ChannelId); SetReplayGain(audioStream); SetPosition(audioStream, 0); }
public void OpenFile(string filePath) { Unload(); streamHandle = Bass.CreateStream(filePath, Flags: BassFlags.Decode | BassFlags.Prescan); activeHandle = BassFx.TempoCreate(streamHandle, BassFlags.FxFreeSource); syncHandle = Bass.ChannelSetSync(activeHandle, SyncFlags.End, 0, SyncProcedureEndStream); Bass.ChannelSetAttribute(activeHandle, ChannelAttribute.TempoUseQuickAlgorithm, 1); ApplyEffects(); status = PlayerStatus.FileLoaded; }
void Load_Sound(string File_Name = "") { Location_S.Value = 0; Location_T.Text = "00:00"; int StreamHandle; StreamHandle = Bass.BASS_StreamCreateFile(File_Name, 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_LOOP); Stream = BassFx.BASS_FX_TempoCreate(StreamHandle, BASSFlag.BASS_FX_FREESOURCE); Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, (float)Volume_S.Value / 100); Bass.BASS_ChannelSetDevice(Stream, Video_Mode.Sound_Device); Location_S.Maximum = Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetLength(Stream, BASSMode.BASS_POS_BYTES)); Bass.BASS_ChannelPlay(Stream, true); }
private void SimpleFX_Load(object sender, System.EventArgs e) { if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_SPEAKERS, this.Handle)) { // all ok // load BASS_FX BassFx.BASS_FX_GetVersion(); } else { MessageBox.Show(this, "Bass_Init error!"); } }
public void Play(string id, float volume = 1, float speed = 1) { if (_sounds.TryGetValue(id, out var sound)) { var s = Bass.BASS_StreamCreateFile(sound, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_FX_FREESOURCE); //sound, 0, 0, BASSFlag.BASS_STREAM_AUTOFREE); s = BassFx.BASS_FX_TempoCreate(s, BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_STREAM_AUTOFREE | BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_MUSIC_AUTOFREE); Bass.BASS_ChannelSetAttribute(s, BASSAttribute.BASS_ATTRIB_VOL, volume); Bass.BASS_ChannelPlay(s, false); } }
/// <summary> /// 曲全体のテンポを取得する /// </summary> /// <returns>テンポ値</returns> /// <remarks>テンポ値の範囲は70-300</remarks> public float GetTempo() { fTempo = BassFx.BASS_FX_BPM_DecodeGet( this.hBassStream, 0, nTotalSeconds, (300 << 16) + 70, // MAX BPM=320, MIN BPM=70 //0, BASSFXBpm.BASS_FX_BPM_DEFAULT, //BASSFXBpm.BASS_FX_BPM_MULT2, null, IntPtr.Zero); return(fTempo); }
/// <summary> /// 曲の一部分のテンポを取得する /// </summary> /// <param name="startSec">開始位置</param> /// <param name="endSec">終了位置</param> /// <returns>テンポ値</returns> /// <remarks>テンポ値の範囲は70-300</remarks> public float GetTempo(double startSec, double endSec) { fTempo = BassFx.BASS_FX_BPM_DecodeGet( this.hBassStream, startSec, endSec, (300 << 16) + 70, // MAX BPM=320, MIN BPM=70 //0, BASSFXBpm.BASS_FX_BPM_DEFAULT, //BASSFXBpm.BASS_FX_BPM_MULT2, null, IntPtr.Zero); return(fTempo); }
public override void Connect(IBassStreamComponent previous) { this.Rate = previous.Rate; this.Channels = previous.Channels; this.ChannelHandle = BassFx.TempoCreate(previous.ChannelHandle, previous.Flags); if (this.ChannelHandle == 0) { BassUtils.Throw(); } if (this.IsActive) { this.Update(); } }
private void PlaySong(Song s) { if (s == null) { return; } if (_channel != 0) { StopSong(); } if (settings.AudioDevice == 0) { MessageBox.Show("オーディオデバイスを設定してください。"); SongsList.SelectedIndex = -1; OpenSettings(null, null); return; } Bass.BASS_SetDevice(settings.AudioDevice); Bass.BASS_Init(settings.AudioDevice, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); _channel = Bass.BASS_StreamCreateFile(s.AudioPath, 0L, 0L, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE); _channel = BassFx.BASS_FX_TempoCreate(_channel, BASSFlag.BASS_DEFAULT); _playing = s; if (_channel == 0) { return; } if (_isDoubleTime) { ToDoubleTime(null, null); } if (_isNightcore) { ToNightcore(null, null); } _timer.Start(); ChangeVolume(null, null); Bass.BASS_ChannelPlay(_channel, false); PlayingStatus.IsEnabled = true; PlayingStatus.ToolTip = "曲の再生を一時停止します。"; PlayingStatus.Content = ""; PlayingTitle.Text = s.Title; PlayingArtist.Text = s.Artist; SongsList.ScrollIntoView(s); }
public TrackBass(Stream data, bool quick = false) { PendingActions.Enqueue(() => { Preview = quick; if (data == null) { throw new ArgumentNullException(nameof(data)); } //encapsulate incoming stream with async buffer if it isn't already. dataStream = data as AsyncBufferStream ?? new AsyncBufferStream(data, quick ? 8 : -1); var procs = new DataStreamFileProcedures(dataStream); BassFlags flags = Preview ? 0 : BassFlags.Decode | BassFlags.Prescan; activeStream = Bass.CreateStream(StreamSystem.NoBuffer, flags, procs.BassProcedures, IntPtr.Zero); if (!Preview) { // We assign the BassFlags.Decode streams to the device "bass_nodevice" to prevent them from getting // cleaned up during a Bass.Free call. This is necessary for seamless switching between audio devices. // Further, we provide the flag BassFlags.FxFreeSource such that freeing the activeStream also frees // all parent decoding streams. const int bass_nodevice = 0x20000; Bass.ChannelSetDevice(activeStream, bass_nodevice); tempoAdjustStream = BassFx.TempoCreate(activeStream, BassFlags.Decode | BassFlags.FxFreeSource); Bass.ChannelSetDevice(activeStream, bass_nodevice); activeStream = BassFx.ReverseCreate(tempoAdjustStream, 5f, BassFlags.Default | BassFlags.FxFreeSource); Bass.ChannelSetAttribute(activeStream, ChannelAttribute.TempoUseQuickAlgorithm, 1); Bass.ChannelSetAttribute(activeStream, ChannelAttribute.TempoOverlapMilliseconds, 4); Bass.ChannelSetAttribute(activeStream, ChannelAttribute.TempoSequenceMilliseconds, 30); } Length = Bass.ChannelBytes2Seconds(activeStream, Bass.ChannelGetLength(activeStream)) * 1000; float frequency; Bass.ChannelGetAttribute(activeStream, ChannelAttribute.Frequency, out frequency); initialFrequency = frequency; bitrate = (int)Bass.ChannelGetAttribute(activeStream, ChannelAttribute.Bitrate); isLoaded = true; OnLoaded?.Invoke(this); }); InvalidateState(); }
public void BassInit() { if (Global.EngineOnline) { //eq.intializeEQ(); foreach (FxItem i in Stack.Children) { i.Direct2Def(); } BassFx.BASS_FX_GetVersion(); BassEngine engine = BassEngine.Instance; engine.PropertyChanged += PropertyChanged; } }
public void Load(string file) { _file = file; decode = Bass.BASS_StreamCreateFile(file, 0L, 0L, BASSFlag.BASS_STREAM_DECODE); stream = BassFx.BASS_FX_TempoCreate(decode, BASSFlag.BASS_SAMPLE_FLOAT); Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_VOL, _Vol); if (_Pitch != -1024) { Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_TEMPO_PITCH, _Pitch); } if (_Speed != -1024) { Bass.BASS_ChannelSetAttribute(stream, BASSAttribute.BASS_ATTRIB_TEMPO, _Speed); } }
protected int GetHandle(string filepath) { int rawHandle = Bass.BASS_StreamCreateFile(filepath, 0, 0, BASSFlag.BASS_STREAM_DECODE); if (rawHandle == 0) { throw new ArgumentException("cannot create a stream."); } int tempoHandle = BassFx.BASS_FX_TempoCreate(rawHandle, BASSFlag.BASS_FX_FREESOURCE); if (tempoHandle == 0) { throw new ArgumentException("cannot create a stream."); } return(tempoHandle); }
private void openfile_FileOk(object sender, CancelEventArgs e) { if (openfile.FileName != String.Empty) { audioPath = openfile.FileName; fileName.Text = audioPath; playButton.Enabled = true; saveButton.Enabled = true; Bass.BASS_StreamFree(audioStream); Bass.BASS_StreamFree(fxStream); audioStream = Bass.BASS_StreamCreateFile(audioPath, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN); if (audioStream != 0) { fxStream = BassFx.BASS_FX_TempoCreate(audioStream, BASSFlag.BASS_FX_FREESOURCE); if (fxStream != 0) { // Вешаем эффекты до воиспроизведения, чтобы не было задержки distortion = Bass.BASS_ChannelSetFX(fxStream, BASSFXType.BASS_FX_BFX_DISTORTION, -4); BASS_BFX_DISTORTION dist = new BASS_BFX_DISTORTION(); dist.fDrive = distAmount.Value; dist.fDryMix = 5.0f; dist.fWetMix = distAmount.Value / 3.0f; dist.fFeedback = -0.5f; dist.fVolume = 0.1f; Bass.BASS_FXSetParameters(distortion, dist); // -- bassboost = Bass.BASS_ChannelSetFX(fxStream, BASSFXType.BASS_FX_DX8_PARAMEQ, -4); BASS_DX8_PARAMEQ eq = new BASS_DX8_PARAMEQ(); eq.fBandwidth = 24; eq.fCenter = 80; eq.fGain = bassAmount.Value; Bass.BASS_FXSetParameters(bassboost, eq); bassboost2 = Bass.BASS_ChannelSetFX(fxStream, BASSFXType.BASS_FX_DX8_PARAMEQ, -4); Bass.BASS_FXSetParameters(bassboost2, eq); return; } } MessageBox.Show(this, "Чот нихуя"); } }
internal AudioTrackBass(Stream data, bool quick = false, bool loop = false) { procs = new BASS_FILEPROCS(ac_Close, ac_Length, ac_Read, ac_Seek); Preview = quick; Looping = loop; BASSFlag flags = Preview ? 0 : (BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN); if (data == null) { throw new AudioNotLoadedException(); } else { //encapsulate incoming stream with async buffer if it isn't already. DataStream = data as AsyncBufferStream; if (DataStream == null) { DataStream = new AsyncBufferStream(data, quick ? 8 : -1); } audioStreamPrefilter = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_NOBUFFER, flags, procs, IntPtr.Zero); } if (Preview) { audioStream = audioStreamForwards = audioStreamPrefilter; } else { audioStream = audioStreamForwards = BassFx.BASS_FX_TempoCreate(audioStreamPrefilter, loop ? BASSFlag.BASS_MUSIC_LOOP : BASSFlag.BASS_DEFAULT); audioStreamBackwards = BassFx.BASS_FX_ReverseCreate(audioStreamPrefilter, 5f, BASSFlag.BASS_DEFAULT); Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_USE_QUICKALGO, Bass.TRUE); Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_OVERLAP_MS, 4); Bass.BASS_ChannelSetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_SEQUENCE_MS, 30); } Length = (Bass.BASS_ChannelBytes2Seconds(audioStream, Bass.BASS_ChannelGetLength(audioStream)) * 1000); Bass.BASS_ChannelGetAttribute(audioStream, BASSAttribute.BASS_ATTRIB_FREQ, ref initialAudioFrequency); currentAudioFrequency = initialAudioFrequency; AudioEngine.RegisterTrack(this); }
public Speech() { DataContractJsonSerializer serialazer = new DataContractJsonSerializer(typeof(SpeechPart[])); using (FileStream stream = new FileStream("Sounds.json", FileMode.Open)) { parts = (SpeechPart[])serialazer.ReadObject(stream); } Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); stream = Bass.BASS_StreamCreateFile("Sounds.wav", 0L, 0L, BASSFlag.BASS_STREAM_DECODE); stream = BassFx.BASS_FX_TempoCreate(stream, BASSFlag.BASS_SAMPLE_LOOP | BASSFlag.BASS_FX_FREESOURCE); worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; worker.DoWork += Run; worker.RunWorkerCompleted += Done; }
private void Scan() { long pos = Bass.BASS_ChannelGetLength(this.handle); this.len = Bass.BASS_ChannelBytes2Seconds(this.handle, pos); _beatProc = new BPMBEATPROC(MyBeatProc); BassFx.BASS_FX_BPM_BeatCallbackSet(this.handle, _beatProc, IntPtr.Zero); BassFx.BASS_FX_BPM_BeatSetParameters(this.handle, this.parameters.Width, this.parameters.Center, this.parameters.Release); BassFx.BASS_FX_BPM_BeatDecodeGet(this.handle, 0.0, this.len, BASSFXBpm.BASS_FX_BPM_BKGRND, _beatProc, IntPtr.Zero); Bass.BASS_StreamFree(this.handle); if (OnComplete != null) { OnComplete(this.parameters.Index); } }
internal AudioStream(AudioManager manager, string path, ResourceContainer resourceContainer) : base(manager) { this.path = path; decodeStream = Bass.CreateStream(path, 0, 0, BassFlags.Decode | BassFlags.Prescan); if (decodeStream == 0) { Trace.WriteLine($"Failed to load audio stream ({path}): {Bass.LastError}"); return; } stream = BassFx.TempoCreate(decodeStream, BassFlags.Default); Bass.ChannelSetAttribute(stream, ChannelAttribute.TempoUseQuickAlgorithm, 1); Bass.ChannelSetAttribute(stream, ChannelAttribute.TempoOverlapMilliseconds, 4); Bass.ChannelSetAttribute(stream, ChannelAttribute.TempoSequenceMilliseconds, 30); Channel = stream; }
public void Load(string file) { var stream = Bass.BASS_StreamCreateFile(file, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_FX_FREESOURCE); var volume = Volume; var tempo = Tempo; Bass.BASS_StreamFree(streamID); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 250); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 5); streamID = BassFx.BASS_FX_TempoCreate(stream, BASSFlag.BASS_STREAM_PRESCAN); Volume = volume; Tempo = tempo; Reset(); }
private void mainForm_Load(object sender, EventArgs e) { // Подгружаем BASS if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_SPEAKERS, this.Handle)) { BASS_INFO info = new BASS_INFO(); Bass.BASS_GetInfo(info); debugInfo.Text += info + "\n" + BassFx.BASS_FX_GetVersion(); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 200); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 1000); } else { MessageBox.Show(this, "BASS_Init() не сработал, басов не будет"); Close(); } }
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(); }); }
void DecodingBPM(bool newStream, double startSec, double endSec, string fp) { if (newStream) { // open the same file as played but for bpm decoding detection _bpmchan = Bass.CreateStream(fp, 0, 0, BassFlags.Decode); if (_bpmchan == 0) { _bpmchan = Bass.MusicLoad(fp, 0, 0, BassFlags.Decode | BassFlags.Prescan, 0); } } // detect bpm in background and return progress in GetBPM_ProgressCallback function if (_bpmchan != 0) { Bpm = BassFx.BPMDecodeGet(_bpmchan, startSec, endSec, 0, BassFlags.FxBpmBackground | BassFlags.FXBpmMult2 | BassFlags.FxFreeSource, _progressProcedure); } }
public void Stop() { _threadDispatcher.Invoke(new Action(() => { BassFx.BASS_FX_BPM_BeatCallbackReset(_recordChan); if (HasWasapi) { _wasapi.Stop(); _wasapi.Dispose(); _wasapi = null; BassWasapi.BASS_WASAPI_Free(); } else { Bass.BASS_ChannelStop(_recordChan); } Bass.BASS_Free(); })); }
private void LoadBassLibraries(string targetPath) { if (!Bass.LoadMe(targetPath)) { throw new BassException("Could not load bass native libraries from the following path: " + targetPath); } if (!BassMix.LoadMe(targetPath)) { throw new BassException("Could not load bassmix library from the following path: " + targetPath); } if (!BassFx.LoadMe(targetPath)) { throw new BassException("Could not load bassfx library from the following path: " + targetPath); } DummyCallToLoadBassLibraries(); }
private void Setup() { if (this.FChannel != null) { if (this.FChannel.BassHandle.HasValue) { _beatProc = new BPMBEATPROC(MyBeatProc); BassFx.BASS_FX_BPM_BeatCallbackSet(this.FChannel.BassHandle.Value, _beatProc, IntPtr.Zero); double band, center, release; this.FPinInBandWidth.GetValue(0, out band); this.FPinInCenter.GetValue(0, out center); this.FPinInRelease.GetValue(0, out release); BassFx.BASS_FX_BPM_BeatSetParameters(this.FChannel.BassHandle.Value, (float)band, (float)center, (float)release); } } }
public AudioTrackBass(Stream data, bool quick = false) { PendingActions.Enqueue(() => { Preview = quick; BassFlags flags = Preview ? 0 : (BassFlags.Decode | BassFlags.Prescan); if (data == null) { throw new ArgumentNullException(nameof(data)); } //encapsulate incoming stream with async buffer if it isn't already. dataStream = data as AsyncBufferStream ?? new AsyncBufferStream(data, quick ? 8 : -1); procs = new DataStreamFileProcedures(dataStream); audioStreamPrefilter = Bass.CreateStream(StreamSystem.NoBuffer, flags, procs.BassProcedures, IntPtr.Zero); if (Preview) { activeStream = audioStreamPrefilter; } else { activeStream = BassFx.TempoCreate(audioStreamPrefilter, BassFlags.Decode); activeStream = BassFx.ReverseCreate(activeStream, 5f, BassFlags.Default); Bass.ChannelSetAttribute(activeStream, ChannelAttribute.TempoUseQuickAlgorithm, 1); Bass.ChannelSetAttribute(activeStream, ChannelAttribute.TempoOverlapMilliseconds, 4); Bass.ChannelSetAttribute(activeStream, ChannelAttribute.TempoSequenceMilliseconds, 30); } Length = (Bass.ChannelBytes2Seconds(activeStream, Bass.ChannelGetLength(activeStream)) * 1000); Bass.ChannelGetAttribute(activeStream, ChannelAttribute.Frequency, out initialFrequency); SampleRate = initialFrequency; Bass.ChannelSetDSP(activeStream, dspProcessor); }); InvalidateState(); }
public AudioTrackBass(Stream data, bool quick = false, bool loop = false) { Preview = quick; Looping = loop; BassFlags flags = Preview ? 0 : (BassFlags.Decode | BassFlags.Prescan); if (data == null) { throw new Exception(@"Data couldn't be loaded!"); } else { //encapsulate incoming stream with async buffer if it isn't already. dataStream = data as AsyncBufferStream; if (dataStream == null) { dataStream = new AsyncBufferStream(data, quick ? 8 : -1); } procs = new DataStreamFileProcedures(dataStream); audioStreamPrefilter = Bass.CreateStream(StreamSystem.NoBuffer, flags, procs.BassProcedures, IntPtr.Zero); } if (Preview) { activeStream = audioStreamPrefilter; } else { activeStream = BassFx.TempoCreate(audioStreamPrefilter, BassFlags.Decode); activeStream = BassFx.ReverseCreate(activeStream, 5f, BassFlags.Default); Bass.ChannelSetAttribute(activeStream, ChannelAttribute.TempoUseQuickAlgorithm, 1); Bass.ChannelSetAttribute(activeStream, ChannelAttribute.TempoOverlapMilliseconds, 4); Bass.ChannelSetAttribute(activeStream, ChannelAttribute.TempoSequenceMilliseconds, 30); } Length = (Bass.ChannelBytes2Seconds(activeStream, Bass.ChannelGetLength(activeStream)) * 1000); Bass.ChannelGetAttribute(activeStream, ChannelAttribute.Frequency, out initialFrequency); }
public override async Task <(bool Changed, SongData song)> Execute(SongData song) { int stream = Bass.BASS_StreamCreateFile(song.FullFileName, 0, 0, BASSFlag.BASS_STREAM_DECODE); if (stream == 0) { log.Error("BPM: Could not create stream for {0}. {1}", song.FullFileName, Bass.BASS_ErrorGetCode().ToString()); return(false, song); } _bpmProc = BpmProgressProc; double len = Bass.BASS_ChannelBytes2Seconds(stream, Bass.BASS_ChannelGetLength(stream)); float bpm = BassFx.BASS_FX_BPM_DecodeGet(stream, 0.0, len, 0, BASSFXBpm.BASS_FX_BPM_BKGRND | BASSFXBpm.BASS_FX_FREESOURCE | BASSFXBpm.BASS_FX_BPM_MULT2, _bpmProc, IntPtr.Zero); song.BPM = Convert.ToInt32(bpm); BassFx.BASS_FX_BPM_Free(stream); return(true, song); }
/// <summary> /// Loads the File Channel with FX. /// </summary> protected override int OnLoad(string FileName) { var h = Bass.CreateStream(FileName, Flags: BassFlags.Decode); if (h == 0) { return(0); } h = BassFx.TempoCreate(h, BassFlags.Decode | BassFlags.FxFreeSource); if (h == 0) { return(0); } _tempoHandle = h; return(BassFx.ReverseCreate(h, 2, BassFlags.FxFreeSource)); }
static void SaveReverse(string FilePath) { try { var sfd = ReverseSaveDialog.Value; sfd.FileName = Path.GetFileNameWithoutExtension(FilePath) + ".Reverse"; if (!sfd.ShowDialog().Value) { return; } var fc = Bass.CreateStream(FilePath, Flags: BassFlags.Decode); var rc = BassFx.ReverseCreate(fc, 2, BassFlags.Decode | BassFlags.FxFreeSource); var wf = WaveFormat.FromChannel(fc); var writer = new WaveFileWriter(new FileStream(sfd.FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read), wf); var blockLength = (int)Bass.ChannelSeconds2Bytes(rc, 2); var buffer = new byte[blockLength]; var gch = GCHandle.Alloc(buffer, GCHandleType.Pinned); while (Bass.ChannelIsActive(rc) == PlaybackState.Playing) { var bytesReceived = Bass.ChannelGetData(rc, gch.AddrOfPinnedObject(), blockLength); writer.Write(buffer, bytesReceived); } gch.Free(); writer.Dispose(); Bass.StreamFree(rc); MessageBox.Show("Saved"); } catch (Exception e) { MessageBox.Show($"Failed\n\n{e}"); } }