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!
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!
发表时间 Mon 10 Jul 06 @ 10:14 am
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
Another view:
Beat if (pos-SongPhase)/SongBpm is an integer
so use it with modulo and compare to 0
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
发表时间 Mon 10 Jul 06 @ 9:15 pm
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?
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?
发表时间 Mon 10 Jul 06 @ 11:11 pm