7
$\begingroup$

If I define:

aNote[x_] := Sin[440 * 2 * Pi * x];

then this works (i.e. it produces a widget with a Play button, and clicking on this button produces an A note):

Play[aNote[x], {x, 0, 3.5}]

but this doesn't:

env[x_] := HeavisidePi[x - 1] + HeavisidePi[x - 2.5];
Play[env[x] aNote[x], {x, 0, 3.5}]

The latter just produces something like:

Sound[SampledSoundFunction[
  Function[{Play`Time24}, 
   Block[{x = 
      0. + 0.000125 Play`Time24}, ((HeavisidePi[x - 1] + 
          HeavisidePi[x - 2.5]) aNote[x] + 0.00024672) 1.00025]], 
  28000, 8000]]

...but no widget, and no sound.

The difference between the two is that in the second one, the sinusoidal sound wave is multiplied by an "envelope" consisting of two rectangular unit bumps of width 1, and centered at 1 and 2.5, respectively.

$\endgroup$
5
$\begingroup$

You can produce an identical signal by using UnitBox instead of HeavisidePi:

aNote[x_] := Sin[440*2*Pi*x];
unv[x_] := UnitBox[x - 1] + UnitBox[x - 2.5];
Play[unv[x] aNote[x], {x, 0, 3.5}]

enter image description here

Use UnitStep and Piecewise for more sophisticated functions.

Not sure, but maybe the reason for your trouble is that HeavisidePi does not evaluate at 1/2:

HeavisidePi[.5]

HeavisidePi[0.5]

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.