pitch_freq: Pitch conversions

View source: R/freq.R

pitch_freqR Documentation

Pitch conversions

Description

Convert between pitches, chords, semitones and frequencies.

Usage

pitch_freq(notes, a4 = 440)

pitch_semitones(notes)

chord_freq(notes, a4 = 440)

chord_semitones(notes)

freq_pitch(
  freq,
  octaves = c("tick", "integer"),
  accidentals = c("flat", "sharp"),
  collapse = FALSE,
  a4 = 440
)

freq_semitones(freq, a4 = 440)

semitone_pitch(
  semitones,
  octaves = c("tick", "integer"),
  accidentals = c("flat", "sharp"),
  collapse = FALSE
)

semitone_freq(semitones, a4 = 440)

Arguments

notes

character, noteworthy string, space-delimited or vector of individual entries. See details.

a4

the fixed frequency of the A above middle C, typically 440 Hz.

freq

numeric vector, frequencies in Hz.

octaves

NULL or character, "tick" or "integer" octave numbering in result.

accidentals

NULL or character, represent accidentals, "flat" or "sharp".

collapse

logical, collapse result into a single string. key and style.

semitones

integer values of pitches.

Details

Frequencies are in Hertz. Values are based on the 12-tone equal-tempered scale. When converting an arbitrary frequency to pitch, it is rounded to the nearest pitch. pitch_freq() and pitch_semitones() strictly accept single notes in noteworthy strings and return numeric vectors. chord_freq() and chord_semitones() accept any noteworthy string and always return a list. These are provided so that all functions are type-safe. See examples.

Value

integer, numeric or noteworthy vector

Examples

x <- "a e4 a4 e5 a5"
y <- pitch_freq(x)
y

freq_semitones(y)
freq_pitch(y)

identical(as_noteworthy(x), freq_pitch(y, "integer", collapse = TRUE))

s <- pitch_semitones(x)
s
semitone_pitch(s)

x <- "a, a,c#e"
chord_semitones(x)
chord_freq(x)

tabr documentation built on Sept. 12, 2024, 6:18 a.m.