MathGroup Archive 2009

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

Search the Archive

Re: Using "/@" Effectively

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104314] Re: Using "/@" Effectively
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Tue, 27 Oct 2009 04:59:27 -0500 (EST)

On 10/25/09 at 11:25 PM, brtubb at pdmusic.org (BenT) wrote:

>Given:

>$Version "7.0 for Microsoft Windows (32-bit) (January 30, 2009)"
>
>miditofreq[n_Integer] := (440./64) 2^((n + 3)/12);

>and

>melody[p_Integer, d_Real] :=
>Play[Sin[miditofreq[p] 2 \[Pi] t], {t, 0, d}, SampleRate -> 44100,
>SampleDepth -> 16]

>I want to be able to use a list of pitch and duration values for a
>melody, and use it like the following, but cannot determine the
>method to Map them properly, as in this (non-working) attempt:

>Sound[melody[#1, #2] & /@ {{0, 1}, {5, 0.5}, {7, 0.5}, {12, 1}}, {0,
>3}, SoundVolume -> .5]

That doesn't work because you are looking for two arguments yet
only providing one argument, a list with two elements. Change it to:

Sound[melody[#1[[1]], #1[[2]]] & /@ {{0, 1}, {5, 0.5}, {7, 0.5},
{12, 1}}, {0,
3}, SoundVolume -> .5]

or

Sound[melody[#1, #2] & @@@ {{0, 1}, {5, 0.5}, {7, 0.5}, {12,
1}}, {0,
3}, SoundVolume -> .5]

and you will get the result you want.




  • Prev by Date: Re: Calculating a given total using only given specific
  • Next by Date: Re: Summing all the elements along a dimension in a matrix
  • Previous by thread: Re: Using "/@" Effectively
  • Next by thread: Re: Using "/@" Effectively