<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">Pessoal, boa tarde!</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Em 15 de março a r-br completará 5 anos. Meus parabéns aos mantenedores da lista e todos seus usuários por essa importante fonte de aprendizado.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">Abaixo vai um código que encontrei na rede e que permite tocar o "Parabéns pra você" no R.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">### <code r></font></div><div class="gmail_default"><font face="monospace, monospace"># browseURL("<a href="http://stackoverflow.com/questions/31782580/how-can-i-play-birthday-music-using-r" target="_blank">http://stackoverflow.com/questions/31782580/how-can-i-play-birthday-music-using-r</a>")</font></div><div class="gmail_default"><font face="monospace, monospace">library("dplyr")</font></div><div class="gmail_default"><font face="monospace, monospace">library("audio")</font></div><div class="gmail_default"><font face="monospace, monospace">notes <- c(A = 0, B = 2, C = 3, D = 5, E = 7, F = 8, G = 10)</font></div><div class="gmail_default"><font face="monospace, monospace">pitch <- "D D E D G F# D D E D A G D D D5 B G F# E C5 C5 B G A G"</font></div><div class="gmail_default"><font face="monospace, monospace">duration <- c(rep(c(0.75, 0.25, 1, 1, 1, 2), 2),</font></div><div class="gmail_default"><font face="monospace, monospace"> 0.75, 0.25, 1, 1, 1, 1, 1, 0.75, 0.25, 1, 1, 1, 2)</font></div><div class="gmail_default"><font face="monospace, monospace">bday <- data_frame(pitch = strsplit(pitch, " ")[[1]],</font></div><div class="gmail_default"><font face="monospace, monospace"> duration = duration)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">bday <-</font></div><div class="gmail_default"><font face="monospace, monospace"> bday %>%</font></div><div class="gmail_default"><font face="monospace, monospace"> mutate(octave = substring(pitch, nchar(pitch)) %>%</font></div><div class="gmail_default"><font face="monospace, monospace"> {suppressWarnings(as.numeric(.))} %>%</font></div><div class="gmail_default"><font face="monospace, monospace"> ifelse(<a href="http://is.na" target="_blank">is.na</a>(.), 4, .),</font></div><div class="gmail_default"><font face="monospace, monospace"> note = notes[substr(pitch, 1, 1)],</font></div><div class="gmail_default"><font face="monospace, monospace"> note = note + grepl("#", pitch) -</font></div><div class="gmail_default"><font face="monospace, monospace"> grepl("b", pitch) + octave * 12 +</font></div><div class="gmail_default"><font face="monospace, monospace"> 12 * (note < 3),</font></div><div class="gmail_default"><font face="monospace, monospace"> freq = 2 ^ ((note - 60) / 12) * 440)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">tempo <- 120</font></div><div class="gmail_default"><font face="monospace, monospace">sample_rate <- 44100</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">make_sine <- function(freq, duration) {</font></div><div class="gmail_default"><font face="monospace, monospace"> wave <- sin(seq(0, duration / tempo * 60, 1 / sample_rate) *</font></div><div class="gmail_default"><font face="monospace, monospace"> freq * 2 * pi)</font></div><div class="gmail_default"><font face="monospace, monospace"> fade <- seq(0, 1, 50 / sample_rate)</font></div><div class="gmail_default"><font face="monospace, monospace"> wave * c(fade, rep(1, length(wave) - 2 * length(fade)), rev(fade))</font></div><div class="gmail_default"><font face="monospace, monospace">}</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">bday_wave <-</font></div><div class="gmail_default"><font face="monospace, monospace"> mapply(make_sine, bday$freq, bday$duration) %>%</font></div><div class="gmail_default"><font face="monospace, monospace"> do.call("c", .)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">play(bday_wave)</font></div><div class="gmail_default"><font face="monospace, monospace">### </code></font></div></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><font face="arial, helvetica, sans-serif" style="font-size:small"><div style="font-family:'trebuchet ms',sans-serif;display:inline"></div></font><font face="arial, helvetica, sans-serif" style="font-size:12.8px"><span style="font-size:small">================================================</span><br>Éder Comunello</font><div style="font-size:12.8px"><span style="font-family:arial,helvetica,sans-serif">Agronomist (UEM), MSc in Environ. Sciences (UEM)</span><font face="arial, helvetica, sans-serif"><br></font></div><div style="font-size:12.8px"><div style="font-size:small"><span style="font-family:arial,helvetica,sans-serif">DSc in Agricultural Systems Engineering (USP/Esalq)</span><br></div><div><span style="font-size:small">Brazilian Agricultural Research Corporation (</span><font face="arial, helvetica, sans-serif" style="font-size:small">Embrapa)</font></div><div><div><font face="arial, helvetica, sans-serif" style="font-size:small">Dourados, MS, Brazil </font><font face="arial, helvetica, sans-serif" size="2">|<O>|</font></div><div style="font-size:small"><span style="font-family:arial,helvetica,sans-serif">================================================</span><br></div></div></div><div style="font-size:small"><font face="arial, helvetica, sans-serif">GEO, </font>-22.2752, -54.8182, 408m<span style="font-family:arial,helvetica,sans-serif"><br></span></div><div style="font-size:12.8px"><span style="font-size:small;font-family:arial,helvetica,sans-serif">UTC-04:00 / DST: UTC-03:00</span></div><div><div><div><br></div><div><br></div></div><div style="font-size:small"><br></div></div></div></div></div></div></div></div></div></div></div>
</div>