# NOT RUN {
sounds = list(
white_noise = runif(8000, -1, 1),
white_noise2 = runif(8000, -1, 1) / 2, # ~6 dB quieter
pure_tone_1KHz = sin(2*pi*1000/16000*(1:8000)) # pure tone at 1 kHz
)
loud = rep(0, length(sounds)); names(loud) = names(sounds)
for (i in 1:length(sounds)) {
# playme(sounds[[i]], 16000)
l = getLoudness(
x = sounds[[i]], samplingRate = 16000, scale = 1,
windowLength = 20, step = NULL,
overlap = 50, SPL_measured = 40,
Pref = 2e-5, plot = FALSE)
loud[i] = mean(l$loudness)
}
loud
# white noise (sound 1) is twice as loud as pure tone at 1 KHz (sound 3),
# and note that the same white noise with lower amplitude has lower loudness
# (provided that "scale" is specified)
# compare: lapply(sounds, range)
# }
# NOT RUN {
s = soundgen()
l = getLoudness(s, SPL_measured = 70, samplingRate = 16000)
# The estimated loudness in sone depends on target SPL
l = getLoudness(s, SPL_measured = 40, samplingRate = 16000)
# ...but not (much) on windowLength and samplingRate
l = getLoudness(soundgen(), SPL_measured = 40, windowLength = 50,
samplingRate = 16000, plot = TRUE)
# input can be an audio file
getLoudness('~/Downloads/temp/032_ut_anger_30-m-roar-curse.wav')
# }
Run the code above in your browser using DataLab