| compmus_match_pitch_template | R Documentation |
Compares chroma vectors in a data frame against a list of templates, most likely key or chord profiles.
compmus_match_pitch_template( dat, templates, method = "cosine", norm = "euclidean" )
dat |
A data frame containing chroma vectors in a |
templates |
A data frame with a |
method |
A character string indicating which distance metric to use (see
|
norm |
An optional character string indicating the method for
pre-normalising each vector with |
A tibble with columns start, duration, name, and
d.
library(tidyverse)
circshift <- function(v, n) {
if (n == 0) v else c(tail(v, n), head(v, -n))
}
major_chord <-
c(1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0)
minor_chord <-
c(1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0)
chord_templates <-
tribble(
~name, ~template,
"D:min", circshift(minor_chord, 2),
"F:maj", circshift(major_chord, 5),
"A:min", circshift(minor_chord, 9),
"C:maj", circshift(major_chord, 0),
"E:min", circshift(minor_chord, 4),
"G:maj", circshift(major_chord, 7),
"B:min", circshift(minor_chord, 11)
)
get_tidy_audio_analysis("5UVsbUV0Kh033cqsZ5sLQi") %>%
compmus_align(sections, segments) %>%
select(sections) %>%
unnest(sections) %>%
mutate(
pitches =
map(segments,
compmus_summarise, pitches,
method = "mean", norm = "manhattan"
)
) %>%
compmus_match_pitch_template(chord_templates, "euclidean", "manhattan")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.