@@ -20,15 +20,14 @@ type DataItem = { x: number; y: number }
2020export const LFO = forwardRef < LFORef , LFOProps > ( ( props , ref ) => {
2121 const {
2222 type = TYPE ,
23- frequency : _frequency = FREQUENCY ,
23+ frequency = FREQUENCY ,
2424 amplitude : _anplitude = AMPLITUDE ,
2525 delay : _delay = DELAY ,
2626 lineWidth = LINE_WIDTH ,
2727 lineColor = LINE_COLOR ,
2828 ...restProps
2929 } = props
3030
31- const frequency = validValue ( _frequency , 0 , 1 )
3231 const amplitude = validValue ( _anplitude , 0 , 1 )
3332 const delay = validValue ( _delay , 0 , 100 )
3433
@@ -62,10 +61,7 @@ export const LFO = forwardRef<LFORef, LFOProps>((props, ref) => {
6261 const generateScales = ( ) => {
6362 const { width, height } = dimensions . current
6463
65- xScale . current = d3
66- . scaleLinear ( )
67- . domain ( [ 0 , 4 * Math . PI * ( frequency * 10 ) ] )
68- . range ( [ 0 , width ] )
64+ xScale . current = d3 . scaleLinear ( ) . domain ( [ 0 , 1 ] ) . range ( [ 0 , width ] )
6965 yScale . current = d3 . scaleLinear ( ) . domain ( [ 0 , 1 ] ) . range ( [ height , 0 ] )
7066 }
7167
@@ -142,8 +138,9 @@ export const LFO = forwardRef<LFORef, LFOProps>((props, ref) => {
142138 ) : { x : number ; y : number } [ ] => {
143139 if ( type !== 'sine' || ! svg ) return [ ]
144140
145- const data = d3 . range ( 0 , 4 * Math . PI * ( frequency * 10 ) , 0.01 ) . map ( ( x ) => {
146- const y = Math . sin ( x ) * amplitude * 0.5 + 0.5
141+ const data = d3 . range ( 0 , 1 , 0.001 ) . map ( ( x ) => {
142+ const adjustedX = x * 2 * Math . PI * frequency
143+ const y = Math . sin ( adjustedX ) * amplitude * 0.5 + 0.5
147144 return { x, y }
148145 } )
149146
@@ -158,8 +155,10 @@ export const LFO = forwardRef<LFORef, LFOProps>((props, ref) => {
158155 const centerY = 0.5
159156 const halfHeight = centerY * amplitude
160157 const data = [ { x : 0 , y : centerY } ] . concat (
161- d3 . range ( 0 , 4 * Math . PI * ( frequency * 10 ) , 0.01 ) . map ( ( x ) => {
162- const y = Math . floor ( x / Math . PI ) % 2 === 0 ? centerY + halfHeight : centerY - halfHeight
158+ d3 . range ( 0 , 1 , 0.001 ) . map ( ( x ) => {
159+ const adjustedX = x * 2 * Math . PI * frequency
160+ const y =
161+ Math . floor ( adjustedX / Math . PI ) % 2 === 0 ? centerY + halfHeight : centerY - halfHeight
163162 return { x, y }
164163 } ) ,
165164 )
@@ -173,12 +172,13 @@ export const LFO = forwardRef<LFORef, LFOProps>((props, ref) => {
173172 if ( type !== 'triangle' || ! svg ) return [ ]
174173
175174 const centerY = 0.5
176- const data = d3 . range ( 0 , 4 * Math . PI * ( frequency * 10 ) , 0.01 ) . map ( ( x ) => {
175+ const data = d3 . range ( 0 , 1 , 0.001 ) . map ( ( x ) => {
177176 // Adjust the phase so that the waveform starts in the middle of the rising segment
178177 // and ensure that the starting point is at the center of the Y-axis
179178 // By mapping the x value to the corresponding position in a cycle,
180179 // the waveform is in the middle of the rising segment when it starts
181- const phase = ( ( x + Math . PI / 2 ) % ( 2 * Math . PI ) ) / Math . PI
180+ const adjustedX = x * 2 * Math . PI * frequency
181+ const phase = ( ( adjustedX + Math . PI / 2 ) % ( 2 * Math . PI ) ) / Math . PI
182182
183183 let y
184184 if ( phase < 1 ) y = phase * amplitude
0 commit comments