Learn R Programming

soundgen (version 2.7.4)

HzToOther: Convert between Hz and other frequency scales

Description

Converts betwen Hz and ERB, bark, mel, log, semitones relative to a reference frequency, or musical notes. Accepts vectors and missing values.

Usage

HzToOther(
  x,
  scale = c("ERB", "bark", "mel", "log", "semitones", "notes")[1],
  ...
)

otherToHz( x, scale = c("ERB", "bark", "mel", "log", "semitones", "notes")[1], ... )

Arguments

x

vector or matrix of frequencies

scale

target scale: "bark" = Zwicker's critical bandwidth scale calculated as in Wang et al. 1992 (see https://en.wikipedia.org/wiki/Bark_scale), "mel" = O'Shaughnessy's original formula (https://en.wikipedia.org/wiki/Mel_scale), "ERB" = Equivalent Rectangular Bandwidth rate (see HzToERB), "log" = log2, "semitones" = semitones relative to a reference value (see HzToSemitones), "notes" = musical notation (see HzToNotes), "linear" = no change

...

other arguments passed on to the scale-specific function

See Also

HzToSemitones HzToNotes HzToERB

Examples

Run this code
x = c(-20, 20, 100, 440, 1000, NA)
HzToOther(x, 'ERB')
HzToOther(x, 'ERB', 'quadratic')
HzToOther(x, 'bark')
HzToOther(x, 'mel')
HzToOther(x, 'log')
HzToOther(x, 'semitones', ref = 16)
HzToOther(x, 'notes', showCents = TRUE)

# ...and back to Hz
x = c(0:10, NA)

otherToHz(x, 'ERB')
otherToHz(x, 'ERB', method = 'quadratic')
otherToHz(HzToOther(c(100, 440, 2000), 'ERB'), 'ERB')

otherToHz(x, 'bark')
otherToHz(HzToOther(c(100, 440, 2000), 'bark'), 'bark')

otherToHz(x, 'mel')
otherToHz(HzToOther(c(100, 440, 2000), 'mel'), 'mel')

otherToHz(x, 'log')

otherToHz(x, 'semitones')
HzToOther(c(440, 210, 880), 'semitones', ref = 440)
otherToHz(HzToOther(c(440, 210, 880), 'semitones'), 'semitones')

otherToHz(c('A4', 'C#6', 'blabla', NA), 'notes')

Run the code above in your browser using DataLab