2
$\begingroup$

I couldn't find the reason why the following code consumming my time (1min no output results):

lis = {1, 3, 7, 19};
Sound[Table[
 Play[Sum[4/(Pi j) Sin[440*j*(t + Pi/2/440)], {j, 1, i, 2}], {t, 0, 
   0.7 2 Pi/440}],
 {i, lis}
 ]
]
$\endgroup$
7
  • 3
    $\begingroup$ Play is HoldAll so you need to add Table[With[{i = i},..., otherwies MMA chokes with "symbolic" Play. $\endgroup$
    – Kuba
    Commented Aug 16, 2016 at 7:39
  • $\begingroup$ As Kuba said, or use Play[Sum[4/(Pi j) Sin[440*j*(t + Pi/2/440)], {j, 1, #, 2}], {t, 0, 0.7 2 Pi/440}] & /@ lis // Sound $\endgroup$
    – Mr.Wizard
    Commented Aug 16, 2016 at 7:41
  • $\begingroup$ See the many linked/duplicate questions for more examples: mathematica.stackexchange.com/questions/linked/7756?lq=1 $\endgroup$
    – Mr.Wizard
    Commented Aug 16, 2016 at 7:43
  • $\begingroup$ @Mr.Wizard good enough? 7756. I feel that a generic topic about Hold* attributes and Block based iterators would be very useful. That's a FAQ. $\endgroup$
    – Kuba
    Commented Aug 16, 2016 at 7:43
  • 1
    $\begingroup$ Why are they Block based and there is no built in With based alternative is another question. $\endgroup$
    – Kuba
    Commented Aug 16, 2016 at 7:44

1 Answer 1

2
$\begingroup$

Like this:

lis = {1, 3, 7, 19};
Sound[Play[
           Sum[4/(Pi j) Sin[440*j*(t + Pi/2/440)], {j, 1, #, 2}],
          {t, 0, 0.7 2 Pi/440}] & /@ lis]

enter image description here

$\endgroup$

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