internal static float calculateBpm() { int audioStreamDecode = Bass.BASS_StreamCreateFile(audioFilename, 0, 0, BASSFlag.BASS_STREAM_DECODE); tmpCount = 0; BassFx.BASS_FX_BPM_BeatCallbackSet(audioStreamDecode, bpmOffset, new IntPtr(1)); float bpm = BassFx.BASS_FX_BPM_DecodeGet(audioStreamDecode, 20, 80, 0, BASSFXBpm.BASS_FX_BPM_MULT2, null); return(bpm); }
/// <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); }
/// <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); }
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); }
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()); } } }