public override void Initialize(int deviceid) { Bass.BASS_SetDevice(deviceid); int handle = Bass.BASS_StreamCreateFile(this.filename, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT); BASSFlag flag = BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_FX_FREESOURCE; if (this.IsDecoding) { flag = flag | BASSFlag.BASS_STREAM_DECODE; } if (this.Mono) { flag = flag | BASSFlag.BASS_SAMPLE_MONO; } handle = BassFx.BASS_FX_TempoCreate(handle, flag); long len = Bass.BASS_ChannelGetLength(handle); this.Length = Bass.BASS_ChannelBytes2Seconds(handle, len); this.BassHandle = handle; _syncProc = new SYNCPROC(TrackSync); // setup a new sync Bass.BASS_ChannelSetSync(handle, BASSSync.BASS_SYNC_END, 0, _syncProc, IntPtr.Zero); this.OnInitialize(); }
public static AudioFX loadFromFile(String path, bool sfx) { initBass(); try { if (Loaded[path] != null && !sfx) { return(Loaded[path]); } } catch (Exception) { //just means wasn't in dict yet } if (File.Exists(path)) { //int h = Bass.BASS_StreamCreateFile(path, 0L, 0, BASSFlag.BASS_DEFAULT); int h = Bass.BASS_StreamCreateFile(path, 0L, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN); h = BassFx.BASS_FX_TempoCreate(h, BASSFlag.BASS_MUSIC_PRESCAN); //Bass.BASS_ChannelSetAttribute(h, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, frequency); if (h == 0) { Console.WriteLine(Bass.BASS_ErrorGetCode()); } AudioFX fx = new AudioFX(h, path, sfx); if (!sfx) { Loaded.Add(path, fx); } return(fx); } Console.WriteLine("Could not find " + path); return(new AudioFX()); //so game doesnt get nullpointerexceptions, no audio plays though }
public void TocarArquivoMP3AlterandoTempo() { if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)) { throw new Exception("Erro ao inicializar BASS."); } try { int streamHandle = Bass.BASS_StreamCreateFile(MP3MattRedman, 0L, 0L, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MUSIC_NOSAMPLE | BASSFlag.BASS_MUSIC_DECODE); Assert.AreNotEqual(0, streamHandle, "BASS_StreamCreateFile"); int streamFXHandle = BassFx.BASS_FX_TempoCreate(streamHandle, BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_SAMPLE_FLOAT); Assert.AreNotEqual(0, streamFXHandle, "BASS_FX_TempoCreate"); Bass.BASS_ChannelSetAttribute(streamFXHandle, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_PREVENT_CLICK, 1); Bass.BASS_ChannelSetAttribute(streamFXHandle, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_SEQUENCE_MS, 82); Bass.BASS_ChannelSetAttribute(streamFXHandle, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_SEEKWINDOW_MS, 14); Bass.BASS_ChannelSetAttribute(streamFXHandle, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_OVERLAP_MS, 12); bool playing = Bass.BASS_ChannelPlay(streamFXHandle, false); Assert.IsTrue(playing, "BASS_ChannelPlay"); bool tempo = Bass.BASS_ChannelSetAttribute(streamFXHandle, BASSAttribute.BASS_ATTRIB_TEMPO, -50f); Assert.IsTrue(tempo, "BASS_ChannelSetAttribute TEMPO"); } finally { Bass.BASS_Free(); } }
void SE_Play() { //選択しているSEを再生 if (IsClosing) { return; } Bass.BASS_ChannelStop(Stream); Bass.BASS_StreamFree(Stream); string SE_Count = SE_Change_Window.Preset_List[SE_Change_Window.Preset_Index][SE_Lists.SelectedIndex + 1]; int StreamHandle = Bass.BASS_StreamCreateFile(SE_Count.Split('|')[SE_Play_Index - 1], 0, 0, BASSFlag.BASS_STREAM_DECODE); Stream = BassFx.BASS_FX_TempoCreate(StreamHandle, BASSFlag.BASS_FX_FREESOURCE); Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, 1f); Bass.BASS_ChannelSetDevice(Stream, Video_Mode.Sound_Device); Bass.BASS_ChannelPlay(Stream, true); if (SE_Play_Index < Select_SE_File_Count) { SE_Play_Index++; SE_Play_Number_T.Text = SE_Play_Index + "/" + Select_SE_File_Count; } else if (Select_SE_File_Count != 1 && SE_Play_Index == Select_SE_File_Count) { SE_Play_Index = 1; SE_Play_Number_T.Text = SE_Play_Index + "/" + Select_SE_File_Count; } }
public int ChangeSpeed(int chan, string loc, float speed) { // get position to resume playback at long pos = Bass.BASS_ChannelGetPosition(chan, BASSMode.BASS_POS_BYTES); if (!Bass.BASS_StreamFree(chan)) { GetBassErrorTrow("Could not free stream: " + chan); } chan = OpenFile(loc, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT); chan = BassFx.BASS_FX_TempoCreate(chan, BASSFlag.BASS_SAMPLE_LOOP); if (chan == 0) { GetBassErrorTrow("Could not open file: " + loc); } if (!Bass.BASS_ChannelSetPosition(chan, pos, BASSMode.BASS_POS_BYTES)) { GetBassErrorTrow("Could not seek to " + pos + " bytes"); } if (!Bass.BASS_ChannelSetAttribute(chan, BASSAttribute.BASS_ATTRIB_TEMPO, CheckTempoRange(speed) - 100)) { GetBassErrorTrow("Could not set attribute: " + BASSAttribute.BASS_ATTRIB_TEMPO); } return(chan); }
public override void Initialize(int deviceid) { Bass.BASS_SetDevice(deviceid); _myStreamCreate = new STREAMPROC(MyFileProc); int handle = Bass.BASS_StreamCreate(44100, 1, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT, _myStreamCreate, IntPtr.Zero); BASSFlag flag = BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_FX_FREESOURCE; if (this.IsDecoding) { flag = flag | BASSFlag.BASS_STREAM_DECODE; } if (this.Mono) { flag = flag | BASSFlag.BASS_SAMPLE_MONO; } handle = BassFx.BASS_FX_TempoCreate(handle, flag); this.BassHandle = handle; this.OnInitialize(); }
public void LoadUrl(string path, string url, Action <long, long> proc, Action finish) { try { ip = new IntPtr(BassdlList.Count); var Bassdl = new BASSDL(path); BassdlList.Add(Bassdl); Bassdl.procChanged = proc; Bassdl.finished = finish; Bassdl.downloadfailed += (e) => { }; decode = Bass.BASS_StreamCreateURL(url + "\r\n" + "Host: musichy.tc.qq.com\r\n" + "Accept-Encoding: identity;q=1, *;q=0\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.66 Safari/537.36 Edg/80.0.361.40\r\n" + "Accept: */*\r\n" + "Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6\r\n" + "Cookie:" + Settings.USettings.Cookie , 0, BASSFlag.BASS_STREAM_DECODE, Bassdl._myDownloadProc, ip); Bassdl.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); } } catch { } }
private void Play_B_Click(object sender, System.Windows.RoutedEventArgs e) { if (IsClosing) { return; } if (Sound_List.SelectedIndex == -1 && Change_List.SelectedIndex == -1) { return; } else if (Sound_List.SelectedIndex != -1 && !File.Exists(Voice_Set.Special_Path + "/Wwise/Temp_01.ogg")) { Message_Feed_Out("サウンドファイルが変換されませんでした。"); return; } else if (Change_List.SelectedIndex != -1 && !File.Exists(Change_Sound_Full_Name[Change_List.SelectedIndex])) { Message_Feed_Out("選択されたファイルが存在しません。"); return; } if (SelectIndex == Sound_List.SelectedIndex || SelectIndex == Change_List.SelectedIndex) { Bass.BASS_ChannelPlay(Stream, false); } else { Bass.BASS_ChannelStop(Stream); Location_S.Value = 0; Bass.BASS_StreamFree(Stream); if (Sound_List.SelectedIndex != -1) { int StreamHandle = Bass.BASS_StreamCreateFile(Voice_Set.Special_Path + "/Wwise/Temp_01.ogg", 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_LOOP); Stream = BassFx.BASS_FX_TempoCreate(StreamHandle, BASSFlag.BASS_FX_FREESOURCE); SelectIndex = Sound_List.SelectedIndex; } else if (Change_List.SelectedIndex != -1) { int StreamHandle = Bass.BASS_StreamCreateFile(Change_Sound_Full_Name[Change_List.SelectedIndex], 0, 0, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_LOOP); Stream = BassFx.BASS_FX_TempoCreate(StreamHandle, BASSFlag.BASS_FX_FREESOURCE); SelectIndex = Change_List.SelectedIndex; } else { Message_Feed_Out("エラーが発生しました。"); return; } IsMusicEnd = new SYNCPROC(EndSync); Bass.BASS_ChannelSetDevice(Stream, Video_Mode.Sound_Device); Bass.BASS_ChannelSetSync(Stream, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME, 0, IsMusicEnd, IntPtr.Zero); Bass.BASS_ChannelPlay(Stream, true); Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, (float)Volume_S.Value / 100); Bass.BASS_ChannelGetAttribute(Stream, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, ref SetFirstFreq); Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, SetFirstFreq + (float)Speed_S.Value); Location_S.Maximum = Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetLength(Stream, BASSMode.BASS_POS_BYTES)); } IsPaused = false; }
private void buttonPlay_Click(object sender, System.EventArgs e) { BassAsio.BASS_ASIO_Stop(); BassAsio.BASS_ASIO_ChannelReset(false, -1, BASSASIOReset.BASS_ASIO_RESET_PAUSE | BASSASIOReset.BASS_ASIO_RESET_JOIN); Bass.BASS_StreamFree(_streamFX); if (_fileName != String.Empty) { // create the decoding stream _stream = Bass.BASS_StreamCreateFile(_fileName, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT); if (_stream != 0) { // now we create a Tempo channel (again a decoding one)...the actual playing channel _streamFX = BassFx.BASS_FX_TempoCreate(_stream, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_SAMPLE_FLOAT); if (_streamFX == 0) { MessageBox.Show(this, "Can't create FX stream!", Enum.GetName(typeof(BASSError), Bass.BASS_ErrorGetCode())); return; } // now setup ASIO myAsioProc = new ASIOPROC(AsioCallback); // get the stream channel info BASS_CHANNELINFO info = new BASS_CHANNELINFO(); Bass.BASS_ChannelGetInfo(_streamFX, info); _originSampleRate = (float)info.freq; this.button2.Text = _originSampleRate.ToString("0"); // enable 1st output channel...(0=first) BassAsio.BASS_ASIO_ChannelEnable(false, 0, myAsioProc, new IntPtr(_streamFX)); // and join the next channels to it for (int a = 1; a < info.chans; a++) { BassAsio.BASS_ASIO_ChannelJoin(false, a, 0); } // since we joined the channels, the next commands will applay to all channles joined // so setting the values to the first channels changes them all automatically // set the source format (float, as the decoding channel is) BassAsio.BASS_ASIO_ChannelSetFormat(false, 0, BASSASIOFormat.BASS_ASIO_FORMAT_FLOAT); // set the source rate BassAsio.BASS_ASIO_ChannelSetRate(false, 0, (double)info.freq); // try to set the device rate too (saves resampling) BassAsio.BASS_ASIO_SetRate((double)info.freq); // and start playing it... // start output using default buffer/latency if (!BassAsio.BASS_ASIO_Start(0)) { MessageBox.Show(this, "Can't start ASIO output", Enum.GetName(typeof(BASSError), BassAsio.BASS_ASIO_ErrorGetCode())); } else { this.labelStatus.Text = "playing"; this.timerUpdate.Start(); } } } }
private void SetURL(string url) { if (stream != 0) { FreeStream(); } int s = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_STREAM_DECODE, null, IntPtr.Zero); stream = BassFx.BASS_FX_TempoCreate(s, BASSFlag.BASS_FX_FREESOURCE); }
private void SetFile(string file) { if (stream != 0) { FreeStream(); } int s = Bass.BASS_StreamCreateFile(file, 0, 0, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_STREAM_DECODE); stream = BassFx.BASS_FX_TempoCreate(s, BASSFlag.BASS_FX_FREESOURCE); }
private void Play_B_Click(object sender, RoutedEventArgs e) { Bass.BASS_ChannelStop(Stream); Bass.BASS_StreamFree(Stream); int StreamHandle = Bass.BASS_StreamCreateFile(Voice_Set.Special_Path + "/Server/" + Voice_Set.SRTTbacon_Server_Name + "/Voices/" + Server_Voices.Voice_List[(int)Voice_Select_S.Value], 0, 0, BASSFlag.BASS_STREAM_DECODE); Stream = BassFx.BASS_FX_TempoCreate(StreamHandle, BASSFlag.BASS_FX_FREESOURCE); Bass.BASS_ChannelSetDevice(Stream, Video_Mode.Sound_Device); Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, (float)(Volume_S.Value / 100)); Bass.BASS_ChannelPlay(Stream, true); }
void Load_Sound(string File_Name = "") { Location_S.Value = 0; Location_T.Text = "00:00"; int 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)); }
public void Start(string path) { this.Stop(); Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); this.songPath = path; this.stream = Bass.BASS_StreamCreateFile(this.songPath, 0, 0, BASSFlag.BASS_STREAM_DECODE); this.stream = BassFx.BASS_FX_TempoCreate(this.stream, BASSFlag.BASS_FX_TEMPO_ALGO_LINEAR); if (this.stream == 0) { throw new Exception("Audio stream could not be created."); } }
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 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); } }
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 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; }
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(); }
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(); }); }
private void SE_Play_B_Click(object sender, RoutedEventArgs e) { if (IsClosing || SE_List.SelectedIndex == -1 || SE_Sound_List.SelectedIndex == -1) { Message_Feed_Out("ファイルが選択されていません。"); return; } if (!File.Exists(SE_Files[SE_List.SelectedIndex][SE_Sound_List.SelectedIndex])) { Message_Feed_Out("音声ファイルが存在しません。削除された可能性があります。"); return; } Bass.BASS_ChannelStop(Stream); Bass.BASS_StreamFree(Stream); int StreamHandle = Bass.BASS_StreamCreateFile(SE_Files[SE_List.SelectedIndex][SE_Sound_List.SelectedIndex], 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_ChannelSetDevice(Stream, Video_Mode.Sound_Device); Bass.BASS_ChannelPlay(Stream, false); Bass.BASS_ChannelSetAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, (float)Volume_S.Value / 100); }
private void buttonPlay_Click(object sender, System.EventArgs e) { this.checkBoxSwap.Checked = false; this.checkBoxFlanger.Checked = false; this.checkBoxEcho.Checked = false; Bass.BASS_StreamFree(_StreamFX); if (_FileName != String.Empty) { // create the decoding stream _Stream = Bass.BASS_StreamCreateFile(_FileName, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_PRESCAN); if (_Stream != 0) { _20mslength = (int)Bass.BASS_ChannelSeconds2Bytes(_Stream, 0.02f); // 20ms window // and start to get the BPM...BEFORE! playing bpmProc = new BPMPROCESSPROC(MyBPMProc); float bpm = BassFx.BASS_FX_BPM_DecodeGet(_Stream, 1f, 180f, Utils.MakeLong(50, 180), BASSFXBpm.BASS_FX_BPM_BKGRND | BASSFXBpm.BASS_FX_FREESOURCE | BASSFXBpm.BASS_FX_BPM_MULT2, bpmProc, IntPtr.Zero); this.labelBPM.Text = String.Format("BPM={0}", bpm); // and set the position back...so that we hear the playback from the beginning... // never get the BPM from '_Stream' while playing...this will steel the data from the decoding channel Bass.BASS_ChannelSetPosition(_Stream, 0); // now we create a Tempo channel...the actual playing channel _StreamFX = BassFx.BASS_FX_TempoCreate(_Stream, BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_SAMPLE_LOOP); } if (_StreamFX != 0 && Bass.BASS_ChannelPlay(_StreamFX, false)) { this.timerUpdate.Start(); // real-time beat position beatProc = new BPMBEATPROC(MyBeatProc); BassFx.BASS_FX_BPM_BeatCallbackSet(_StreamFX, beatProc, IntPtr.Zero); } else { Console.WriteLine("Error = {0}", Bass.BASS_ErrorGetCode()); } } }
public static void Play(string file, bool loadOnly) { Stop(); baseStreamHandle = Bass.BASS_StreamCreateFile(file, 0, 0, BASSFlag.BASS_STREAM_DECODE); BASS_CHANNELINFO info = Bass.BASS_ChannelGetInfo(baseStreamHandle); mixStreamHandle = BassMix.BASS_Mixer_StreamCreate(info.freq, info.chans, BASSFlag.BASS_STREAM_DECODE); BassMix.BASS_Mixer_StreamAddChannel(mixStreamHandle, baseStreamHandle, BASSFlag.BASS_MIXER_MATRIX); streamHandle = BassFx.BASS_FX_TempoCreate(mixStreamHandle, BASSFlag.BASS_FX_FREESOURCE); Mono = mono; Speed = speed; if (!loadOnly) { Bass.BASS_ChannelPlay(streamHandle, false); } BASSError er = Bass.BASS_ErrorGetCode(); syncProc = new SYNCPROC(AudioEnded); Bass.BASS_ChannelSetSync(streamHandle, BASSSync.BASS_SYNC_END, 0, syncProc, IntPtr.Zero); Playing = !loadOnly; FileLoaded = true; }
/// <summary> /// Loads the sample audio data. /// </summary> /// <param name="sample">The sample to load.</param> /// <returns>The loaded sample</returns> private Sample LoadSampleAudioData(Sample sample) { // abort if audio data already loaded if (sample.Channel != int.MinValue) { return(sample); } Debug.Print("Loading sample Audio Data " + sample.Description); sample.AudioData = File.ReadAllBytes(sample.Filename); sample.AudioDataHandle = GCHandle.Alloc(sample.AudioData, GCHandleType.Pinned); sample.Channel = Bass.BASS_StreamCreateFile(sample.AudioDataPointer, 0, sample.AudioData.Length, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN); if (sample.Channel == 0) { var errorCode = Bass.BASS_ErrorGetCode(); throw new Exception("Cannot load sample " + sample.Filename + ". Error code: " + errorCode.ToString()); } sample.Channel = BassFx.BASS_FX_ReverseCreate(sample.Channel, 1, BASSFlag.BASS_STREAM_DECODE); if (sample.Channel == 0) { throw new Exception("Cannot load sample " + sample.Filename); } Bass.BASS_ChannelSetAttribute(sample.Channel, BASSAttribute.BASS_ATTRIB_REVERSE_DIR, (float)BASSFXReverse.BASS_FX_RVS_FORWARD); sample.Channel = BassFx.BASS_FX_TempoCreate(sample.Channel, BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_STREAM_DECODE); if (sample.Channel == 0) { throw new Exception("Cannot load sample " + sample.Filename); } sample.Length = Bass.BASS_ChannelGetLength(sample.Channel); sample.DefaultSampleRate = BassHelper.GetSampleRate(sample.Channel); return(sample); }
public void LoadStream() { if (fFileName == string.Empty) { return; } if (!this.fAudioDeviceInitialized) { InitializeAudioDevice(); } if (fStreamFxHandler == 0) //if (fStreamHandler == 0) { //Create the stream of the song file in order to play it var fStreamHandler = Bass.BASS_StreamCreateFile(fFileName, 0L, 0L, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MUSIC_NOSAMPLE | BASSFlag.BASS_MUSIC_DECODE); if (fStreamHandler == 0) { throw new AudioProcessingError(string.Format("SongPlayer couldn't create the stream of the file [{0}].", fFileName)); } //Create the strem over the song to process effects (velocity) fStreamFxHandler = BassFx.BASS_FX_TempoCreate(fStreamHandler, BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_SAMPLE_FLOAT); if (fStreamFxHandler == 0) { throw new AudioProcessingError(string.Format("SongPlayer couldn't create the stream for FX effects for the file [{0}].", fFileName)); } Bass.BASS_ChannelSetAttribute(fStreamFxHandler, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_PREVENT_CLICK, 1); Bass.BASS_ChannelSetAttribute(fStreamFxHandler, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_SEQUENCE_MS, 82); Bass.BASS_ChannelSetAttribute(fStreamFxHandler, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_SEEKWINDOW_MS, 14); Bass.BASS_ChannelSetAttribute(fStreamFxHandler, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_OVERLAP_MS, 12); } }
public void TocarArquivoMP3AlterandoPitch() { if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)) { throw new Exception("Erro ao inicializar BASS."); } try { //var audioFile = @"C:\1-Pessoal\Guitarmonics-OpenSource\trunk\DataFolder\Songs\Metallica.RideTheLightning.ForWhomTheBellTolls\Metallica.RideTheLightning.ForWhomTheBellTolls.mp3"; var audioFile = MP3MattRedman; int streamHandle = Bass.BASS_StreamCreateFile(audioFile, 0L, 0L, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MUSIC_NOSAMPLE | BASSFlag.BASS_MUSIC_DECODE); Assert.AreNotEqual(0, streamHandle, "BASS_StreamCreateFile"); int streamFXHandle = BassFx.BASS_FX_TempoCreate(streamHandle, BASSFlag.BASS_FX_FREESOURCE | BASSFlag.BASS_SAMPLE_FLOAT); Assert.AreNotEqual(0, streamFXHandle, "BASS_FX_TempoCreate"); Bass.BASS_ChannelSetAttribute(streamFXHandle, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_PREVENT_CLICK, 1); Bass.BASS_ChannelSetAttribute(streamFXHandle, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_SEQUENCE_MS, 82); Bass.BASS_ChannelSetAttribute(streamFXHandle, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_SEEKWINDOW_MS, 14); Bass.BASS_ChannelSetAttribute(streamFXHandle, BASSAttribute.BASS_ATTRIB_TEMPO_OPTION_OVERLAP_MS, 12); bool playing = Bass.BASS_ChannelPlay(streamFXHandle, false); Assert.IsTrue(playing, "BASS_ChannelPlay"); bool tempo = Bass.BASS_ChannelSetAttribute(streamFXHandle, BASSAttribute.BASS_ATTRIB_TEMPO_PITCH, 2f); //Sobe 2 semitons (1 tom) //bool tempo = Bass.BASS_ChannelSetAttribute(streamFXHandle, BASSAttribute.BASS_ATTRIB_TEMPO_PITCH, -0.5f); //desce 0.5 semitom. Assert.IsTrue(tempo, "BASS_ChannelSetAttribute TEMPO"); } finally { Bass.BASS_Free(); } }