From 3d2eba93a6ed0170edaf3bd9e63e050ff058d718 Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Sat, 4 Mar 2023 19:27:51 -0500 Subject: [PATCH 01/13] added octave_ratio to expand harmonics --- R/expand-harmonics.R | 30 +++++++++-------- man/expand_harmonics.Rd | 14 +++++--- man/play_wav.Rd | 1 + man/save_wav.Rd | 1 + man/sparse_fr_spectrum.Rd | 1 + man/sparse_pc_spectrum.Rd | 1 + man/sparse_pi_spectrum.Rd | 1 + man/wave.Rd | 1 + tests/testthat/test-expand_harmonics.R | 40 ++++++++++++++++++++++ tests/testthat/test-sparse_fr_spectrum.R | 42 ++++++++++++++++++++++++ 10 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 tests/testthat/test-sparse_fr_spectrum.R diff --git a/R/expand-harmonics.R b/R/expand-harmonics.R index 57b2bde..f78295f 100644 --- a/R/expand-harmonics.R +++ b/R/expand-harmonics.R @@ -22,6 +22,9 @@ #' @param label_harmonics #' If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers. #' +#' @param octave_ratio +#' The octave ratio for stretching and compressing harmonics, defaults to 2.0. +#' #' @rdname expand_harmonics #' #' @inheritParams collapse_summing_amplitudes @@ -31,7 +34,8 @@ expand_harmonics <- function(x, roll_off = 1, digits = 6, label_harmonics = FALSE, - coherent = FALSE) { + coherent = FALSE, + octave_ratio = 2.0) { UseMethod("expand_harmonics") } @@ -42,7 +46,8 @@ expand_harmonics.sparse_fr_spectrum <- function(x, roll_off = 1, digits = 6, label_harmonics = FALSE, - coherent = FALSE) { + coherent = FALSE, + octave_ratio = 2.0) { expand_harmonics(sparse_pi_spectrum(x), num_harmonics = num_harmonics, roll_off = roll_off, @@ -59,15 +64,17 @@ expand_harmonics.sparse_pi_spectrum <- function(x, roll_off = 1, digits = 6, label_harmonics = FALSE, - coherent = FALSE) { - template <- pi_harmonic_template(num_harmonics, roll_off) + coherent = FALSE, + octave_ratio = 2.0) { purrr::map2(pitch(x), amp(x), function(pitch, amp) { + n <- seq_len(num_harmonics) + f0 <- midi_to_freq(pitch) df <- data.frame( - x = pitch + template$interval, - y = amp * template$amplitude + x = freq_to_midi(f0 * octave_ratio ^ log2(n)), + y = amp * 1 / (n ^ roll_off) ) - if (label_harmonics) df$labels <- seq_along(template$interval) + if (label_harmonics) df$labels <- seq_along(df$x) df }) %>% collapse_summing_amplitudes(digits = digits, coherent = coherent) %>% @@ -81,16 +88,11 @@ expand_harmonics.pi_chord <- function(x, roll_off = 1, digits = 6, label_harmonics = FALSE, - coherent = FALSE) { + coherent = FALSE, + octave_ratio = 2.0) { sparse_pi_spectrum(x, num_harmonics = num_harmonics, roll_off = roll_off, digits = digits, label_harmonics = label_harmonics) } - -pi_harmonic_template <- function(num_harmonics, roll_off, digits = 6) { - tibble::tibble(n = seq_len(num_harmonics), - interval = 12 * log(.data$n, base = 2), - amplitude = 1 / (.data$n ^ roll_off)) -} diff --git a/man/expand_harmonics.Rd b/man/expand_harmonics.Rd index 11aa277..0f877b8 100644 --- a/man/expand_harmonics.Rd +++ b/man/expand_harmonics.Rd @@ -13,7 +13,8 @@ expand_harmonics( roll_off = 1, digits = 6, label_harmonics = FALSE, - coherent = FALSE + coherent = FALSE, + octave_ratio = 2 ) \method{expand_harmonics}{sparse_fr_spectrum}( @@ -22,7 +23,8 @@ expand_harmonics( roll_off = 1, digits = 6, label_harmonics = FALSE, - coherent = FALSE + coherent = FALSE, + octave_ratio = 2 ) \method{expand_harmonics}{sparse_pi_spectrum}( @@ -31,7 +33,8 @@ expand_harmonics( roll_off = 1, digits = 6, label_harmonics = FALSE, - coherent = FALSE + coherent = FALSE, + octave_ratio = 2 ) \method{expand_harmonics}{pi_chord}( @@ -40,7 +43,8 @@ expand_harmonics( roll_off = 1, digits = 6, label_harmonics = FALSE, - coherent = FALSE + coherent = FALSE, + octave_ratio = 2 ) } \arguments{ @@ -66,6 +70,8 @@ assuming coherent summation, where the amplitudes simply add together (default is \code{FALSE}). Otherwise incoherent summation is used, where the amplitudes are squared, added, then square rooted.} + +\item{octave_ratio}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} } \description{ Expands each tone in an object into its implied harmonics. diff --git a/man/play_wav.Rd b/man/play_wav.Rd index 783c0e7..56e447b 100644 --- a/man/play_wav.Rd +++ b/man/play_wav.Rd @@ -37,6 +37,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} + \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} \item{\code{coherent}}{Whether the amplitudes from different spectral components should be combined assuming coherent summation, where the amplitudes simply add together (default is \code{FALSE}). diff --git a/man/save_wav.Rd b/man/save_wav.Rd index a990c0e..ce91b3d 100644 --- a/man/save_wav.Rd +++ b/man/save_wav.Rd @@ -51,6 +51,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} + \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} \item{\code{coherent}}{Whether the amplitudes from different spectral components should be combined assuming coherent summation, where the amplitudes simply add together (default is \code{FALSE}). diff --git a/man/sparse_fr_spectrum.Rd b/man/sparse_fr_spectrum.Rd index a9732bd..168a7e6 100644 --- a/man/sparse_fr_spectrum.Rd +++ b/man/sparse_fr_spectrum.Rd @@ -43,6 +43,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} + \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} \item{\code{coherent}}{Whether the amplitudes from different spectral components should be combined assuming coherent summation, where the amplitudes simply add together (default is \code{FALSE}). diff --git a/man/sparse_pc_spectrum.Rd b/man/sparse_pc_spectrum.Rd index 3d6b13c..ed45bcd 100644 --- a/man/sparse_pc_spectrum.Rd +++ b/man/sparse_pc_spectrum.Rd @@ -31,6 +31,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} + \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} }} \item{coherent}{Whether the amplitudes from different spectral components should be combined diff --git a/man/sparse_pi_spectrum.Rd b/man/sparse_pi_spectrum.Rd index 0c230bf..6084fdb 100644 --- a/man/sparse_pi_spectrum.Rd +++ b/man/sparse_pi_spectrum.Rd @@ -34,6 +34,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} + \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} }} \item{amplitude}{(Numeric vector) diff --git a/man/wave.Rd b/man/wave.Rd index 0cf9c4c..861c2a2 100644 --- a/man/wave.Rd +++ b/man/wave.Rd @@ -40,6 +40,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} + \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} \item{\code{coherent}}{Whether the amplitudes from different spectral components should be combined assuming coherent summation, where the amplitudes simply add together (default is \code{FALSE}). diff --git a/tests/testthat/test-expand_harmonics.R b/tests/testthat/test-expand_harmonics.R index 2023abb..ce56619 100644 --- a/tests/testthat/test-expand_harmonics.R +++ b/tests/testthat/test-expand_harmonics.R @@ -79,3 +79,43 @@ test_that("rounding", { c(0, 7) %>% sparse_pi_spectrum(digits = 0) ) }) +test_that('octave ratio stretches and compresses',{ + harmonic_default_result <- 60 %>% + sparse_pi_spectrum(num_harmonics=10) %>% + pitch + expect_equal(harmonic_default_result[1], 60) + expect_equal(harmonic_default_result[2], 60+12) + expect_equal(harmonic_default_result[4], 60+24) + expect_equal(harmonic_default_result[8], 60+36) + + harmonic_explicit_result <- 60 %>% + sparse_pi_spectrum(num_harmonics=10, octave_ratio = 2.0) %>% + pitch + expect_equal(harmonic_explicit_result[1], 60) + expect_equal(harmonic_explicit_result[2], 60+12) + expect_equal(harmonic_explicit_result[4], 60+24) + expect_equal(harmonic_explicit_result[8], 60+36) + + compressed_result <- 60 %>% + sparse_pi_spectrum(num_harmonics=10, octave_ratio = 1.9) %>% + pitch + expect_equal(compressed_result[1], 60) + expect_equal(compressed_result[2], + freq_to_midi(midi_to_freq(60)*1.9^log2(2))) + expect_equal(compressed_result[4], + freq_to_midi(midi_to_freq(60)*1.9^log2(4))) + expect_equal(compressed_result[8], + freq_to_midi(midi_to_freq(60)*1.9^log2(8))) + + stretcheded_result <- 60 %>% + sparse_pi_spectrum(num_harmonics=10, octave_ratio = 2.1) %>% + pitch + expect_equal(stretcheded_result[1], 60) + expect_equal(stretcheded_result[2], + freq_to_midi(midi_to_freq(60)*2.1^log2(2))) + expect_equal(stretcheded_result[4], + freq_to_midi(midi_to_freq(60)*2.1^log2(4))) + expect_equal(stretcheded_result[8], + freq_to_midi(midi_to_freq(60)*2.1^log2(8))) + +}) diff --git a/tests/testthat/test-sparse_fr_spectrum.R b/tests/testthat/test-sparse_fr_spectrum.R new file mode 100644 index 0000000..f7b091f --- /dev/null +++ b/tests/testthat/test-sparse_fr_spectrum.R @@ -0,0 +1,42 @@ +context("test-sparse_fr_spectrum") + +test_that('octave ratio stretches and compresses',{ + harmonic_default_result <- 60 %>% + sparse_fr_spectrum(num_harmonics=10) %>% + freq %>% freq_to_midi + expect_equal(harmonic_default_result[1], 60) + expect_equal(harmonic_default_result[2], 60+12) + expect_equal(harmonic_default_result[4], 60+24) + expect_equal(harmonic_default_result[8], 60+36) + + harmonic_explicit_result <- 60 %>% + sparse_fr_spectrum(num_harmonics=10, octave_ratio = 2.0) %>% + freq %>% freq_to_midi + expect_equal(harmonic_explicit_result[1], 60) + expect_equal(harmonic_explicit_result[2], 60+12) + expect_equal(harmonic_explicit_result[4], 60+24) + expect_equal(harmonic_explicit_result[8], 60+36) + + compressed_result <- 60 %>% + sparse_fr_spectrum(num_harmonics=10, octave_ratio = 1.9) %>% + freq %>% freq_to_midi + expect_equal(compressed_result[1], 60) + expect_equal(compressed_result[2], + freq_to_midi(midi_to_freq(60)*1.9^log2(2))) + expect_equal(compressed_result[4], + freq_to_midi(midi_to_freq(60)*1.9^log2(4))) + expect_equal(compressed_result[8], + freq_to_midi(midi_to_freq(60)*1.9^log2(8))) + + stretcheded_result <- 60 %>% + sparse_fr_spectrum(num_harmonics=10, octave_ratio = 2.1) %>% + freq %>% freq_to_midi + expect_equal(stretcheded_result[1], 60) + expect_equal(stretcheded_result[2], + freq_to_midi(midi_to_freq(60)*2.1^log2(2))) + expect_equal(stretcheded_result[4], + freq_to_midi(midi_to_freq(60)*2.1^log2(4))) + expect_equal(stretcheded_result[8], + freq_to_midi(midi_to_freq(60)*2.1^log2(8))) + +}) From fdd8fecefae27680247f7c0866d4a8acf43fd5ee Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Wed, 16 Aug 2023 18:51:50 -0400 Subject: [PATCH 02/13] changed rol off to match timbre paper --- R/expand-harmonics.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/expand-harmonics.R b/R/expand-harmonics.R index f78295f..cf580d5 100644 --- a/R/expand-harmonics.R +++ b/R/expand-harmonics.R @@ -72,7 +72,7 @@ expand_harmonics.sparse_pi_spectrum <- function(x, f0 <- midi_to_freq(pitch) df <- data.frame( x = freq_to_midi(f0 * octave_ratio ^ log2(n)), - y = amp * 1 / (n ^ roll_off) + y = 1 * 10 ^ ( -roll_off * log2(n) / 20) ) if (label_harmonics) df$labels <- seq_along(df$x) df From dba8b24d36541029dc291842d42c23553285a40c Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Wed, 16 Aug 2023 18:58:05 -0400 Subject: [PATCH 03/13] roll off dB --- R/expand-harmonics.R | 16 ++++++++-------- R/smooth-pc-spectrum.R | 6 +++--- R/smooth-pi-spectrum.R | 4 ++-- man/expand_harmonics.Rd | 10 +++++----- man/play_wav.Rd | 2 +- man/save_wav.Rd | 2 +- man/smooth_pc_spectrum.Rd | 6 +++--- man/smooth_pi_spectrum.Rd | 4 ++-- man/sparse_fr_spectrum.Rd | 2 +- man/sparse_pc_spectrum.Rd | 2 +- man/sparse_pi_spectrum.Rd | 2 +- man/wave.Rd | 2 +- tests/testthat/test-expand_harmonics.R | 4 ++-- tests/testthat/test-gaussian_filter.R | 2 +- 14 files changed, 32 insertions(+), 32 deletions(-) diff --git a/R/expand-harmonics.R b/R/expand-harmonics.R index cf580d5..4154919 100644 --- a/R/expand-harmonics.R +++ b/R/expand-harmonics.R @@ -13,7 +13,7 @@ #' Number of harmonics (including the fundamental) to which #' each tone should be expanded. #' -#' @param roll_off (Numeric scalar) Parametrises the amount of amplitude roll-off +#' @param roll_off_dB (Numeric scalar) Parametrises the amount of amplitude roll-off #' in the harmonics, with greater values corresponding to higher roll-off. #' #' @param digits @@ -31,7 +31,7 @@ #' @export expand_harmonics <- function(x, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, digits = 6, label_harmonics = FALSE, coherent = FALSE, @@ -43,14 +43,14 @@ expand_harmonics <- function(x, #' @export expand_harmonics.sparse_fr_spectrum <- function(x, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, digits = 6, label_harmonics = FALSE, coherent = FALSE, octave_ratio = 2.0) { expand_harmonics(sparse_pi_spectrum(x), num_harmonics = num_harmonics, - roll_off = roll_off, + roll_off_dB = roll_off_dB, digits = digits, label_harmonics = label_harmonics, coherent = coherent) %>% @@ -61,7 +61,7 @@ expand_harmonics.sparse_fr_spectrum <- function(x, #' @export expand_harmonics.sparse_pi_spectrum <- function(x, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, digits = 6, label_harmonics = FALSE, coherent = FALSE, @@ -72,7 +72,7 @@ expand_harmonics.sparse_pi_spectrum <- function(x, f0 <- midi_to_freq(pitch) df <- data.frame( x = freq_to_midi(f0 * octave_ratio ^ log2(n)), - y = 1 * 10 ^ ( -roll_off * log2(n) / 20) + y = 1 * 10 ^ ( -roll_off_dB * log2(n) / 20) ) if (label_harmonics) df$labels <- seq_along(df$x) df @@ -85,14 +85,14 @@ expand_harmonics.sparse_pi_spectrum <- function(x, #' @export expand_harmonics.pi_chord <- function(x, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, digits = 6, label_harmonics = FALSE, coherent = FALSE, octave_ratio = 2.0) { sparse_pi_spectrum(x, num_harmonics = num_harmonics, - roll_off = roll_off, + roll_off_dB = roll_off_dB, digits = digits, label_harmonics = label_harmonics) } diff --git a/R/smooth-pc-spectrum.R b/R/smooth-pc-spectrum.R index 6e90dfe..1ca245f 100644 --- a/R/smooth-pc-spectrum.R +++ b/R/smooth-pc-spectrum.R @@ -75,7 +75,7 @@ smooth_pc_spectrum <- function( ..., sigma = 6.83, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, coherent = FALSE ) { UseMethod("smooth_pc_spectrum") @@ -88,12 +88,12 @@ smooth_pc_spectrum.default <- function( ..., sigma = 6.83, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, coherent = FALSE ) { smooth_pc_spectrum(sparse_pc_spectrum(x, num_harmonics = num_harmonics, - roll_off = roll_off, + roll_off_dB = roll_off_dB, coherent = coherent), sigma = sigma, coherent = coherent, diff --git a/R/smooth-pi-spectrum.R b/R/smooth-pi-spectrum.R index 8133cbc..739c8f5 100644 --- a/R/smooth-pi-spectrum.R +++ b/R/smooth-pi-spectrum.R @@ -79,12 +79,12 @@ smooth_pi_spectrum <- function(x, sigma = 6.83, ...) { smooth_pi_spectrum.default <- function(x, sigma = 6.83, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, coherent = FALSE, ...) { smooth_pi_spectrum(sparse_pi_spectrum(x, num_harmonics = num_harmonics, - roll_off = roll_off, + roll_off_dB = roll_off_dB, coherent = coherent, ...), sigma = sigma, diff --git a/man/expand_harmonics.Rd b/man/expand_harmonics.Rd index 0f877b8..0130112 100644 --- a/man/expand_harmonics.Rd +++ b/man/expand_harmonics.Rd @@ -10,7 +10,7 @@ expand_harmonics( x, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, digits = 6, label_harmonics = FALSE, coherent = FALSE, @@ -20,7 +20,7 @@ expand_harmonics( \method{expand_harmonics}{sparse_fr_spectrum}( x, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, digits = 6, label_harmonics = FALSE, coherent = FALSE, @@ -30,7 +30,7 @@ expand_harmonics( \method{expand_harmonics}{sparse_pi_spectrum}( x, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, digits = 6, label_harmonics = FALSE, coherent = FALSE, @@ -40,7 +40,7 @@ expand_harmonics( \method{expand_harmonics}{pi_chord}( x, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, digits = 6, label_harmonics = FALSE, coherent = FALSE, @@ -58,7 +58,7 @@ Should be of class Number of harmonics (including the fundamental) to which each tone should be expanded.} -\item{roll_off}{(Numeric scalar) Parametrises the amount of amplitude roll-off +\item{roll_off_dB}{(Numeric scalar) Parametrises the amount of amplitude roll-off in the harmonics, with greater values corresponding to higher roll-off.} \item{digits}{Number of digits to which each partial's MIDI pitch should be rounded.} diff --git a/man/play_wav.Rd b/man/play_wav.Rd index 56e447b..86d35a7 100644 --- a/man/play_wav.Rd +++ b/man/play_wav.Rd @@ -33,7 +33,7 @@ Chord fade-out time (seconds).} \item{\code{num_harmonics}}{(Integerish scalar) Number of harmonics (including the fundamental) to which each tone should be expanded.} - \item{\code{roll_off}}{(Numeric scalar) Parametrises the amount of amplitude roll-off + \item{\code{roll_off_dB}}{(Numeric scalar) Parametrises the amount of amplitude roll-off in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} diff --git a/man/save_wav.Rd b/man/save_wav.Rd index ce91b3d..9e388c7 100644 --- a/man/save_wav.Rd +++ b/man/save_wav.Rd @@ -47,7 +47,7 @@ used to avoid clicks and other artifacts.} \item{\code{num_harmonics}}{(Integerish scalar) Number of harmonics (including the fundamental) to which each tone should be expanded.} - \item{\code{roll_off}}{(Numeric scalar) Parametrises the amount of amplitude roll-off + \item{\code{roll_off_dB}}{(Numeric scalar) Parametrises the amount of amplitude roll-off in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} diff --git a/man/smooth_pc_spectrum.Rd b/man/smooth_pc_spectrum.Rd index 570d246..035021e 100644 --- a/man/smooth_pc_spectrum.Rd +++ b/man/smooth_pc_spectrum.Rd @@ -11,7 +11,7 @@ smooth_pc_spectrum( ..., sigma = 6.83, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, coherent = FALSE ) @@ -20,7 +20,7 @@ smooth_pc_spectrum( ..., sigma = 6.83, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, coherent = FALSE ) @@ -41,7 +41,7 @@ perceptual blurring. Defaults to 6.83 cents, after Number of harmonics (including the fundamental) to which each tone should be expanded.} -\item{roll_off}{(Numeric scalar) Parametrises the amount of amplitude roll-off +\item{roll_off_dB}{(Numeric scalar) Parametrises the amount of amplitude roll-off in the harmonics, with greater values corresponding to higher roll-off.} \item{coherent}{Whether the amplitudes from different spectral components should be combined diff --git a/man/smooth_pi_spectrum.Rd b/man/smooth_pi_spectrum.Rd index 2cb8295..6d691ae 100644 --- a/man/smooth_pi_spectrum.Rd +++ b/man/smooth_pi_spectrum.Rd @@ -12,7 +12,7 @@ smooth_pi_spectrum(x, sigma = 6.83, ...) x, sigma = 6.83, num_harmonics = 11L, - roll_off = 1, + roll_off_dB = 1, coherent = FALSE, ... ) @@ -34,7 +34,7 @@ perceptual blurring. Defaults to 6.83 cents, after Number of harmonics (including the fundamental) to which each tone should be expanded.} -\item{roll_off}{(Numeric scalar) Parametrises the amount of amplitude roll-off +\item{roll_off_dB}{(Numeric scalar) Parametrises the amount of amplitude roll-off in the harmonics, with greater values corresponding to higher roll-off.} \item{coherent}{Whether the amplitudes from different spectral components should be combined diff --git a/man/sparse_fr_spectrum.Rd b/man/sparse_fr_spectrum.Rd index 168a7e6..41a22dd 100644 --- a/man/sparse_fr_spectrum.Rd +++ b/man/sparse_fr_spectrum.Rd @@ -39,7 +39,7 @@ and correspond to a numeric vector of amplitudes. \item{\code{num_harmonics}}{(Integerish scalar) Number of harmonics (including the fundamental) to which each tone should be expanded.} - \item{\code{roll_off}}{(Numeric scalar) Parametrises the amount of amplitude roll-off + \item{\code{roll_off_dB}}{(Numeric scalar) Parametrises the amount of amplitude roll-off in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} diff --git a/man/sparse_pc_spectrum.Rd b/man/sparse_pc_spectrum.Rd index ed45bcd..a837a9e 100644 --- a/man/sparse_pc_spectrum.Rd +++ b/man/sparse_pc_spectrum.Rd @@ -27,7 +27,7 @@ sparse_pc_spectrum(x, ...) \item{\code{num_harmonics}}{(Integerish scalar) Number of harmonics (including the fundamental) to which each tone should be expanded.} - \item{\code{roll_off}}{(Numeric scalar) Parametrises the amount of amplitude roll-off + \item{\code{roll_off_dB}}{(Numeric scalar) Parametrises the amount of amplitude roll-off in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} diff --git a/man/sparse_pi_spectrum.Rd b/man/sparse_pi_spectrum.Rd index 6084fdb..d291879 100644 --- a/man/sparse_pi_spectrum.Rd +++ b/man/sparse_pi_spectrum.Rd @@ -30,7 +30,7 @@ sparse_pi_spectrum(x, ...) \item{\code{num_harmonics}}{(Integerish scalar) Number of harmonics (including the fundamental) to which each tone should be expanded.} - \item{\code{roll_off}}{(Numeric scalar) Parametrises the amount of amplitude roll-off + \item{\code{roll_off_dB}}{(Numeric scalar) Parametrises the amount of amplitude roll-off in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} diff --git a/man/wave.Rd b/man/wave.Rd index 861c2a2..83f79f7 100644 --- a/man/wave.Rd +++ b/man/wave.Rd @@ -36,7 +36,7 @@ wave(x, ...) \item{\code{num_harmonics}}{(Integerish scalar) Number of harmonics (including the fundamental) to which each tone should be expanded.} - \item{\code{roll_off}}{(Numeric scalar) Parametrises the amount of amplitude roll-off + \item{\code{roll_off_dB}}{(Numeric scalar) Parametrises the amount of amplitude roll-off in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} diff --git a/tests/testthat/test-expand_harmonics.R b/tests/testthat/test-expand_harmonics.R index ce56619..19624d3 100644 --- a/tests/testthat/test-expand_harmonics.R +++ b/tests/testthat/test-expand_harmonics.R @@ -36,14 +36,14 @@ test_that("misc", { test_that("roll-off", { pi_chord(0) %>% - expand_harmonics(num_harmonics = 6, roll_off = 2) %>% + expand_harmonics(num_harmonics = 6, roll_off_dB = 2) %>% {amp(.)} %>% expect_equal(c(1, 1 / 2 ^ 2, 1 / 3 ^ 2, 1 / 4 ^ 2, 1 / 5 ^ 2, 1 / 6 ^ 2)) }) test_that("MIDI transposition", { pi_chord(0) %>% - expand_harmonics(num_harmonics = 6, roll_off = 2) %>% + expand_harmonics(num_harmonics = 6, roll_off_dB = 2) %>% {pitch(.)} %>% expect_equal(c(10, 22, 29, 34, 38, 41), tolerance = 1) diff --git a/tests/testthat/test-gaussian_filter.R b/tests/testthat/test-gaussian_filter.R index 6d16e1d..89599e0 100644 --- a/tests/testthat/test-gaussian_filter.R +++ b/tests/testthat/test-gaussian_filter.R @@ -4,7 +4,7 @@ test_that("worked example", { fr_chord(100) %>% filter_spectrum_gaussian(location = c(100, 1000, 2000), width = 100, - roll_off = 0, num_harmonics = 30) %>% + roll_off_dB = 0, num_harmonics = 30) %>% tibble::as_tibble() %>% (function(x) x[x$y > 0.2, ]) %>% expect_equal(tibble::tribble( From c4c2726ea827e026b62f5313fae28372a41f0e6c Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Mon, 24 Jun 2024 10:06:50 -0400 Subject: [PATCH 04/13] added cochlea --- DESCRIPTION | 2 +- R/sparse-spectrum.R | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index a2e8600..97973da 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ Suggests: testthat (>= 2.1.0), covr (>= 3.2.0), ggplot2 (>= 3.0.0) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Imports: plyr (>= 1.8.4), Rdpack (>= 0.9.0), diff --git a/R/sparse-spectrum.R b/R/sparse-spectrum.R index 253934f..c69ac48 100644 --- a/R/sparse-spectrum.R +++ b/R/sparse-spectrum.R @@ -78,14 +78,23 @@ set_labels.sparse_spectrum <- function(x, labels) { } #' @export -plot.sparse_spectrum <- function(x, ggplot = FALSE, xlim = NULL, ...) { +plot.sparse_spectrum <- function(x, cochlea=FALSE, ggplot = FALSE, xlim = NULL, ...) { df <- as.data.frame(x) + if (cochlea) { + greenwood <- function(frequency) { + 100 * (1 - (log10( frequency / 165.4 + 0.88 ) / 2.1)) + } + df$x = greenwood(df$x) + x_label = 'Cochlea (%)' + } else { + x_label = x_lab(x) + } if (ggplot) { assert_installed("ggplot2") ggplot2::ggplot(df, ggplot2::aes_string(x = "x", xend = "x", y = 0, yend = "y")) + ggplot2::geom_segment() + - ggplot2::scale_x_continuous(x_lab(x), limits = xlim) + + ggplot2::scale_x_continuous(x_label, limits = xlim) + ggplot2::scale_y_continuous(y_lab(x)) } else { n <- nrow(df) @@ -95,7 +104,7 @@ plot.sparse_spectrum <- function(x, ggplot = FALSE, xlim = NULL, ...) { df2$x[I + 1:3] <- df$x[i] df2$y[I + 2L] <- df$y[i] } - plot(df2$x, df2$y, xlab = x_lab(x), ylab = y_lab(x), + plot(df2$x, df2$y, xlab = x_label, ylab = y_lab(x), type = "l", xlim = xlim, ...) if (!is.null(df$labels)) { for (i in seq_len(nrow(df))) { From 3cf5e3b8c65ab58b1747c597e5550871b3c1300f Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Mon, 24 Jun 2024 10:18:06 -0400 Subject: [PATCH 05/13] bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 97973da..0dc762c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hrep Title: Harmony Representations -Version: 0.16.1 +Version: 0.16.2 Authors@R: person("Peter", "Harrison", email = "pmc.harrison@gmail.com", role = c("aut", "cre")) Description: This package provides utilities for representing and manipulating chord sequences for perceptually informed harmony modelling. From da6e06fc4ce9a7fff3b4533d43fa46a026b12750 Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Mon, 24 Jun 2024 10:19:37 -0400 Subject: [PATCH 06/13] Increment version number to 0.17.0 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0dc762c..9bf728c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hrep Title: Harmony Representations -Version: 0.16.2 +Version: 0.17.0 Authors@R: person("Peter", "Harrison", email = "pmc.harrison@gmail.com", role = c("aut", "cre")) Description: This package provides utilities for representing and manipulating chord sequences for perceptually informed harmony modelling. diff --git a/NEWS.md b/NEWS.md index 4379f60..d48bdd3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# hrep 0.17.0 + # hrep 0.16.1 - Remove unnecessary info messages. From 66dd27e75d733fd4c451abafada75871da89bde1 Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Mon, 24 Jun 2024 17:21:06 -0400 Subject: [PATCH 07/13] added log plotting --- R/sparse-spectrum.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/sparse-spectrum.R b/R/sparse-spectrum.R index c69ac48..35ef78d 100644 --- a/R/sparse-spectrum.R +++ b/R/sparse-spectrum.R @@ -78,7 +78,7 @@ set_labels.sparse_spectrum <- function(x, labels) { } #' @export -plot.sparse_spectrum <- function(x, cochlea=FALSE, ggplot = FALSE, xlim = NULL, ...) { +plot.sparse_spectrum <- function(x, cochlea=FALSE, ggplot = FALSE, xlim = NULL, trans=F, ...) { df <- as.data.frame(x) if (cochlea) { greenwood <- function(frequency) { @@ -95,6 +95,7 @@ plot.sparse_spectrum <- function(x, cochlea=FALSE, ggplot = FALSE, xlim = NULL, y = 0, yend = "y")) + ggplot2::geom_segment() + ggplot2::scale_x_continuous(x_label, limits = xlim) + + {if (trans) {ggplot2::scale_x_continuous(trans='log10')}} + ggplot2::scale_y_continuous(y_lab(x)) } else { n <- nrow(df) From 52172a56e5107d0e9249b3621853d14766c564d5 Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Mon, 24 Jun 2024 17:21:22 -0400 Subject: [PATCH 08/13] Increment version number to 0.18.0 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9bf728c..fac61ba 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hrep Title: Harmony Representations -Version: 0.17.0 +Version: 0.18.0 Authors@R: person("Peter", "Harrison", email = "pmc.harrison@gmail.com", role = c("aut", "cre")) Description: This package provides utilities for representing and manipulating chord sequences for perceptually informed harmony modelling. diff --git a/NEWS.md b/NEWS.md index d48bdd3..fb08ccf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# hrep 0.18.0 + # hrep 0.17.0 # hrep 0.16.1 From ef3e3e3839d921c47c62524b8cd50f614e3c12fa Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Mon, 24 Jun 2024 17:25:27 -0400 Subject: [PATCH 09/13] Increment version number to 0.19.0 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index fac61ba..2e60778 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hrep Title: Harmony Representations -Version: 0.18.0 +Version: 0.19.0 Authors@R: person("Peter", "Harrison", email = "pmc.harrison@gmail.com", role = c("aut", "cre")) Description: This package provides utilities for representing and manipulating chord sequences for perceptually informed harmony modelling. diff --git a/NEWS.md b/NEWS.md index fb08ccf..02a2aac 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# hrep 0.19.0 + # hrep 0.18.0 # hrep 0.17.0 From e158948c4be7c2b0d04e06d8a69aa05cced05fa8 Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Mon, 24 Jun 2024 17:25:44 -0400 Subject: [PATCH 10/13] bug dfix --- R/sparse-spectrum.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/sparse-spectrum.R b/R/sparse-spectrum.R index 35ef78d..d7e4830 100644 --- a/R/sparse-spectrum.R +++ b/R/sparse-spectrum.R @@ -78,7 +78,8 @@ set_labels.sparse_spectrum <- function(x, labels) { } #' @export -plot.sparse_spectrum <- function(x, cochlea=FALSE, ggplot = FALSE, xlim = NULL, trans=F, ...) { +plot.sparse_spectrum <- function(x, cochlea=FALSE, ggplot = FALSE, xlim = NULL, + trans_log=NULL, ...) { df <- as.data.frame(x) if (cochlea) { greenwood <- function(frequency) { @@ -94,8 +95,7 @@ plot.sparse_spectrum <- function(x, cochlea=FALSE, ggplot = FALSE, xlim = NULL, ggplot2::ggplot(df, ggplot2::aes_string(x = "x", xend = "x", y = 0, yend = "y")) + ggplot2::geom_segment() + - ggplot2::scale_x_continuous(x_label, limits = xlim) + - {if (trans) {ggplot2::scale_x_continuous(trans='log10')}} + + ggplot2::scale_x_continuous(x_label, limits = xlim, trans=trans_log) + ggplot2::scale_y_continuous(y_lab(x)) } else { n <- nrow(df) From cad791a0f65a6f34b30b357d04aa22aee23e7695 Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Mon, 24 Jun 2024 17:32:24 -0400 Subject: [PATCH 11/13] Increment version number to 0.20.0 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2e60778..6ea7ea5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hrep Title: Harmony Representations -Version: 0.19.0 +Version: 0.20.0 Authors@R: person("Peter", "Harrison", email = "pmc.harrison@gmail.com", role = c("aut", "cre")) Description: This package provides utilities for representing and manipulating chord sequences for perceptually informed harmony modelling. diff --git a/NEWS.md b/NEWS.md index 02a2aac..acc8493 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# hrep 0.20.0 + # hrep 0.19.0 # hrep 0.18.0 From e9ca5c934d98dfeb7c627ca29e6a1848657b3157 Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Mon, 24 Jun 2024 17:32:35 -0400 Subject: [PATCH 12/13] bug --- R/sparse-spectrum.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/sparse-spectrum.R b/R/sparse-spectrum.R index d7e4830..df03599 100644 --- a/R/sparse-spectrum.R +++ b/R/sparse-spectrum.R @@ -79,7 +79,7 @@ set_labels.sparse_spectrum <- function(x, labels) { #' @export plot.sparse_spectrum <- function(x, cochlea=FALSE, ggplot = FALSE, xlim = NULL, - trans_log=NULL, ...) { + trans='identity', ...) { df <- as.data.frame(x) if (cochlea) { greenwood <- function(frequency) { @@ -95,7 +95,7 @@ plot.sparse_spectrum <- function(x, cochlea=FALSE, ggplot = FALSE, xlim = NULL, ggplot2::ggplot(df, ggplot2::aes_string(x = "x", xend = "x", y = 0, yend = "y")) + ggplot2::geom_segment() + - ggplot2::scale_x_continuous(x_label, limits = xlim, trans=trans_log) + + ggplot2::scale_x_continuous(x_label, limits = xlim, transform=trans) + ggplot2::scale_y_continuous(y_lab(x)) } else { n <- nrow(df) From 57d24e7a939e8e687db35f4393f9dfb7a9a3e604 Mon Sep 17 00:00:00 2001 From: Brian Mulloy Date: Thu, 19 Jun 2025 14:39:55 -0400 Subject: [PATCH 13/13] changes name of octave ratio to pseudo octave --- R/expand-harmonics.R | 12 ++++++------ man/expand_harmonics.Rd | 10 +++++----- man/play_wav.Rd | 2 +- man/save_wav.Rd | 2 +- man/sparse_fr_spectrum.Rd | 2 +- man/sparse_pc_spectrum.Rd | 2 +- man/sparse_pi_spectrum.Rd | 2 +- man/wave.Rd | 2 +- tests/testthat/test-expand_harmonics.R | 6 +++--- tests/testthat/test-sparse_fr_spectrum.R | 6 +++--- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/R/expand-harmonics.R b/R/expand-harmonics.R index 4154919..216a753 100644 --- a/R/expand-harmonics.R +++ b/R/expand-harmonics.R @@ -22,7 +22,7 @@ #' @param label_harmonics #' If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers. #' -#' @param octave_ratio +#' @param pseudo_octave #' The octave ratio for stretching and compressing harmonics, defaults to 2.0. #' #' @rdname expand_harmonics @@ -35,7 +35,7 @@ expand_harmonics <- function(x, digits = 6, label_harmonics = FALSE, coherent = FALSE, - octave_ratio = 2.0) { + pseudo_octave = 2.0) { UseMethod("expand_harmonics") } @@ -47,7 +47,7 @@ expand_harmonics.sparse_fr_spectrum <- function(x, digits = 6, label_harmonics = FALSE, coherent = FALSE, - octave_ratio = 2.0) { + pseudo_octave = 2.0) { expand_harmonics(sparse_pi_spectrum(x), num_harmonics = num_harmonics, roll_off_dB = roll_off_dB, @@ -65,13 +65,13 @@ expand_harmonics.sparse_pi_spectrum <- function(x, digits = 6, label_harmonics = FALSE, coherent = FALSE, - octave_ratio = 2.0) { + pseudo_octave = 2.0) { purrr::map2(pitch(x), amp(x), function(pitch, amp) { n <- seq_len(num_harmonics) f0 <- midi_to_freq(pitch) df <- data.frame( - x = freq_to_midi(f0 * octave_ratio ^ log2(n)), + x = freq_to_midi(f0 * pseudo_octave ^ log2(n)), y = 1 * 10 ^ ( -roll_off_dB * log2(n) / 20) ) if (label_harmonics) df$labels <- seq_along(df$x) @@ -89,7 +89,7 @@ expand_harmonics.pi_chord <- function(x, digits = 6, label_harmonics = FALSE, coherent = FALSE, - octave_ratio = 2.0) { + pseudo_octave = 2.0) { sparse_pi_spectrum(x, num_harmonics = num_harmonics, roll_off_dB = roll_off_dB, diff --git a/man/expand_harmonics.Rd b/man/expand_harmonics.Rd index 0130112..623da60 100644 --- a/man/expand_harmonics.Rd +++ b/man/expand_harmonics.Rd @@ -14,7 +14,7 @@ expand_harmonics( digits = 6, label_harmonics = FALSE, coherent = FALSE, - octave_ratio = 2 + pseudo_octave = 2 ) \method{expand_harmonics}{sparse_fr_spectrum}( @@ -24,7 +24,7 @@ expand_harmonics( digits = 6, label_harmonics = FALSE, coherent = FALSE, - octave_ratio = 2 + pseudo_octave = 2 ) \method{expand_harmonics}{sparse_pi_spectrum}( @@ -34,7 +34,7 @@ expand_harmonics( digits = 6, label_harmonics = FALSE, coherent = FALSE, - octave_ratio = 2 + pseudo_octave = 2 ) \method{expand_harmonics}{pi_chord}( @@ -44,7 +44,7 @@ expand_harmonics( digits = 6, label_harmonics = FALSE, coherent = FALSE, - octave_ratio = 2 + pseudo_octave = 2 ) } \arguments{ @@ -71,7 +71,7 @@ assuming coherent summation, where the amplitudes simply add together Otherwise incoherent summation is used, where the amplitudes are squared, added, then square rooted.} -\item{octave_ratio}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} +\item{pseudo_octave}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} } \description{ Expands each tone in an object into its implied harmonics. diff --git a/man/play_wav.Rd b/man/play_wav.Rd index 86d35a7..0c4f4f1 100644 --- a/man/play_wav.Rd +++ b/man/play_wav.Rd @@ -37,7 +37,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} - \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} + \item{\code{pseudo_octave}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} \item{\code{coherent}}{Whether the amplitudes from different spectral components should be combined assuming coherent summation, where the amplitudes simply add together (default is \code{FALSE}). diff --git a/man/save_wav.Rd b/man/save_wav.Rd index 9e388c7..c9b6fa4 100644 --- a/man/save_wav.Rd +++ b/man/save_wav.Rd @@ -51,7 +51,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} - \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} + \item{\code{pseudo_octave}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} \item{\code{coherent}}{Whether the amplitudes from different spectral components should be combined assuming coherent summation, where the amplitudes simply add together (default is \code{FALSE}). diff --git a/man/sparse_fr_spectrum.Rd b/man/sparse_fr_spectrum.Rd index 41a22dd..e524f0e 100644 --- a/man/sparse_fr_spectrum.Rd +++ b/man/sparse_fr_spectrum.Rd @@ -43,7 +43,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} - \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} + \item{\code{pseudo_octave}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} \item{\code{coherent}}{Whether the amplitudes from different spectral components should be combined assuming coherent summation, where the amplitudes simply add together (default is \code{FALSE}). diff --git a/man/sparse_pc_spectrum.Rd b/man/sparse_pc_spectrum.Rd index a837a9e..de6040d 100644 --- a/man/sparse_pc_spectrum.Rd +++ b/man/sparse_pc_spectrum.Rd @@ -31,7 +31,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} - \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} + \item{\code{pseudo_octave}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} }} \item{coherent}{Whether the amplitudes from different spectral components should be combined diff --git a/man/sparse_pi_spectrum.Rd b/man/sparse_pi_spectrum.Rd index d291879..40dd482 100644 --- a/man/sparse_pi_spectrum.Rd +++ b/man/sparse_pi_spectrum.Rd @@ -34,7 +34,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} - \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} + \item{\code{pseudo_octave}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} }} \item{amplitude}{(Numeric vector) diff --git a/man/wave.Rd b/man/wave.Rd index 83f79f7..93dd88b 100644 --- a/man/wave.Rd +++ b/man/wave.Rd @@ -40,7 +40,7 @@ each tone should be expanded.} in the harmonics, with greater values corresponding to higher roll-off.} \item{\code{digits}}{Number of digits to which each partial's MIDI pitch should be rounded.} \item{\code{label_harmonics}}{If TRUE, then the harmonics in the resulting spectrum are labelled with their harmonic numbers.} - \item{\code{octave_ratio}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} + \item{\code{pseudo_octave}}{The octave ratio for stretching and compressing harmonics, defaults to 2.0.} \item{\code{coherent}}{Whether the amplitudes from different spectral components should be combined assuming coherent summation, where the amplitudes simply add together (default is \code{FALSE}). diff --git a/tests/testthat/test-expand_harmonics.R b/tests/testthat/test-expand_harmonics.R index 19624d3..1491aa3 100644 --- a/tests/testthat/test-expand_harmonics.R +++ b/tests/testthat/test-expand_harmonics.R @@ -89,7 +89,7 @@ test_that('octave ratio stretches and compresses',{ expect_equal(harmonic_default_result[8], 60+36) harmonic_explicit_result <- 60 %>% - sparse_pi_spectrum(num_harmonics=10, octave_ratio = 2.0) %>% + sparse_pi_spectrum(num_harmonics=10, pseudo_octave = 2.0) %>% pitch expect_equal(harmonic_explicit_result[1], 60) expect_equal(harmonic_explicit_result[2], 60+12) @@ -97,7 +97,7 @@ test_that('octave ratio stretches and compresses',{ expect_equal(harmonic_explicit_result[8], 60+36) compressed_result <- 60 %>% - sparse_pi_spectrum(num_harmonics=10, octave_ratio = 1.9) %>% + sparse_pi_spectrum(num_harmonics=10, pseudo_octave = 1.9) %>% pitch expect_equal(compressed_result[1], 60) expect_equal(compressed_result[2], @@ -108,7 +108,7 @@ test_that('octave ratio stretches and compresses',{ freq_to_midi(midi_to_freq(60)*1.9^log2(8))) stretcheded_result <- 60 %>% - sparse_pi_spectrum(num_harmonics=10, octave_ratio = 2.1) %>% + sparse_pi_spectrum(num_harmonics=10, pseudo_octave = 2.1) %>% pitch expect_equal(stretcheded_result[1], 60) expect_equal(stretcheded_result[2], diff --git a/tests/testthat/test-sparse_fr_spectrum.R b/tests/testthat/test-sparse_fr_spectrum.R index f7b091f..b7654d0 100644 --- a/tests/testthat/test-sparse_fr_spectrum.R +++ b/tests/testthat/test-sparse_fr_spectrum.R @@ -10,7 +10,7 @@ test_that('octave ratio stretches and compresses',{ expect_equal(harmonic_default_result[8], 60+36) harmonic_explicit_result <- 60 %>% - sparse_fr_spectrum(num_harmonics=10, octave_ratio = 2.0) %>% + sparse_fr_spectrum(num_harmonics=10, pseudo_octave = 2.0) %>% freq %>% freq_to_midi expect_equal(harmonic_explicit_result[1], 60) expect_equal(harmonic_explicit_result[2], 60+12) @@ -18,7 +18,7 @@ test_that('octave ratio stretches and compresses',{ expect_equal(harmonic_explicit_result[8], 60+36) compressed_result <- 60 %>% - sparse_fr_spectrum(num_harmonics=10, octave_ratio = 1.9) %>% + sparse_fr_spectrum(num_harmonics=10, pseudo_octave = 1.9) %>% freq %>% freq_to_midi expect_equal(compressed_result[1], 60) expect_equal(compressed_result[2], @@ -29,7 +29,7 @@ test_that('octave ratio stretches and compresses',{ freq_to_midi(midi_to_freq(60)*1.9^log2(8))) stretcheded_result <- 60 %>% - sparse_fr_spectrum(num_harmonics=10, octave_ratio = 2.1) %>% + sparse_fr_spectrum(num_harmonics=10, pseudo_octave = 2.1) %>% freq %>% freq_to_midi expect_equal(stretcheded_result[1], 60) expect_equal(stretcheded_result[2],