sounds = list(
noise_1KHz = soundgen:::zeroOne(bandpass(rnorm(8000), 16000,
lwr = 900, upr = 1100)) * 2 -1, # narrow-band noise at 1 KHz
white_noise = runif(8000, -1, 1), # white noise
white_noise2 = runif(8000, -1/2, 1/2), # ~6 dB quieter
pure_tone_1KHz = sin(2*pi*1000/16000*(1:8000)), # pure tone at 1 kHz
pure_tone_100Hz = sin(2*pi*100/16000*(1:8000)) # pure tone at 100 Hz
)
# playme(sounds)
l = getLoudness(
x = sounds, samplingRate = 16000, scale = 1,
windowLength = 40, step = NULL, input = c('spec', 'audSpec')[1],
overlap = 50, SPL_measured = 60,
plot = FALSE)
l$summary
# loudness depends on amplitude if "scale" is provided (cf. sounds 2 and 3)
# narrowband noise / tone at 1 kHz, 60 dB: sharpness ~=1 acum, loudness ~=4 sone
# a steady glissando from 125 to 8000 Hz (constant on a musical scale)
pitch = exp(seq(log(125), log(8000), length.out = 16000))
s = sinpi(2 * cumsum(pitch) / 16000)
l1 = getLoudness(s, samplingRate = 16000, SPL_measured = 70)
# steady SPL, but variable loudness
# The estimated loudness and sharpness depend on target SPL
l2 = getLoudness(s, samplingRate = 16000, SPL_measured = 40, plot = FALSE)
l1$summary$loudness_mean
l2$summary$loudness_mean
# ...but not (much) on windowLength and samplingRate
l3 = getLoudness(s, samplingRate = 16000, SPL_measured = 40,
windowLength = 50, plot = FALSE)
l3$summary$loudness_mean
if (FALSE) {
# Using auditory spectrogram as input instead of STFT (slower)
l4 = getLoudness(s, samplingRate = 16000, SPL_measured = 40, input = 'audSpec')
l4$summary$loudness_mean
# Process all audio files in a folder
l5 = getLoudness('~/Downloads/temp', savePlots = TRUE)
l5$summary
}
Run the code above in your browser using DataLab