/*
Problem is that the wrap method for cycle() doesn't seem to support the type of large
phase increments typically used in FM (because of index values). So we need to use a different
wrap method, and then everything seems to work OK. Hmmm...
*/

freq = param( 'freq', 440 )
cmRatio = param( 'cmRatio', 2.57 )
modulatorFreq = mul( freq, cmRatio )
index = param( 'index', 10 )

modulator = mul( cycle( mul( freq, cmRatio) ), mul(freq, index) )
//modulator = cycle( mul( freq, cmRatio) )
carrier = cycle( add( freq, modulator ) )

play( carrier )




sine = freq => {
  let phase = ssd(0),
      freqAccum = mul( freq, 1/44100 ),
      adder = add( phase.out, freqAccum ),
      wrapper = wrap( adder, 0, 1 )
  
  phase.in( wrapper )
  
  let mysin = sin( 
    mul( 
      adder,
      Math.PI * 2 
    )
  )
  
  return mysin
}
 
 
freq = param( 'freq', 440 )
cmRatio = param( 'cmRatio', 2.57 )
modulatorFreq = mul( freq, cmRatio )
index = param( 'index', 10 )
 
modulator = memo( mul( sine( mul( freq, cmRatio) ), mul(freq, index) ) )
carrier = sine( add( freq, modulator ) )
 
play( carrier )