Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.2K Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Playing sequences of sounds (sine waves)

Posted 1 year ago

I want to play without interruption sequences of numerous (say) sine waves. This works fine :

Sound[{Play[Sin[1000 t], {t, 0, 0.2}], Play[Sin[2000 t], {t, 0, 0.2}], Play[Sin[3000 t], {t, 0, 0.2}]}]

Why this doesn't ?

Sound[Table[Play[Sin[k 1000 t], {t, 0, 0.2}], {k, 1, 3}]]

Thanks in advance.

POSTED BY: André Hautot
2 Replies
Posted 1 year ago

Fine, this helps me a lot, Thank you

POSTED BY: André Hautot
Posted 1 year ago

Looking at this expression

Sound[Table[Play[Sin[k 1000 t], {t, 0, 0.2}], {k, 1, 3}]]

Play has the HoldAll attribute, which prevents the substitution for k in the table. So you end up with a bunch of sound expressions that have a raw k in them, which makes them invalid.

You could create the Sins first and then map Play over them:

Sound[Play[#, {t, 0, .2}] & /@ Table[Sin[k 1000 t], {k, 1, 3}]]

Or you could inactivate Play inside the table and re-activate it once the table is complete:

Sound[Activate[Table[Inactive[Play][Sin[k 1000 t], {t, 0, 0.2}], {k, 1, 3}]]]

I wouldn't be surprised if there were a function designed to do this kind of think automatically, but I'm not familiar with this domain.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard