GeneraStudios
Member
Hi everyone,
I'm trying to use cos(x) or sin(x) to make an LFO and i'm having trouble syncing it. I'm pretty sure that i'm just having a brainfart on the trig side. At this time I just want the period to match some even divider of the tempo (1/4 note, 1/8th note). Anyone have any idea what i'm doing wrong?
First I declare some storage values to store the BPM and the ms length of each beat, this seems to work fine. Then I set the listener to trigger what I believe is every 1/2 beat.
Further down....
In this case I want my wave centered around 0.5 and to oscillate between 1 and 0 (so 0.5 +cos()/2). Then inside the cos() function i'm dividing by 2pi to get the period to be 1*x. Then every iteration of the listener call I have a counter ~x which is incremented by the length of 1 beat in seconds, this is what gets put into the cos() function as x. Then i'm just using that value to adjust pan.
It oscillates, and I can control the speed. But its definitely not synced correctly. I also tried this for the cos() calculation:
?myXY[0] := 0.5 + cos(~x / 2.0 / 3.14159 * ~Tempo_ms_real/1000.0) /2.0
Which I think would then set the period to the amount of time for one beat, but that still doesn't seem to be working.
Anyone have any ideas what i'm doing wrong?
Thanks,
--
Andrew
I'm trying to use cos(x) or sin(x) to make an LFO and i'm having trouble syncing it. I'm pretty sure that i'm just having a brainfart on the trig side. At this time I just want the period to match some even divider of the tempo (1/4 note, 1/8th note). Anyone have any idea what i'm doing wrong?
First I declare some storage values to store the BPM and the ms length of each beat, this seems to work fine. Then I set the listener to trigger what I believe is every 1/2 beat.
Code:
declare $Tempo
declare $Tempo_ms
declare ~Tempo_ms_real
$Tempo := ms_to_ticks(60000000)/960
{$Tempo_ms := ticks_to_ms($Tempo)}
~Tempo_ms_real := 60000.0 / int_to_real($Tempo)
$Tempo_ms := real_to_int(~Tempo_ms_real)
set_listener($NI_SIGNAL_TIMER_BEAT,2 ) {Listen every 1/2 beat?}
Further down....
In this case I want my wave centered around 0.5 and to oscillate between 1 and 0 (so 0.5 +cos()/2). Then inside the cos() function i'm dividing by 2pi to get the period to be 1*x. Then every iteration of the listener call I have a counter ~x which is incremented by the length of 1 beat in seconds, this is what gets put into the cos() function as x. Then i'm just using that value to adjust pan.
Code:
on listener
?myXY[0] := 0.5 + cos(~x / 2.0 / 3.14159) /2.0 {1st cursor, X axis}
{?myXY[1] := (?myXY[1] + cos(~x*2.0) / 10.0) {1st cursor, X axis}
~x := ~x+~Tempo_ms_real/1000.0 {Increment seconds every 1/2 beat}
{~x := ~x + 0.1}
set_engine_par($ENGINE_PAR_PAN, real_to_int(?myXY[0] * 1000000.0), $menu,-1,-1)
set_engine_par($ENGINE_PAR_VOLUME, real_to_int(?myXY[1] * 1000000.0), $menu,-1,-1)
message (?myXY[0])
end on
It oscillates, and I can control the speed. But its definitely not synced correctly. I also tried this for the cos() calculation:
?myXY[0] := 0.5 + cos(~x / 2.0 / 3.14159 * ~Tempo_ms_real/1000.0) /2.0
Which I think would then set the period to the amount of time for one beat, but that still doesn't seem to be working.
Anyone have any ideas what i'm doing wrong?
Thanks,
--
Andrew