Re: Using "/@" Effectively
- To: mathgroup at smc.vnet.net
- Subject: [mg104316] Re: Using "/@" Effectively
- From: Nicholas <physnick at gmail.com>
- Date: Tue, 27 Oct 2009 04:59:50 -0500 (EST)
- References: <hc38lq$iae$1@smc.vnet.net>
Ben, Nice, but each mapped element is a list by itself, so you need something like Sound[melody[#[[1]], #[[2]]] & /@ {{0, 1.}, {5, 0.5}, {7, 0.5}, {12, 1.}}, {0, 3.}, SoundVolume -> .5] Also, I would change the definition of your original "melody" and "miditofreq" to accept any input, not just real numbers and integers, since it did not produce the desired output when run. This has more generality, yet the same function: melody[p_, d_] := Play[Sin[miditofreq[p] 2 \[Pi] t], {t, 0, d}, SampleRate -> 44100, SampleDepth -> 16] Additionally, I would be surprised if you could hear the melody that you have listed since the frequencies are around 10 Hz, which we won't recognize as a tone. Good luck, Nick. On Oct 26, 12:30 am, BenT <brt... at pdmusic.org> 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?