Title: | A Simple Sequencer for Data Sonification |
---|---|
Description: | A rudimentary sequencer to define, manipulate and mix sound samples. The underlying motivation is to sonify data, as demonstrated in the blog <https://globxblog.github.io/>, the presentation by Renard and Le Bescond (2022, <https://hal.science/hal-03710340v1>) or the poster by Renard et al. (2023, <https://hal.inrae.fr/hal-04388845v1>). |
Authors: | Benjamin Renard [aut, cre, cph] , INRAE [fnd], European Commission [fnd] (This project has received funding from the European Union’s Horizon 2020 research and innovation programme under the Marie Sklodowska-Curie grant agreement No 835496) |
Maintainer: | Benjamin Renard <[email protected]> |
License: | GPL-3 |
Version: | 1.0.1 |
Built: | 2025-01-14 05:35:54 UTC |
Source: | https://github.com/benrenard/sequencer |
Apply a delay to a sound sample. See https://en.wikipedia.org/wiki/Comb_filter
applyDelay(sample, type = "feedforward", delayTime = 0.6, echoes = c(0.8))
applyDelay(sample, type = "feedforward", delayTime = 0.6, echoes = c(0.8))
sample |
soundSample object, input sample |
type |
Character string, the delay type: feedforward or feedback |
delayTime |
Numeric >0, delay time in s. |
echoes |
Numeric vector >0. The size of the vector gives the number of echoes, the values the level of each echo (generally decreases to 0). |
The sound sample with a delay effect
# example code notes=c('E3','G3','A3','B3','D4','E4','G4') synth=getSynth(notes) raw=as.soundSample(play.instrument(synth,notes=notes[c(1,2,3,2,3,4,3,4,5,4,5,6,5,6,7)])) plot(raw) ## Not run: # All calls to function 'listen' are wrapped in \dontrun{} since # they rely on an external audio player to listen to the audio samples. # See ?tuneR::setWavPlayer for setting a default player. listen(raw) ## End(Not run) # Single echo by default cooked=applyDelay(raw) plot(cooked) ## Not run: listen(cooked) # Multiple echoes cooked=applyDelay(raw,echoes=1/(1:10)) plot(cooked) ## Not run: listen(cooked) # Feedback-type delay cooked=applyDelay(raw,echoes=1/(1:10),type='feedback') plot(cooked) ## Not run: listen(cooked)
# example code notes=c('E3','G3','A3','B3','D4','E4','G4') synth=getSynth(notes) raw=as.soundSample(play.instrument(synth,notes=notes[c(1,2,3,2,3,4,3,4,5,4,5,6,5,6,7)])) plot(raw) ## Not run: # All calls to function 'listen' are wrapped in \dontrun{} since # they rely on an external audio player to listen to the audio samples. # See ?tuneR::setWavPlayer for setting a default player. listen(raw) ## End(Not run) # Single echo by default cooked=applyDelay(raw) plot(cooked) ## Not run: listen(cooked) # Multiple echoes cooked=applyDelay(raw,echoes=1/(1:10)) plot(cooked) ## Not run: listen(cooked) # Feedback-type delay cooked=applyDelay(raw,echoes=1/(1:10),type='feedback') plot(cooked) ## Not run: listen(cooked)
Apply a distortion to a sound sample
applyDisto(sample, type = c("clip", "tanh"), level = 2, ..., rescale = FALSE)
applyDisto(sample, type = c("clip", "tanh"), level = 2, ..., rescale = FALSE)
sample |
soundSample object, input sample |
type |
Character string, the distortion type |
level |
Numeric >0, distortion level |
... |
other parameters passed to the distortion transfer function |
rescale |
Logical. If TRUE, the soundSample wave is rescaled to [-1,1] |
The distorted sound sample
# example code raw=oscillator(freq=110,duration=0.5) plot(raw) dist=applyDisto(raw,type='tanh',level=5) plot(dist)
# example code raw=oscillator(freq=110,duration=0.5) plot(raw) dist=applyDisto(raw,type='tanh',level=5) plot(dist)
Apply a volume envelope to a sound sample.
applyEnvelope(sample, env)
applyEnvelope(sample, env)
sample |
Sound sample object. |
env |
Envelope object. Envelope values should all be between 0 and 1. |
A sound sample object.
# Define the sound sample sam <- soundSample(sin(2*pi*seq(0,0.5,1/44100)*220)) # 0.5-second A (220 Hz) # Define the envelope env <- envelope(t=c(0,0.03,1),v=c(0,1,0)) # Apply it res <- applyEnvelope(sam,env) # Compare waveforms plot(sam,main='before') plot(res,main='after') ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(res) ## End(Not run)
# Define the sound sample sam <- soundSample(sin(2*pi*seq(0,0.5,1/44100)*220)) # 0.5-second A (220 Hz) # Define the envelope env <- envelope(t=c(0,0.03,1),v=c(0,1,0)) # Apply it res <- applyEnvelope(sam,env) # Compare waveforms plot(sam,main='before') plot(res,main='after') ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(res) ## End(Not run)
Convert a tuneR::Wave object into a soundSample.
as.soundSample(w, pan = 0)
as.soundSample(w, pan = 0)
w |
tuneR Wave object |
pan |
Numeric in [-1;1], panoramic. -1 (resp. 1) only select the left (resp. right) channel of w (if the latter is stereo). 0 averages both channels |
An object of class 'soundSample'.
w <- tuneR::Wave(left=sin(2*pi*seq(0,1,,44100)*440)) # 1-second A sam <- as.soundSample(w) plot(sam)
w <- tuneR::Wave(left=sin(2*pi*seq(0,1,,44100)*440)) # 1-second A sam <- as.soundSample(w) plot(sam)
Convert a soundSample into a tuneR::Wave object.
as.Wave(x)
as.Wave(x)
x |
sound sample object. |
a tuneR Wave object.
sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)) # 1-second A (440 Hz) w <- as.Wave(sam) tuneR::plot(w)
sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)) # 1-second A (440 Hz) w <- as.Wave(sam) tuneR::plot(w)
A ride cymbal (hit ion the bell) sound sample object
bell
bell
An object of class soundSample
of length 4.
Check that the size of a wave does not exceed the maximum allowed size.
checkMaxSize(n, nmax)
checkMaxSize(n, nmax)
n |
integer, size to be checked |
nmax |
integer, maximum allowed size |
nothing - just stops execution with an error message if n>nmax
Check that the arguments used in sequencing functions (e.g. time, volume, pan, etc.) are valid.
checkSeqArgs(argList)
checkSeqArgs(argList)
argList |
list, a named list containg the arguments |
nothing - just stops execution with an error message if something is invalid
Transfer function for 'clip' distortion
disto_clip(x, level)
disto_clip(x, level)
x |
Numeric vector in [-1,1], input signal |
level |
Numeric (>=0), distortion level |
a numeric vector containing the distorted output signal
Transfer function for 'tanh' distortion
disto_tanh(x, level)
disto_tanh(x, level)
x |
Numeric vector in [-1,1], input signal |
level |
Numeric (>=0), distortion level |
a numeric vector containing the distorted output signal
Creates a new instance of an 'envelope' object (https://en.wikipedia.org/wiki/Envelope_(music)). In this package an envelop is viewed as a curve v(t), where t is the time and v the value of the envelope. Time t is normalized between 0 and 1 so that 1 corresponds to the end of the sound sample the envelope is applied to (and 0 to its beginning). The curve is defined by a discrete set of points (t,v) (linear interpolation in between).
envelope(t, v)
envelope(t, v)
t |
Numeric vector, normalized time. Vector of increasing values starting at 0 and ending at 1. |
v |
Numeric vector, same size as t, envelop values v(t). |
An object of class 'envelope'.
# A triangular envelop env <- envelope(t=c(0,0.3,1),v=c(0,1,0)) # An ADSR envelope (https://en.wikipedia.org/wiki/Envelope_(music)#ADSR) env <- envelope(t=c(0,0.1,0.3,0.8,1),v=c(0,1,0.4,0.4,0)) # An envelope that could be used for a 1-octave frequency modulation (from 440 to 220 Hz) env <- envelope(t=c(0,1),v=c(440,220)) # An envelope that could be used for phase modulation # (https://en.wikipedia.org/wiki/Phase_modulation) env <- envelope(t=seq(0,1,0.01),v=(-pi/2)*sin(2*pi*4*seq(0,1,0.01)))
# A triangular envelop env <- envelope(t=c(0,0.3,1),v=c(0,1,0)) # An ADSR envelope (https://en.wikipedia.org/wiki/Envelope_(music)#ADSR) env <- envelope(t=c(0,0.1,0.3,0.8,1),v=c(0,1,0.4,0.4,0)) # An envelope that could be used for a 1-octave frequency modulation (from 440 to 220 Hz) env <- envelope(t=c(0,1),v=c(440,220)) # An envelope that could be used for phase modulation # (https://en.wikipedia.org/wiki/Phase_modulation) env <- envelope(t=seq(0,1,0.01),v=(-pi/2)*sin(2*pi*4*seq(0,1,0.01)))
Get frequencies from note names (in scientific pitch notation).
getFrequencies(notes, minOctave = 0, maxOctave = 8)
getFrequencies(notes, minOctave = 0, maxOctave = 8)
notes |
Character vector, note names. |
minOctave |
integer, smallest (lowest-pitched) octave |
maxOctave |
integer, largest (highest-pitched) octave |
a numeric vector of frequencies (in Hz)
# example code getFrequencies(c('A3','A4','A5','C#6','Db6','A9','X0')) getFrequencies(c('A3','A4','A5','C#6','Db6','A9','X0'),maxOctave=9)
# example code getFrequencies(c('A3','A4','A5','C#6','Db6','A9','X0')) getFrequencies(c('A3','A4','A5','C#6','Db6','A9','X0'),maxOctave=9)
Creates a sound sample corresponding to the kth harmonics of a given frequency
getHarmonics( freq, k, peak = 0.03, decay = 0.8, duration = 1, sustain = 0.25, type = "sine" )
getHarmonics( freq, k, peak = 0.03, decay = 0.8, duration = 1, sustain = 0.25, type = "sine" )
freq |
Numeric, base frequency in Hz |
k |
Integer >=1, kth harmonics |
peak |
Numeric, peak time in seconds |
decay |
Numeric, end-of-decay time in seconds |
duration |
Numeric, total duration in seconds |
sustain |
Numeric, sustain volume |
type |
String, oscillator type, one of 'sine', 'saw', 'square' or 'triangle'. If an unknowm string is provided, a sine oscillator will be used. |
An object of class 'soundSample'.
sam1 <- getHarmonics(440,1) plot(sam1) sam2 <- getHarmonics(440,3) plot(sam2) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam2) ## End(Not run)
sam1 <- getHarmonics(440,1) plot(sam1) sam2 <- getHarmonics(440,3) plot(sam2) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam2) ## End(Not run)
Get notes (in scientific pitch notation) from frequencies. The note with the closest frequency is returned.
getNotes(frequencies, minOctave = 0, maxOctave = 8, option = "b")
getNotes(frequencies, minOctave = 0, maxOctave = 8, option = "b")
frequencies |
numeric vector, frequencies in Hz |
minOctave |
integer, smallest (lowest-pitched) octave |
maxOctave |
integer, largest (highest-pitched) octave |
option |
character, use 'b' or '#' in note names? |
a character vector of notes
# example code getNotes(seq(440,10000,100)) getNotes(seq(440,10000,100),maxOctave=10,option='#')
# example code getNotes(seq(440,10000,100)) getNotes(seq(440,10000,100),maxOctave=10,option='#')
Creates an additive, Hammond-inspired Synthesizer. Higher harmonics decay faster and have smaller sustain.
getSynth( notes, nHarmonics = 5, peak = 0.03, decay = 0.8, duration = 1, sustain = 0.25, decayPar = 1, sustainPar = 4, type = "sine" )
getSynth( notes, nHarmonics = 5, peak = 0.03, decay = 0.8, duration = 1, sustain = 0.25, decayPar = 1, sustainPar = 4, type = "sine" )
notes |
Character vector, note names |
nHarmonics |
Integer >=1, number of harmonics |
peak |
Numeric, peak time in seconds |
decay |
Numeric, end-of-decay time in seconds |
duration |
Numeric, total duration in seconds |
sustain |
Numeric, sustain volume |
decayPar |
Numeric, the higher the value the smaller the decay time for higher harmonics |
sustainPar |
Numeric, the higher the value the smaller the sustain volume for higher harmonics |
type |
String, oscillator type, one of 'sine', 'saw', 'square' or 'triangle'. If an unknown string is provided, a sine oscillator will be used. |
An object of class 'instrument'.
synth <- getSynth(c('E2','B2','E3','G3','A3')) w=play.instrument(synth,time=(0:(length(synth)-1))*0.5,fadeout=rep(Inf,length(synth))) tuneR::plot(w) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to play the audio sample. # See ?tuneR::setWavPlayer for setting a default player. tuneR::play(w) ## End(Not run)
synth <- getSynth(c('E2','B2','E3','G3','A3')) w=play.instrument(synth,time=(0:(length(synth)-1))*0.5,fadeout=rep(Inf,length(synth))) tuneR::plot(w) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to play the audio sample. # See ?tuneR::setWavPlayer for setting a default player. tuneR::play(w) ## End(Not run)
Creates one note with frequency freq from an additive, Hammond-inspired synth. Higher harmonics decay faster and have smaller sustain.
getSynthNote( freq, nHarmonics = 5, peak = 0.03, decay = 0.8, duration = 1, sustain = 0.25, decayPar = 1, sustainPar = 4, type = "sine" )
getSynthNote( freq, nHarmonics = 5, peak = 0.03, decay = 0.8, duration = 1, sustain = 0.25, decayPar = 1, sustainPar = 4, type = "sine" )
freq |
Numeric, base frequency in Hz |
nHarmonics |
Integer >=1, number of harmonics |
peak |
Numeric, peak time in seconds |
decay |
Numeric, end-of-decay time in seconds |
duration |
Numeric, total duration in seconds |
sustain |
Numeric, sustain volume |
decayPar |
Numeric, the higher the value the smaller the decay time for higher harmonics |
sustainPar |
Numeric, the higher the value the smaller the sustain volume for higher harmonics |
type |
String, oscillator type, one of 'sine', 'saw', 'square' or 'triangle'. If an unknown string is provided, a sine oscillator will be used. |
An object of class 'soundSample'.
sam <- getSynthNote(440,nHarmonics=7) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
sam <- getSynthNote(440,nHarmonics=7) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
Get the times steps associated with a sound sample.
getTime(x)
getTime(x)
x |
sound sample object. |
a numeric vector containing the sampling times in second.
# Define sound sample sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)+0.1*rnorm(44100)) # 1-second noisy A # Compute sampling times timeSteps=getTime(sam)
# Define sound sample sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)+0.1*rnorm(44100)) # 1-second noisy A # Compute sampling times timeSteps=getTime(sam)
Times series of annual temperature anomalies at the global scale, 1850-2021. This time series is the one used to create the Warming Stripes (https://www.climate-lab-book.ac.uk/2018/warming-stripes/).
globalT
globalT
An object of class data.frame
with 172 rows and 2 columns.
https://www.metoffice.gov.uk/hadobs/hadcrut4/data/current/download.html
A hi-hat sound sample object
hiHat
hiHat
An object of class soundSample
of length 4.
An open hi-hat sound sample object
hiHat_o
hiHat_o
An object of class soundSample
of length 4.
A hi-hat sound sample object
hiHat2
hiHat2
An object of class soundSample
of length 4.
http://www.archive.org/details/OpenPathMusic44V1
Creates a new instance of an 'instrument' object. An instrument is a named list of sound samples (all with the same sampling rate).
instrument(samples, notes = as.character(1:length(samples)))
instrument(samples, notes = as.character(1:length(samples)))
samples |
list of sound samples |
notes |
string vector, name given to each sample |
An object of class 'Instrument'.
drumset <- instrument(samples=list(kick,snare,hiHat),notes=c('boom','tat','cheet'))
drumset <- instrument(samples=list(kick,snare,hiHat),notes=c('boom','tat','cheet'))
A kick sound sample object
kick
kick
An object of class soundSample
of length 4.
A kick sound sample object
kick2
kick2
An object of class soundSample
of length 4.
http://www.archive.org/details/OpenPathMusic44V1
Listen to a sound sample. Based on tuneR function 'play'
listen(x)
listen(x)
x |
sound sample object. |
nothing - listening function.
# Define sound sample sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)+0.1*rnorm(44100)) # 1-second noisy A ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
# Define sound sample sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)+0.1*rnorm(44100)) # 1-second noisy A ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
An instrument containing a few basic sounds from a TR-909-inspired drumkit
mini909
mini909
An object of class instrument
of length 6.
https://freesound.org/people/altemark/packs/1643/
Take several wave objects (package tuneR) and mix them according to volume and pan.
mix(waves, volume = rep(1, length(waves)), pan = rep(0, length(waves)))
mix(waves, volume = rep(1, length(waves)), pan = rep(0, length(waves)))
waves |
List of wave S4 objects (tuneR) |
volume |
Numeric vector, volume between 0 and 1. |
pan |
Numeric vector, pan between -1 (left) and 1 (right) (0 = centered). |
the result of th mix, an S4 Wave object (from package tuneR).
# A 2-second drum groove (4/4 measure) # hi-hat on 16th notes hh <- sequence(hiHat,time=2*(0:15)/16,volume=rep(c(1,rep(0.5,3)),4)) # bass kick on 1 and 3 k <- sequence(kick,time=2*c(0,8)/16) # snare on 2 and 4 s <- sequence(snare,time=2*c(4,12)/16) # Mix the 3 tracks m1 <- mix(list(hh,k,s)) ## Not run: # All calls to function 'tuneR::play' ar wrapped in \dontrun{} since they rely # on an external audio player to play the audio sample. # See ?tuneR::setWavPlayer for setting a default player. tuneR::play(m1) ## End(Not run) # Try with less hihat, more kick m2 <- mix(list(hh,k,s),volume=c(0.3,1,0.8)) ## Not run: tuneR::play(m2)
# A 2-second drum groove (4/4 measure) # hi-hat on 16th notes hh <- sequence(hiHat,time=2*(0:15)/16,volume=rep(c(1,rep(0.5,3)),4)) # bass kick on 1 and 3 k <- sequence(kick,time=2*c(0,8)/16) # snare on 2 and 4 s <- sequence(snare,time=2*c(4,12)/16) # Mix the 3 tracks m1 <- mix(list(hh,k,s)) ## Not run: # All calls to function 'tuneR::play' ar wrapped in \dontrun{} since they rely # on an external audio player to play the audio sample. # See ?tuneR::setWavPlayer for setting a default player. tuneR::play(m1) ## End(Not run) # Try with less hihat, more kick m2 <- mix(list(hh,k,s),volume=c(0.3,1,0.8)) ## Not run: tuneR::play(m2)
Builds a dataframe containing notes (in scientific pitch notation) and corresponding frequencies.
noteFrequencyTable(minOctave = 0, maxOctave = 8)
noteFrequencyTable(minOctave = 0, maxOctave = 8)
minOctave |
integer, smallest (lowest-pitched) octave |
maxOctave |
integer, largest (highest-pitched) octave |
a data frame with 4 columns: note name 1 (written with 'b'), note name 2 (written with '#'),index (in semitones with respect to A4) and frequency (in Hz)
# example code noteFrequencyTable()
# example code noteFrequencyTable()
Creates a soundSample using a oscillator.
oscillator(type = "sine", freq = 440, duration = 1, phase = 0, rate = 44100)
oscillator(type = "sine", freq = 440, duration = 1, phase = 0, rate = 44100)
type |
String, oscillator type, one of 'sine', 'saw', 'square' or 'triangle'. If an unknown string is provided, a sine oscillator will be used. |
freq |
Numeric, note frequency in Hz |
duration |
Numeric, note duration in second |
phase |
Numeric, phase in radians (typically between 0 and 2*pi) |
rate |
Numeric, sampling rate in Hz |
An object of class 'soundSample'.
sam <- oscillator(type='saw',freq=220,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
sam <- oscillator(type='saw',freq=220,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
Creates a soundSample by repeating a user-provided pattern.
oscillator_pattern(pattern, freq = 440, duration = 1, rate = 44100)
oscillator_pattern(pattern, freq = 440, duration = 1, rate = 44100)
pattern |
Numeric vector, pattern. |
freq |
Numeric, note frequency in Hz |
duration |
Numeric, note duration in second |
rate |
Numeric, sampling rate in Hz |
An object of class 'soundSample'.
sam <- oscillator_pattern(pattern=airquality$Ozone,freq=110,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
sam <- oscillator_pattern(pattern=airquality$Ozone,freq=110,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
Creates a soundSample using a saw oscillator.
oscillator_saw(freq = 440, duration = 1, phase = 0, rate = 44100)
oscillator_saw(freq = 440, duration = 1, phase = 0, rate = 44100)
freq |
Numeric, note frequency in Hz |
duration |
Numeric, note duration in second |
phase |
Numeric, phase in radians (typically between 0 and 2*pi) |
rate |
Numeric, sampling rate in Hz |
An object of class 'soundSample'.
sam <- oscillator_saw(freq=220,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
sam <- oscillator_saw(freq=220,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
Creates a soundSample using a sine oscillator.
oscillator_sine(freq = 440, duration = 1, phase = 0, rate = 44100)
oscillator_sine(freq = 440, duration = 1, phase = 0, rate = 44100)
freq |
Numeric, note frequency in Hz |
duration |
Numeric, note duration in second |
phase |
Numeric, phase in radians (typically between 0 and 2*pi) |
rate |
Numeric, sampling rate in Hz |
An object of class 'soundSample'.
sam <- oscillator_sine(freq=220,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
sam <- oscillator_sine(freq=220,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
Creates a soundSample using a square oscillator.
oscillator_square(freq = 440, duration = 1, phase = 0, rate = 44100)
oscillator_square(freq = 440, duration = 1, phase = 0, rate = 44100)
freq |
Numeric, note frequency in Hz |
duration |
Numeric, note duration in second |
phase |
Numeric, phase in radians (typically between 0 and 2*pi) |
rate |
Numeric, sampling rate in Hz |
An object of class 'soundSample'.
sam <- oscillator_square(freq=220,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
sam <- oscillator_square(freq=220,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
Creates a soundSample using a triangle oscillator.
oscillator_triangle(freq = 440, duration = 1, phase = 0, rate = 44100)
oscillator_triangle(freq = 440, duration = 1, phase = 0, rate = 44100)
freq |
Numeric, note frequency in Hz |
duration |
Numeric, note duration in second |
phase |
Numeric, phase in radians (typically between 0 and 2*pi) |
rate |
Numeric, sampling rate in Hz |
An object of class 'soundSample'.
sam <- oscillator_triangle(freq=220,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
sam <- oscillator_triangle(freq=220,duration=0.1) plot(sam) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to listen to the audio sample. # See ?tuneR::setWavPlayer for setting a default player. listen(sam) ## End(Not run)
Maps a series of values into pitches of notes
pitchMapping(x, notes)
pitchMapping(x, notes)
x |
Numeric vector |
notes |
character vector, notes onto which values are map (i.e. the musical scakle). Notes should be written in Scientific pitch notation, e.g. c('C4','E4','G4') (see https://en.wikipedia.org/wiki/Scientific_pitch_notation) |
a character vector representing the original values transformed into pitches
pitchMapping(x=1:10,notes=c('C4','E4','G4')) pitchMapping(rnorm(20),notes=c('E3','Gb3','G3','A3','B3','C4','D4'))
pitchMapping(x=1:10,notes=c('C4','E4','G4')) pitchMapping(rnorm(20),notes=c('E3','Gb3','G3','A3','B3','C4','D4'))
Take a sound sample and repeat it following given timeline, volume and pan.
play.instrument( inst, notes = 1:length(inst), time = seq(0, (length(notes) - 1) * 0.25, length.out = length(notes)), volume = rep(1, length(notes)), pan = rep(0, length(notes)), fadein = rep(0.01, length(notes)), fadeout = fadein, env = NULL, nmax = 10 * 10^6 )
play.instrument( inst, notes = 1:length(inst), time = seq(0, (length(notes) - 1) * 0.25, length.out = length(notes)), volume = rep(1, length(notes)), pan = rep(0, length(notes)), fadein = rep(0.01, length(notes)), fadeout = fadein, env = NULL, nmax = 10 * 10^6 )
inst |
Instrument object. |
notes |
String or integer vector, the notes of the instrument to be played, either by name or by index. |
time |
Numeric vector, time (in seconds) at which each note should be played. Should be non-negative, non-decreasing and have same size as notes. |
volume |
Numeric vector, volume between 0 and 1, |
pan |
Numeric vector, pan between -1 (left) and 1 (right) (0 = centered). Same size as notes. |
fadein |
Numeric vector, fade-in duration (in seconds), same size as notes. |
fadeout |
Numeric vector, fade-out duration (in seconds), same size as notes. Use Inf for 'let ring'. |
env |
list of envelope objects, envelope applied to each note. |
nmax |
Integer, max number of values for each channel of the resulting Wave. Default value (10*10^6) roughly corresponds to a 150 Mb stereo wave, ~3 min 45s. |
an S4 Wave object (from package tuneR).
# Create an instrument samples=list(oscillator(freq=110),oscillator(freq=220),oscillator(freq=261.63), oscillator(freq=293.66),oscillator(freq=392)) notes=c('A2','A3','C4','D4','G4') onTheMoon <- instrument(samples,notes) # Play it w=play.instrument(onTheMoon) # View the result tuneR::plot(w) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to play the audio sample. # See ?tuneR::setWavPlayer for setting a default player. tuneR::play(w) ## End(Not run) # Use options w=play.instrument(onTheMoon,time=c(0,0.2,0.4,0.6,0.8,0.9), notes=c('A2','G4','D4','C4','A3','A2'), volume=seq(0.2,1,length.out=6),pan=c(0,-1,1,-1,1,0), fadeout=c(Inf,0.01,0.01,0.01,Inf,Inf)) # View the result tuneR::plot(w) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to play the audio sample. # See ?tuneR::setWavPlayer for setting a default player. tuneR::play(w) ## End(Not run)
# Create an instrument samples=list(oscillator(freq=110),oscillator(freq=220),oscillator(freq=261.63), oscillator(freq=293.66),oscillator(freq=392)) notes=c('A2','A3','C4','D4','G4') onTheMoon <- instrument(samples,notes) # Play it w=play.instrument(onTheMoon) # View the result tuneR::plot(w) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to play the audio sample. # See ?tuneR::setWavPlayer for setting a default player. tuneR::play(w) ## End(Not run) # Use options w=play.instrument(onTheMoon,time=c(0,0.2,0.4,0.6,0.8,0.9), notes=c('A2','G4','D4','C4','A3','A2'), volume=seq(0.2,1,length.out=6),pan=c(0,-1,1,-1,1,0), fadeout=c(Inf,0.01,0.01,0.01,Inf,Inf)) # View the result tuneR::plot(w) ## Not run: # This line of code is wrapped in \dontrun{} since it relies # on an external audio player to play the audio sample. # See ?tuneR::setWavPlayer for setting a default player. tuneR::play(w) ## End(Not run)
Plot an envelope.
## S3 method for class 'envelope' plot(x, ...)
## S3 method for class 'envelope' plot(x, ...)
x |
envelope object. |
... |
further arguments passed to the base plot function. |
nothing - plotting function.
# Define envelope env <- envelope(t=c(0,0.1,0.3,0.8,1),v=c(0,1,0.4,0.4,0)) # plot it plot(env)
# Define envelope env <- envelope(t=c(0,0.1,0.3,0.8,1),v=c(0,1,0.4,0.4,0)) # plot it plot(env)
Plot a sound sample. Uses plotly to add zooming capability.
## S3 method for class 'soundSample' plot(x, ...)
## S3 method for class 'soundSample' plot(x, ...)
x |
sound sample object. |
... |
further arguments passed to tuneR plotting function. |
nothing - plotting function.
# Define sound sample sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)+0.1*rnorm(44100)) # 1-second noisy A # plot it plot(sam)
# Define sound sample sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)+0.1*rnorm(44100)) # 1-second noisy A # plot it plot(sam)
Read a sound sample from a .mp3 or .wav file.
read.soundSample(file, ...)
read.soundSample(file, ...)
file |
string, file with extension .wav or.mp3 |
... |
additional arguments passed to function tuneR::readWave |
An object of class 'soundSample'.
sam=try(read.soundSample(file='vignettes/07027201.mp3'))
sam=try(read.soundSample(file='vignettes/07027201.mp3'))
Rescale a series between two bounds
rescale(x, low = 0, high = 1)
rescale(x, low = 0, high = 1)
x |
Numeric vector |
low |
Numeric, lower bound |
high |
Numeric, higher bound |
a rescaled numeric vector
# example code rescale(1:10) rescale(rnorm(10), 100, 101)
# example code rescale(1:10) rescale(rnorm(10), 100, 101)
A ride cymbal sound sample object
ride
ride
An object of class soundSample
of length 4.
Take a sound sample and repeat it following given timeline, volume and pan.
sequence( sample, time, letRing = TRUE, volume = rep(1, NROW(time)), pan = rep(0, NROW(time)), nmax = 10 * 10^6 )
sequence( sample, time, letRing = TRUE, volume = rep(1, NROW(time)), pan = rep(0, NROW(time)), nmax = 10 * 10^6 )
sample |
Sound sample object. |
time |
Numeric vector, time (in seconds) at which sample should be repeated |
letRing |
Logical. If TRUE overlapping samples are added; if FALSE, a new sample stops the previous one (=> beware of the click!)) |
volume |
Numeric vector, volume between 0 and 1. |
pan |
Numeric vector, pan between -1 (left) and 1 (right) (0 = centered). |
nmax |
Integer, max number of values for each channel of the resulting Wave. Default value (10*10^6) roughly corresponds to a 150 Mb stereo wave, ~3 min 45s. |
an S4 Wave object (from package tuneR).
# EXAMPLE 1 # Define a sound sample sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)+0.1*rnorm(44100)) # 1-second noisy A # Sequence it s <- sequence(sam,time=c(0,0.5,0.75),letRing=FALSE,volume=c(0.4,1,1),pan=c(-1,0,1)) # View the result tuneR::plot(s) ## Not run: # All calls to function 'tuneR::play' are wrapped in \dontrun{} since # they rely on an external audio player to play the audio sample. # See ?tuneR::setWavPlayer for setting a default player. tuneR::play(s) ## End(Not run) #' EXAMPLE 2 - make it funkyer # 2-second sequence based on hi-hat sample s <- sequence(hiHat,time=seq(0,2,,16),volume=rep(c(1,rep(0.5,3)),4)) # View the result tuneR::plot(s) ## Not run: tuneR::play(s)
# EXAMPLE 1 # Define a sound sample sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)+0.1*rnorm(44100)) # 1-second noisy A # Sequence it s <- sequence(sam,time=c(0,0.5,0.75),letRing=FALSE,volume=c(0.4,1,1),pan=c(-1,0,1)) # View the result tuneR::plot(s) ## Not run: # All calls to function 'tuneR::play' are wrapped in \dontrun{} since # they rely on an external audio player to play the audio sample. # See ?tuneR::setWavPlayer for setting a default player. tuneR::play(s) ## End(Not run) #' EXAMPLE 2 - make it funkyer # 2-second sequence based on hi-hat sample s <- sequence(hiHat,time=seq(0,2,,16),volume=rep(c(1,rep(0.5,3)),4)) # View the result tuneR::plot(s) ## Not run: tuneR::play(s)
Shift the pitch of a sound sample by n semitones. Note that the duration of the resulting sample is not the same as that of the original.
shiftPitch(sample, n)
shiftPitch(sample, n)
sample |
Sound sample object. |
n |
numeric, number of semitones. |
A sound sample object.
# Define a A sound sample and get a D by adding 5 semitones A <- soundSample(sin(2*pi*seq(0,0.5,1/44100)*220)) # 0.5-second A (220 Hz) D <- shiftPitch(A,5)
# Define a A sound sample and get a D by adding 5 semitones A <- soundSample(sin(2*pi*seq(0,0.5,1/44100)*220)) # 0.5-second A (220 Hz) D <- shiftPitch(A,5)
A snare sound sample object
snare
snare
An object of class soundSample
of length 4.
A snare sound sample object
snare2
snare2
An object of class soundSample
of length 4.
http://www.archive.org/details/OpenPathMusic44V1
Sonification of climate stripes data, or more generally, of a time series of values. A smoothed version of the time series is computed by moving average, then sonification proceeds as follows:
Backtrack is a standard house-like tune, including a four-on-the-floor kick+hi-hat pattern on the drum, a bass following the drum kick, and 3 chords played by a synthesizer
The smoothed time series controls the master volume and the amount of 'distortion' in the synthesizer's sound
Large anomalies below / above the smoothed series trigger percussion sounds (by default a snare and a hand clap) that are panned full left (negative anomalies) and full right (positive anomalies)
sonifyStripes( values = sequenceR::globalT$Anomaly, bpm = 135, minVol = 0.1, nma = 10, pClap = 0.15, synthVar = 0.5, kick = sequenceR::mini909$bass, hihat = sequenceR::mini909$hihat, openHihat = sequenceR::mini909$hihat_o, posPercussion = sequenceR::mini909$snare, negPercussion = sequenceR::mini909$clap, bassNote = "E1", chord1 = c("E2", "E3", "G3", "D4", "Gb4"), chord2 = c("E2", "D3", "Gb3", "A3", "E4"), chord3 = c("E2", "B2", "Gb3", "G3", "D4"), videoFile = NULL, videoResFactor = 1 )
sonifyStripes( values = sequenceR::globalT$Anomaly, bpm = 135, minVol = 0.1, nma = 10, pClap = 0.15, synthVar = 0.5, kick = sequenceR::mini909$bass, hihat = sequenceR::mini909$hihat, openHihat = sequenceR::mini909$hihat_o, posPercussion = sequenceR::mini909$snare, negPercussion = sequenceR::mini909$clap, bassNote = "E1", chord1 = c("E2", "E3", "G3", "D4", "Gb4"), chord2 = c("E2", "D3", "Gb3", "A3", "E4"), chord3 = c("E2", "B2", "Gb3", "G3", "D4"), videoFile = NULL, videoResFactor = 1 )
values |
Numeric vector, values to sonify. Default is global temperature anomalies over the period 1850-2021 |
bpm |
Numeric > 0, tempo in beat per minute |
minVol |
Numeric >= 0, minimum volume reached when smoothed series is minimum |
nma |
Numeric >=0 , number of moving average steps on each side of the current value (i.e. moving average window is 2*nma+1 when possible, nma+1 on the series' edges) |
pClap |
Numeric in (0,0.5). "Large" anomalies triggering claps/snare are defined as anomalies below (resp. above) the pClap (resp. (1-pClap))-quantile of anomalies. |
synthVar |
Numeric >= 0 , controls the variability of the synthesizer sound. When zero, the synthesizer sound does not change. Large values induce more variability in the synthesizer sound. |
kick |
soundSample, sound sample used to play the kick drum. |
hihat |
soundSample, sound sample used to play the closed hi-hat. |
openHihat |
soundSample, sound sample used to play the open hi-hat. |
posPercussion |
soundSample, sound sample used to play the positive-anomaly percussion. |
negPercussion |
soundSample, sound sample used to play the negative-anomaly percussion. |
bassNote |
string, bass note (in scientific pitch notation). |
chord1 |
string vector, first chord played by synthesizer. |
chord2 |
string vector, second chord played by synthesizer. |
chord3 |
string vector, third chord played by synthesizer. |
videoFile |
file path, full path to video file. When NULL, video is not created. |
videoResFactor |
Numeric > 0 , video resolution, 2 recommended for good-quality video. |
A list with the following components:
mix, tuneR::Wave object, the final mix of the sonification.
dat, data frame with 4 columns: time step, raw value, smoothed value, anomaly
quantiles, numeric vector of size 2, the quantiles defining large negative/positive anomalies
waves, list of tuneR::Wave object, individual waves for each instrument in case you wish to mix them in your own way.
w <- sonifyStripes()
w <- sonifyStripes()
Creates a new instance of a 'soundSample' object. A sound sample can be viewed as a minimalistic version of an "audio wave" object (see package tuneR for instance). It is necessarily mono and the wave time series is normalized between -1 and 1.
soundSample(wave, rate = 44100)
soundSample(wave, rate = 44100)
wave |
Numeric vector, wave time series |
rate |
Numeric, sampling rate (default 44100 Hz) |
An object of class 'soundSample'.
sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)) # 1-second A (440 Hz) sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)+0.1*rnorm(44100)) # 1-second noisy A
sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)) # 1-second A (440 Hz) sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)+0.1*rnorm(44100)) # 1-second noisy A
Compute the time vector starting from 0 associated with a duration and a sampling rate
timeVector(duration = 1, rate = 44100)
timeVector(duration = 1, rate = 44100)
duration |
Numeric |
rate |
Numeric |
a numeric vector
Times series of monthly temperatures and precipitations recorded at Wagga-Wagga, New South Wales, Australia, 1940-2018
WaggaWagga
WaggaWagga
An object of class data.frame
with 79 rows and 3 columns.
http://www.bom.gov.au/cgi-bin/climate/hqsites/site_data.cgi?period=annual&variable=meanT&station=072150
http://www.bom.gov.au/cgi-bin/climate/hqsites/site_data.cgi?period=annual&variable=rain&station=072150
Write each sound sample of the instrument as a separate .wav or .mp3 file.
write.instrument(inst, dir = tempdir(), fmt = "wav")
write.instrument(inst, dir = tempdir(), fmt = "wav")
inst |
Instrument object. |
dir |
String, directory where files should be written. |
fmt |
String, 'wav' or 'mp3'. |
nothing - writing function.
# Create an instrument drumset <- instrument(samples=list(kick,snare,hiHat),notes=c('boom','tat','cheet')) # Write to files (one per element) write.instrument(drumset)
# Create an instrument drumset <- instrument(samples=list(kick,snare,hiHat),notes=c('boom','tat','cheet')) # Write to files (one per element) write.instrument(drumset)
Write a sound sample in .wav or .mp3 format.
write.soundSample(x, file)
write.soundSample(x, file)
x |
sound sample object. |
file |
string, destination file. Default file format is .wav. If file extension is .mp3, conversion to mp3 is attempted using ffmpeg, which hence needs to be available (see https://ffmpeg.org/). |
nothing - writing function.
sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)) # 1-second A (440 Hz) write.soundSample(sam,file=tempfile())
sam <- soundSample(sin(2*pi*seq(0,1,,44100)*440)) # 1-second A (440 Hz) write.soundSample(sam,file=tempfile())