2
$\begingroup$

How can I play a tone and adjust its frequency and amplitude?

As an example, say I wanted to play a SquareWave with a slider for frequency and amplitude. Using a Manipulate. I have tried the following:

  • Using Manipulate the Play object reloads each time the sliders are adjusted, so the tone stops when adjusted; and it takes a long time to evaluate and render said object.

    Manipulate[Play[SquareWave[{-a,a}, f t], {t,0,10}], {{a,1}, 0, 10}, {{f,440}, 20, 20000}]
    
  • Using Dynamic on the Play object reevaluates like Manipulate, using it at any position inside the Play causes the object to stop rendering entirely (Sound:ssnm), apparently failing to find an amplitude scale factor.

    Dynamic @ Play[SquareWave[{-a,a}, f t], {t,0,10}]
    Play[Dynamic @ SquareWave[{-a,a}, f t], {t,0,10}]
    Play[SquareWave[Dynamic@{-a,a}, t Dynamic@f], {t,0,10}]
    
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.