3
$\begingroup$

I am trying to play a sequence of sounds in Mathematica using Table. My real example is much more complicated so that is why I got to using Table,

Why doesn't the follow code work?

frequencies = {{100, 200}, {200, 300}, {400, 600}};
Sound[
  Table[
    Sound[Play[Total[Sin[# 2 Pi t] & /@ frequencies[[i]]], {t, 0, 0.5}]], 
    {i, 1, 3, 1}]]

If I run the sounds as a list it works fine, but when using table it does not, I just get the following:

Sound[{Sound[
   Sound[SampledSoundFunction[
     Function[{Play`Time494}, 
      Block[{t = 
         0. + 0.000125 Play`Time494}, (Total[(Sin[#1 2 \[Pi] t] &) /@ 
            frequencies[[i]]] - 4.44089*10^-16) 0.568158]], 4000, 
     8000]]], 
  Sound[Sound[
    SampledSoundFunction[
     Function[{Play`Time495}, 
      Block[{t = 
         0. + 0.000125 Play`Time495}, (Total[(Sin[#1 2 \[Pi] t] &) /@ 
            frequencies[[i]]] + 1.88738*10^-15) 0.525731]], 4000, 
     8000]]], 
  Sound[Sound[
    SampledSoundFunction[
     Function[{Play`Time496}, 
      Block[{t = 
         0. + 0.000125 Play`Time496}, (Total[(Sin[#1 2 \[Pi] t] &) /@ 
            frequencies[[i]]] + 8.88178*10^-16) 0.525731]], 4000, 
     8000]]]}]

Any help appreciated

$\endgroup$
4
$\begingroup$

I get something like this

frequencies = {{100, 200}, {200, 300}, {400, 600}};
Sound[Table[
  Evaluate@Sound[
    Play[Total[Sin[#*2 Pi t] & /@ frequencies[[i]]], {t, 0, 
      0.5}]], {i, 1, 3, 1}]]

Mathematica graphics

And it plays sound when clicking on the pay button. (just added Evaluate). See if this is what you expecting the sound to be. I am not good with music.

$\endgroup$
1
$\begingroup$

This code is written by Shenlan.

 Block[{s1 = "C", s2 = "D", s3 = "E", s4 = "F", s5 = "G", s6 = "A", 
      s7 = "B", t1 = 0.25, t2 = 0.5}, 
     Sound[SoundNote @@@ {{s3, t1}, {s3, t1}, {s4, t1}, {s5, 
         t1},(*||*){s5, t1}, {s4, t1}, {s3, t1}, {s2, t1}, {s1, t1}, {s1, 
         t1}, {s2, t1}, {s3, t1},(*||*){s3, t2}, {None, t1/2}, {s2, 
         t1/2}, {s2, t2},(*||*){s3, t1}, {s3, t1}, {s4, t1}, {s5, 
         t1},(*||*){s5, t1}, {s4, t1}, {s3, t1}, {s2, t1},(*||*){s1, 
         t1}, {s1, t1}, {s2, t1}, {s3, t1},(*||*){s2, t1}, {None, 
         t1/2}(*Rest*), {s1, t1/2}, {s1, 2 t1},(*||||*){s2, t1}, {s2, 
         t1}, {s3, t1}, {s1, t1},(*|*){s2, t1}, {s3, t1/2}, {s4, 
         t1/2}, {s3, t1}, {s1, t1},(*|*){s2, t1}, {s3, t1/2}, {s4, 
         t1/2}, {s3, t1}, {s2, t1},(*|*){s1, t1/2}, {s2, t1/2}, {s5, 
         t1}, {s3, t1/2}, {s3, t1/2}, {s3, t1}, {s4, t1}, {s5, t1}, {s5, 
         t1}, {s4, t1}, {s3, t1/2}, {s4, t1/2}, {s2, t1/2}, {s1, t1}, {s1,
          t1}, {s2, t1}, {s3, t1}, {s2, t1}, {None, t1/2}(*Rest*), {s1, 
         t1/2}, {s1, 2 t1}}]]
$\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.