1
$\begingroup$

I am using

Play[f[t], {t,0,30}] 

to play sound defined by f(t), which is 30 seconds long. It is taking a very long time to evaluate this expression (10 minutes and counting). What are the limitations of Play that might make it take so long?

If it is relevant, my function f(t) is a piecewise sequence of sine waves strung together, each about 2 seconds long.

$\endgroup$
4
  • $\begingroup$ How long does this take? Play[Sin[t], {t, 0, 30}] $\endgroup$
    – thedude
    Mar 29, 2016 at 6:22
  • $\begingroup$ No time at all... $\endgroup$
    – gdavtor
    Mar 29, 2016 at 6:26
  • $\begingroup$ Then I suppose interpolating a Table[] of your piecewise fuction should work. $\endgroup$
    – thedude
    Mar 29, 2016 at 6:32
  • $\begingroup$ What do you mean by interpolating a table? $\endgroup$
    – gdavtor
    Mar 29, 2016 at 6:37

1 Answer 1

3
$\begingroup$
f[t_] = Piecewise[{{Sin[t + 0.2], 2 > t >= 0}, {Sin[t - 0.4], 
     4 >= t >= 2}}];
Plot[f@t, {t, 0, 4}, PlotRange -> All]

enter image description here

int[t_] = Interpolation[Table[{t, f@t}, {t, 0, 4, 0.01}]]@t;
Plot[int@t, {t, 0, 4}, PlotRange -> All]

enter image description here

Play[int@t, {t, 0, 4}]

enter image description here


EDIT

Easier way:

Sound[{Play[Sin[t+1], {t, 0, 2}], Play[Sin[t-1], {t, 0, 2}]}]
$\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.