latex_format <- FALSE # set TRUE to compile the LaTeX paper save_figures <- FALSE # set TRUE to compile the LaTeX paper
These analyses are the ones reported in paper titled "onsetsync: An R Package for Onset Synchrony Analysis" (submitted) by Tuomas Eerola and Martin Clayton. The sections and figures correspond to the manuscript.
library(dplyr) library(ggplot2) devtools::install_github("tuomaseerola/onsetsync") library(onsetsync) packageVersion("onsetsync")
library(dplyr) library(ggplot2) library(onsetsync) packageVersion("onsetsync")
data("CSS_IEMP", package = "onsetsync") CSS_Song2 <- CSS_IEMP[[2]] CSS_Song2 <- dplyr::select(CSS_Song2,Piece,Section,Clave,Bass,Guitar,Tres,SD,Cycle,Isochronous.SD.Time) # delete previous print(knitr::kable(head(CSS_Song2),digits = 2,format = if(latex_format==TRUE){'latex'} else {'markdown'}))
tab1 <- summarise_onsets(df = CSS_Song2, instr = c('Clave','Bass','Guitar','Tres','Isochronous.SD.Time')) print(knitr::kable(tab1, digits = 1,format = if(latex_format==TRUE){'latex'} else {'markdown'}))
print(plot_by_beat(df = CSS_Song2, instr = c('Bass','Clave','Guitar','Tres'), beat = 'SD', virtual='Isochronous.SD.Time', pcols=2))
if(save_figures==TRUE){ fig1<-plot_by_beat(df = CSS_Song2, instr = c('Bass','Clave','Guitar','Tres'), beat = 'SD', virtual='Isochronous.SD.Time', pcols=2) ggsave(filename = 'figure1.pdf',fig1,height = 4,width = 7.5) }
Begin with a diagnostic plot.
print(plot_by_beat(df = CSS_Song2, instr = c('Guitar','Tres'), beat = 'SD', virtual = 'Isochronous.SD.Time', griddeviations = TRUE))
if(save_figures==TRUE){ fig2 <- plot_by_beat(df = CSS_Song2, instr = c('Guitar','Tres'), beat = 'SD', virtual = 'Isochronous.SD.Time', griddeviations = TRUE) print(fig2) ggsave(filename = 'figure2.pdf',fig2,height = 6,width = 10) }
d1 <- sync_sample_paired(CSS_Song2, instr1 = "Guitar", instr2 = "Tres", beat = "SD") dplyr::summarise(data.frame(d1), N = n(), Mean.ms = mean(asynch*1000), Sd.ms = sd(asynch*1000))
inst <- c('Clave','Bass','Guitar','Tres') # Define instruments dn <- sync_execute_pairs(CSS_Song2,inst,beat = "SD") print(plot_by_pair(dn))
if(save_figures==TRUE){ fig3 <- plot_by_pair(dn) # plot print(fig3) ggsave(filename = 'figure3.pdf',fig5,height = 4,width = 6) }
Reporting of several measures of absolute asyncronies.
d <- sync_sample_paired(CSS_Song2,'Clave','Bass',beat = 'SD') print(summarise_sync(d))
Relative measure for two instruments vs other other instruments.
x<-sync_sample_paired_relative(df = CSS_Song2,instr = 'Bass',instr_ref = c('Guitar','Bass','Tres','Clave'),beat = 'SD') print(x$`Mean pairwise asynchrony`) x <- sync_sample_paired_relative(df = CSS_Song2,instr = 'Clave',instr_ref = c('Guitar','Bass','Tres','Clave'),beat = 'SD') print(x$`Mean pairwise asynchrony`)
dn <- sync_execute_pairs(df = CSS_Song2, instruments = c("Guitar", "Tres"),beat = "SD") print(summarise_sync_by_pair(dn, bybeat = TRUE))
Using the built-in corpus of Cuban Salsa and Son preformances (CSS_IEMP
).
corpus <- onsetsync::CSS_IEMP D <- sync_sample_paired(corpus,'Guitar','Tres',n=0,beat='SD') D <- D$asynch D$asynch_abs <- abs(D$asynch)*1000 print(paste('Mean asynchrony across all performances is', round(mean(D$asynch)*1000,1),'ms'))
print(plot_by_dataset(D,'asynch_abs','name', box = TRUE) + ylab('Absolute Asynchrony (ms)'))
if(save_figures==TRUE){ fig4 <- plot_by_dataset(D,'asynch_abs','name', box = TRUE) fig4 + ylab('Absolute Asynchrony (ms)') ggsave(filename = 'figure4.pdf',fig7,height = 3.5,width = 6) }
CSS_Song2 <- CSS_Song2 %>% group_by(Cycle) %>% mutate(Tempo = 240/(max(Isochronous.SD.Time) - min(Isochronous.SD.Time))) %>% ungroup() d2 <- sync_sample_paired(CSS_Song2,"Tres","Guitar", beat = 'Tempo') d3 <- sync_sample_paired(CSS_Song2,"Tres","Guitar", beat = 'Isochronous.SD.Time') tmp <- data.frame(asynch = d2$asynch*1000, Tempo = d2$beatL, Time = d3$beatL) fig<-plot_by_var_time(tmp,var1 = "Time", var2="asynch",var3="Tempo",ylabel='Synchrony (ms)') print(fig)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.