Author Topic: BPM Counter class  (Read 159 times)

zak_8

  • Posts: 5
BPM Counter class
« on: 21 Jul '17 - 14:46 »
I am tryig to implement a program that takes a mp3 file and counting the BPM in real time.

BPMCounter class gives me 2 different set of BPM values in 2 different times on the same mp3 file.

Code example:
Code: [Select]
public Form1()
        {
            InitializeComponent();

            // create a stream
            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            _stream = Bass.BASS_StreamCreateFile("drums100.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
            Bass.BASS_ChannelGetInfo(_stream, info);
        }

        public void button1_Click(object sender, System.EventArgs e)
        {
         
            timerBPM = new DispatcherTimer();
            timerBPM.Tick += new EventHandler(timerBPM_Tick);
            timerBPM.Interval = TimeSpan.FromMilliseconds(20);


            if (_stream != 0 && Bass.BASS_ChannelPlay(_stream, false))
            {
                //playing...
                _bpm.Reset(info.freq);
                // start our bpm timer callback
                this.timerBPM.Start();
            }
        }

        private void timerBPM_Tick(object sender, System.EventArgs e)
        {
            if (_stream == 0 || Bass.BASS_ChannelIsActive(_stream) != BASSActive.BASS_ACTIVE_PLAYING)
            {
                this.timerBPM.Stop();
                return;
            }
            bool beat = _bpm.ProcessAudio(_stream, true);
            if (beat)
            {
                // display the live calculated BPM value
                this.labelBPM = _bpm.BPM.ToString("#00.0");
                Console.WriteLine(this.labelBPM);

            }
        }

Why could this have happened?
« Last Edit: 21 Jul '17 - 15:18 by zak_8 »