Skip to content

Instantly share code, notes, and snippets.

@tycheleturner
Created December 23, 2022 17:01
Show Gist options
  • Save tycheleturner/004c5b76b7dc7ba4c08b5f8ed06b7039 to your computer and use it in GitHub Desktop.
Save tycheleturner/004c5b76b7dc7ba4c08b5f8ed06b7039 to your computer and use it in GitHub Desktop.
#!/bin/Rscript
# Tychele N. Turner, Ph.D.
# December 23, 2022
# Up on the Housetop in R
#install the Rmusic package if you do not already have it
#devtools::install_github("keithmcnulty/Rmusic", build_vignettes = TRUE)
#load library
library("Rmusic")
#note from Rmusic package: default is 4th piano octave (lower is 3, higher is 5)
#set the pitch
uoth_pitch <- paste(
"D5 D5 E5 D5 B A",
"G B D5",
"E5 E5 D5 B",
"A D5 D5",
"D5 D5 E5 D5 B A",
"G B D5",
"E5 E5 E5 D5 D5 B",
"A D5 G",
"C5, C5, E5",
"D5 D5 D5 B",
"A C5 C5",
"B D5 D5 G B",
"D5 D5 E5 D5 B",
"C5 D5 E5",
"D5 D5 E5 D5 D5 B",
"A D5 G"
)
uoth_pitch <- strsplit(uoth_pitch, " ")[[1]]
# set the time
uoth_duration <- c(
1, 0.5, 0.5, 1, 0.5, 0.5,
1, 1, 2,
1, 1, 1, 1,
1, 1, 2,
1, 0.5, 0.5, 1, 0.5, 0.5,
1, 1, 2,
1, 0.5, 0.5, 0.5, 0.5, 1,
1, 1, 2,
1, 1, 2,
1, 0.5, 0.5, 2,
1, 1, 2,
1, 0.5, 0.5, 1, 1,
1, 0.5, 0.5, 1, 1,
1, 1, 1,
1, 0.5, 0.5, 0.5, 0.5, 1,
1, 1, 1
)
# play the music
Rmusic::play_music(uoth_pitch, uoth_duration)
# save the music
Rmusic::save_music(uoth_pitch, uoth_duration, output_file = "up_on_the_housetop.wav")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment