Giter Site home page Giter Site logo

adamstark / btrack Goto Github PK

View Code? Open in Web Editor NEW
378.0 18.0 76.0 579 KB

A Real-Time Beat Tracker

License: GNU General Public License v3.0

C++ 80.54% Python 0.40% Makefile 0.85% C 4.52% CMake 0.26% Max 13.42%
beat-tracking beat-detection real-time audio

btrack's People

Contributors

adamstark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

btrack's Issues

"ninja" Build error

Hi, An error occurs when trying to build the application

  • 'Rotate is not a member of std'

std::rotate (frame.begin(), frame.begin() + hopSize, frame.end());
as well

  • error: ninja: build stopped: subcommand failed.

Resampling returns NaNs

It happens rarely and only for a few samples.. but when it happens, it messes up all downstream calculations. I'm running BTrack with a blocksize of 512 which doesn't require resampling (I disabled it).

[offtopic?] Getting errors on openFrameworks addon ofxBTrack on Windows10/VS2017. [working fine on macOS]

Thanks @adamstark for this addon (and Gist too)!
it's working really nice on macOS as an OF addon.

Just in case you know what's happening...
Any hint? What I can try to avoid the errors?

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2440	'=': cannot convert from 'void *' to 'LINEAR_DATA *'	example-audioInput	f:\openframeworks\addons\ofxbtrack\libs\libsamplerate\src_linear.c	173	
Error	C2440	'=': cannot convert from 'void *' to 'SINC_FILTER *'	example-audioInput	f:\openframeworks\addons\ofxbtrack\libs\libsamplerate\src_sinc.c	217	
Error	C2440	'=': cannot convert from 'void *' to 'SRC_PRIVATE *'	example-audioInput	f:\openframeworks\addons\ofxbtrack\libs\libsamplerate\samplerate.c	35	
Error	C2440	'=': cannot convert from 'void *' to 'ZOH_DATA *'	example-audioInput	f:\openframeworks\addons\ofxbtrack\libs\libsamplerate\src_zoh.c	164	
Error	C2131	expression did not evaluate to a constant	example-audioInput	f:\openframeworks\addons\ofxbtrack\libs\btrack\btrack.cpp	383	
#173
	if (psrc->private_data == NULL)
	{	priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
		psrc->private_data = priv ;
		} ;
#217
	if ((filter = calloc (1, sizeof (SINC_FILTER) + sizeof (filter->buffer [0]) * (temp_filter.b_len + temp_filter.channels))) == NULL)
		return SRC_ERR_MALLOC_FAILED ;
	if ((psrc = calloc (1, sizeof (*psrc))) == NULL)
	{	if (error)
			*error = SRC_ERR_MALLOC_FAILED ;
		return NULL ;
		} ;
	if (psrc->private_data == NULL)
	{	priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
		psrc->private_data = priv ;
		} ;
	if (psrc->private_data == NULL)
	{	priv = calloc (1, sizeof (*priv) + psrc->channels * sizeof (float)) ;
		psrc->private_data = priv ;
		} ;
//=======================================================================
void BTrack::resampleOnsetDetectionFunction()
{
	float output[512];
    
    float input[onsetDFBufferSize];

https://github.com/satoruhiga/ofxBTrack

Question about sample rate

In the code there are some instances of 44100 hardcoded. Does that mean the input audio frames are expected to have a sampling rate of 44100?

Python setup.py build compilation error

Hello! I am trying to install via the Python bindings. I am getting the following compilation error when running python setup.py build. Running on Python 3.7.6 OSX 10.15.6. Any idea where I can find the C++ file, or how to install dependencies if needed?

creating build/temp.macosx-10.9-x86_64-3.7/BTrack/src
compile options: '-DUSE_FFTW -I/Users/mnalavadi/anaconda3/envs/blah/lib/python3.7/site-packages/numpy/core/include -I/Users/mnalavadi/anaconda3/envs/blah/lib/python3.7/site-packages/numpy/core/include -I/usr/local/include -I../../libs/kiss_fft130 -I/Users/mnalavadi/anaconda3/envs/blah/include/python3.7m -c'
g++: btrack_python_module.cpp
g++: ../../src/BTrack.cpp
g++: ../../src/OnsetDetectionFunction.cpp
In file included from ../../src/OnsetDetectionFunction.cpp:23:0:
../../src/OnsetDetectionFunction.h:26:19: fatal error: fftw3.h: No such file or directory
 #include "fftw3.h"
                   ^
compilation terminated.
In file included from ../../src/BTrack.h:25:0,
                 from ../../src/BTrack.cpp:24:
../../src/OnsetDetectionFunction.h:26:19: fatal error: fftw3.h: No such file or directory
 #include "fftw3.h"
                   ^
compilation terminated.
In file included from btrack_python_module.cpp:3:0:
../../src/OnsetDetectionFunction.h:26:19: fatal error: fftw3.h: No such file or directory
 #include "fftw3.h"

Some question about algorithm implementation

Hi, thank you for sharing this library!

I have some question about this implementation:

  1. Why swapping of the windowed time-domain signal before taking FFT while calculating ODF,
    but no swapping of the ODF while calculating ACF?

  2. Is it necessary to do resampling on ODF? even if onsetDFBufferSize is equal to output_len?

  3. Why only 41 BPM values kept (80:2:160) but not 81 values (80:1:160)?

  4. Why x[0] is abandoned in x_thresh calculation at first 't' sample in adaptiveThreshold?

  5. In the mapping from "beat period observation vector" to "tempo observation vector", why the higher octave of beat period (the "t_index2" term) is considered but without the lower octave? And Is it necessary to calculate the whole 128 dimension combFilterBankOutput as Davies[2007]?

Thanks in advance!

A simple BTrack example

Hi,

I'm having a little trouble on how to use your BTrack. Can you make a simple program using your BTrack?

I really appreciate it

inaccuracy on windows C# wrapper

Greetings,

I'm building some custom camera switching software for BMD video switcher and I decided to implement beat driven switching for long live events with DJ sets. Your code is the only one I found to be simple enough to interface and to give it a try with porting to c# so I don't need to write beat tracking from scratch.
My software is written in C# .net 4.6.1 and uses NAudio library for live audio sampling from soundcard input. I wrote a simple managed C++/CLI DLL to interface unmanaged static lib compiled from Your source. Here's the wrapper class (sorry for unmarked code, github was giving me troubles, I couldn't embed it in one piece so i gave up from styling):

// BTrackWrapper.h
#include <windows.h>
#include <vcclr.h>
#using <System.dll>

#pragma unmanaged
#include "BTrack.h"
#include "OnsetDetectionFunction.h"
#pragma once

#pragma managed

using namespace System;

namespace BTrackWrapper {
public ref class BTrackWrapper
{
public:
BTrackWrapper() : m_Impl(new BTrack) {}
BTrackWrapper(int hopSize) : m_Impl(new BTrack(hopSize)) {}
BTrackWrapper(int hopSize, int frameSize) : m_Impl(new BTrack(hopSize, frameSize)) {}
~BTrackWrapper() {
delete m_Impl;
}
protected:
!BTrackWrapper() {
delete m_Impl;
}
public:
void processAudioFrameWrapper(System::IntPtr frame) {
m_Impl->processAudioFrame((double*)((int)frame));
}

	void processOnsetDetectionFunctionSampleWrapper(double sample) {
		m_Impl->processOnsetDetectionFunctionSample(sample);
	}

	bool beatDueInCurrentFrameWrapper() {
		return bool (m_Impl->beatDueInCurrentFrame());
	}

	void fixTempoWrapper(double tempo) {
		m_Impl->fixTempo(tempo);
	}

	double getCurrentTempoEstimate() {
		return double(m_Impl->getCurrentTempoEstimate());
	}
private:
	BTrack * m_Impl;
};

}

In C# code, I create instance with window and hop size and use methods as supposed:

...
BTrackWrapper.BTrackWrapper btw = new BTrackWrapper.BTrackWrapper(512, 1024);
...
//sampling 1024 samples and forwarding them to BTracker with some pin_pointers
private void OnDataAvailable(object sender, WaveInEventArgs args)
{
List frame = new List();
// interpret as 16 bit audio
for (int index = 0; index < args.BytesRecorded; index += 2)
{
short sample = (short)((args.Buffer[index + 1] << 8) |
args.Buffer[index + 0]);
// to floating point
var sample32 = sample / 32768.0;
//sample32 = lpf.Transform(sample32);
frame.Add(sample32);
}

        var framearray = frame.ToArray();
        GCHandle handle = GCHandle.Alloc(framearray, GCHandleType.Pinned);
        var framePtr = handle.AddrOfPinnedObject();
        btw.processAudioFrameWrapper(framePtr);
        
        if (btw.beatDueInCurrentFrameWrapper())
        {
            //camera switching
        }
        handle.Free();
    }

I had some problems with compiling libsamplerate but i finally managed to do a successful build. It works, well kind of. It seems very inaccurate and slow for some reason - bpm is usually underestimated, being reported as about 70ish percent of real value. But something that bugs me more is how rarely it actually detects beat. It does the detection about every 10-13 real beats and usually drifts because od tempo mismatch, then corrects itself a bit and drifts again and so on..
Do You have any idea what could be a problem or maybe you came across such issue yourself? I tried modifying some basic values in BTracker such as alpha and tightness but it didn't really help much. I also tried taking only one audio channel (sampling twice as long of a period and incrementing index by 4) with same results.

Thank You in advance for reply!

More responsive??

First of all, thank you very much for sharing this project!

This is not an issue, but more like a general question: How can I make it more responsive to changes in tempi? Which parameter should I tweak in order to make it faster to react the change at the cost of stability or precision? (a float value called "alpha" seems to be the one??)

Thanks in advance!

Downbeat and upbeat are detected alternatively

Hi, thank you again for sharing this library!

I have observed that this algorithm outputs downbeat/upbeat alternatively.
For example we have a 30-second music piece, in the first 15 second, we get the downbeats from the algorithm. Then from 15 second, the algorithm starts to output the upbeats to the end of music piece.

It is possible that the downbeat/upbeat switching mentioned above happens many time in a music piece.
But in my application a stable beat interval is needed(all-downbeat or all-upbeat will be good).
So I am wondering the reason and how to overcome this.

Thanks in advance!

Have python version ?

Dear,

Thanks for your great project.

Do you develop the python version for beat tracking?

And I want to get the BPM at real time, Could U help me ?

Any advice or suggestion will be Okey

compile error

Hello, I have followed the instructions from the Readme, included the header file BTrack.h in a main.cpp file created, and all the headers and cpp's file are in the same folder with main.cpp.However, when I try to instantiate a BTrack object, I get the following error at compile: undefined reference to `BTrack::BTrack(int, int). I tried a few other things but none of them worked. What is the problem ?

Want to try but new to GitHub...

Hi i downloaded the files to try and see if i could work this in my DAW or stand alone but i literally have no clue how...
Any tips?

BPM limitation

I've been struggling to retrieve the BPM of Eagles - Hotel California: 75.
Until I found out your algorithm makes sure the tempo is comprised between 80 and 160.
Could you please explain this restriction?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.