Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Using MapAt with Play

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113853] Re: Using MapAt with Play
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Tue, 16 Nov 2010 05:03:47 -0500 (EST)
  • References: <ibr391$8vi$1@smc.vnet.net>

Am 15.11.2010 11:50, schrieb BenT:
> Using Mathematica 7, please consider this code:
> 
> Play[{Sin[440 t 2 Pi], Sin[441 t 2 Pi]}, {t, 0, 1},
>  SampleRate -> 44100, SampleDepth -> 16]
> 
> which works as intended.
> 
> But now attempting to use the MapAt function,
> 
> p = {440, 550, 660, 770, 880};
> Play[{Sin[# t 2 Pi], Sin[(# + 1) t 2 Pi] &} /@ p, {t, 0, 1},
>  SampleRate -> 44100, SampleDepth -> 16]
> 
> I get the following error coding:
> 
> During evaluation of In[28]:= Sound::ssnm: A good PlayRange could not
> be found since most of the samples are not evaluating to machine-size
> real numbers. >>
> 
> Out[28]= Sound[
>  SampledSoundFunction[
>   Function[{Play`Time37},
>    Block[{t =
>       0. + 0.0000226757 Play`Time37}, ({Sin[#1 t 2 \[Pi]],
>          Sin[(#1 + 1) t 2 \[Pi]] &} /@ p + 0.) 1.]],
>   44100, {44100, 16}]]
> 
> Can anyone tell me how to "correct" the problem? The intent is to
> "automate" the playback of several "paired" pitches.

There seem to be three problems with your code:
1) the pure function termination is at the wrong place
2) Play doesn't like the list of list, so I Flatten the resulting list
of lists
3) Play has attribute HoldAll, so we need to Evaluate to enforce the
evaluation.

Honestly my impression is that Play has some problems handling input
that it doesn't accept, my Kernel died a few times when experimenting
with it...

The follwing works, although I doubt it does what you intended (it plays
on 10 channels.):

p = {440, 550, 660, 770, 880};

Play[
 Evaluate[Flatten[{Sin[# t 2 Pi], Sin[(# + 1) t 2 Pi]} & /@ p]],
 {t, 0, 1}, SampleRate -> 44100, SampleDepth -> 16
 ]

Maybe this is closer to what you want? It adds up the signals instead of
playing them on different channels...

Play[
 Evaluate[
  Plus @@ Flatten[{Sin[# t 2 Pi], Sin[(# + 1) t 2 Pi]} & /@ p]],
 {t, 0, 1}, SampleRate -> 44100, SampleDepth -> 16
 ]

hth,

albert


  • Prev by Date: Best method to break apart a data set
  • Next by Date: Updating old packages to later Ma versions
  • Previous by thread: Using MapAt with Play
  • Next by thread: Re: Using MapAt with Play