To add your own measures for scoring the melodic singing data, outputted by the pYIN algorithm, you can use the additional_scoring_measures argument to the SAA or SAA_standalone functions.

The argument should be a function with the following arguments: onset, dur, freq, note, stimuli, stimuli_durations or a list of functions, each with the same arguments.

Here are some examples.

Example 1

Here is the inclusion of a trivial scoring measure which counts the number of sung notes above C4 (MIDI pitch 60).

check_no_notes_above_c4 <- function(onset, dur, freq, note, stimuli, stimuli_durations) {
  # C4 is MIDI note number 60
  sum(note > 60)

}


SAA::SAA_standalone(skip_setup = TRUE,
                    app_name = 'additional_measures',
                    num_items = list(long_tones = 2L, arrhythmic = 2L, rhythmic = 2L),
                     examples = 0,
                     max_goes = 1L,
                     additional_scoring_measures = check_no_notes_above_c4)

Example 2

Here is another trivial scoring function which takes the log of some of the user’s melodic production data, the stimuli durations and multiplies the frequencies by 2. There is no reason why this would be useful, but is a way of demonstrating that you can transform the melodic production variables, and also store them in a dataframe.

library(SAA)


log_scores <- function(onset, dur, freq, note, stimuli, stimuli_durations) {

  tibble::tibble(log_onset = log(onset),
                 log_dur = log(dur),
                 freq_2 = freq * 2,
                 stimuli_durations = log(stimuli_durations))

}

Example 3

Include the last two functions as a list, for both function results to appear in the results file:

SAA::SAA_standalone(skip_setup = TRUE,
                    app_name = 'additional_measures',
                    num_items = list(long_tones = 2L, arrhythmic = 2L, rhythmic = 2L),
                    examples = 0,
                    max_goes = 1L,
                    additional_scoring_measures = list(check_no_notes_above_c4, log_scores))