Connexion rapide:  

Forum: VirtualDJ Plugins

Sujet Executing some code on a beat using BPM

Ce topic est ancien et peut contenir des informations obselètes ou incorrectes.

pjakop1Home userMember since 2006
I guess this is quite a basic question, but I didn't find anything useful so far.

I would like to make a controll for some hardware based on beat of the song, I don't know, wheiter I need a kind of OnTimer procedure and synchronize it with BPM, or there is some way of procesing simple codes in every loop alredy.

I just want some simple code starts executing on every beat (or every 2, 4 beats) wherever you start the plugin in the song.

tnx in advance!
 

Posté Mon 10 Jul 06 @ 10:14 am
djcelPRO InfinityModeratorMember since 2004
You have to use "SongBpm" and "SongPhase" from the sound plugin SDK

SongBpm is the number of samples between two beats.
SongPhase is the shift of the CBG, from the first sample of the song.

Thus, you have a beat at every (SongPhase + N * SongBpm) sample , N>=0


int pos; // the current position in the song

int bpm,nextbeat;

bpm = SongBpm?SongBpm:22050;
nextbeat = SongPhase;

while(nextbeat <= pos) nextbeat+=bpm;


Another view:
Beat if (pos-SongPhase)/SongBpm is an integer
so use it with modulo and compare to 0
 

Posté Mon 10 Jul 06 @ 9:15 pm
pjakop1Home userMember since 2006
I figured out already how to find the number of samples to the next beat, but I am not that good in coding that I would know how to use that value.

I use Microstof Visual Studio and the plugin I got from this page.
Would it be ok if I pick "fixed size buffer" type of processing and set the SampleSize to the value "nextbeat" you used above to run my code on the time of the beat?

 

Posté Mon 10 Jul 06 @ 11:11 pm


(Les anciens sujets et forums sont automatiquement fermés)