Hi I'm in the process of making a small bpm calculator, as part of a bigger whole. It detects taps on a midikey and calculates the bpm from the distance between the taps. What it boils down to is that I end up with a duration, which at 60 bpm (and tight tapping) is 47904.000000 and if I run with --srate44100 is 44096.000000. Looks to me like time is counted in samples, right? Anyways, if my algorithm should work at all sample rates, I need to ask from within chuck what sample rate we're running at. How is this done? -- peace, love & harmony Atte http://www.atte.dk | quartet: http://www.anagrammer.dk http://www.atte.dk/gps | compositions: http://www.atte.dk/compositions
This works for me ( on win32 ), using a variety of 1::second / 1::samp => float srate; %chuck --srateN Atte André Jensen wrote:
Hi
I'm in the process of making a small bpm calculator, as part of a bigger whole. It detects taps on a midikey and calculates the bpm from the distance between the taps. What it boils down to is that I end up with a duration, which at 60 bpm (and tight tapping) is 47904.000000 and if I run with --srate44100 is 44096.000000. Looks to me like time is counted in samples, right?
Anyways, if my algorithm should work at all sample rates, I need to ask from within chuck what sample rate we're running at. How is this done?
Philip Davidson wrote:
This works for me ( on win32 ), using a variety of 1::second / 1::samp => float srate;
Thanks, didn't think about the samp. I'll give it a try. -- peace, love & harmony Atte http://www.atte.dk | quartet: http://www.anagrammer.dk http://www.atte.dk/gps | compositions: http://www.atte.dk/compositions
Atte André Jensen wrote:
This works for me ( on win32 ), using a variety of 1::second / 1::samp => float srate;
Potentially stupid question: Using this (thanks, it works) I get a bpm as a duration: ((now - first_tap)/nb_taps)/sample_rate * 60 Another place I do: 60 => int bpm; 1::second / 1::samp => float sample_rate; Is it possible to cast the calculated bpm in duration to float? -- peace, love & harmony Atte http://www.atte.dk | quartet: http://www.anagrammer.dk http://www.atte.dk/gps | compositions: http://www.atte.dk/compositions
Hi Atte, I think (and makes sense) you cannot cast from dur to float but there is a work around, ie. dividing by samp and assigning to float. 1::samp => dur bpm; bpm/samp => float n; <<< n + 1.>>>; On Jun 19, 2006, at 1:14 AM, Atte André Jensen wrote:
Atte André Jensen wrote:
This works for me ( on win32 ), using a variety of 1::second / 1::samp => float srate;
Potentially stupid question:
Using this (thanks, it works) I get a bpm as a duration: ((now - first_tap)/nb_taps)/sample_rate * 60
Another place I do:
60 => int bpm; 1::second / 1::samp => float sample_rate;
Is it possible to cast the calculated bpm in duration to float?
-- peace, love & harmony Atte
http://www.atte.dk | quartet: http://www.anagrammer.dk http://www.atte.dk/gps | compositions: http://www.atte.dk/ compositions _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
dur/dur = float, and float * dur = dur; so you may divide by whatever unit you wish to work in.. ( bpm / 1::minute, bpm / 1::second, etc ). eduard aylon wrote:
Hi Atte,
I think (and makes sense) you cannot cast from dur to float but there is a work around, ie. dividing by samp and assigning to float.
1::samp => dur bpm; bpm/samp => float n; <<< n + 1.>>>;
On Jun 19, 2006, at 1:14 AM, Atte André Jensen wrote:
Atte André Jensen wrote:
This works for me ( on win32 ), using a variety of 1::second / 1::samp => float srate; Potentially stupid question:
Using this (thanks, it works) I get a bpm as a duration: ((now - first_tap)/nb_taps)/sample_rate * 60
Another place I do:
60 => int bpm; 1::second / 1::samp => float sample_rate;
Is it possible to cast the calculated bpm in duration to float?
-- peace, love & harmony Atte
http://www.atte.dk | quartet: http://www.anagrammer.dk http://www.atte.dk/gps | compositions: http://www.atte.dk/ compositions _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
participants (3)
-
Atte André Jensen
-
eduard aylon
-
Philip Davidson