MathGroup Archive 2009

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

Search the Archive

Re: Using "/@" Effectively

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104321] Re: [mg104292] Using "/@" Effectively
  • From: Mark Perrin <m.perrin at me.com>
  • Date: Tue, 27 Oct 2009 05:00:46 -0500 (EST)
  • References: <200910260425.XAA18594@smc.vnet.net>

I think that instead of:

Sound[melody[#1, #2] & /@ {{0, 1}, {5, 0.5}, {7, 0.5}, {12, 1}}, {0,
3}, SoundVolume -> .5], at 3:25 PM, BenT wrote:

it should be:

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

As you are mapping one list over the function, but want to insert part  
1 and part 2 of each item in that list.

Also the list should be:

{{0, 1.0}, {5, 0.5}, {7, 0.5}, {12, 1.0}}

instead of:

{{0, 1}, {5, 0.5}, {7, 0.5}, {12, 1}}, {0,
3}

If you are using Reals in position 2

Hope that is what you meant,

Cheers,

Mark Perrin


On 26/10/2009, at 3:25 PM, 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]
>
> Can anyone show me the correct (or even a better) way to do so?
>
>
>



  • Prev by Date: Notebook
  • Next by Date: Re: Using "/@" Effectively
  • Previous by thread: Re: Using "/@" Effectively
  • Next by thread: Re: Using "/@" Effectively