music.core package¶
Submodules¶
music.core.classes module¶
music.core.functions module¶
This file holds minimal implementations to avoid repetitions in the musical pieces of the MASS framework:
Sounds are represented as arrays of PCM samples. Stereo files are represented by arrays of shape (2, nsamples).
- See the music Python Package:
- https://github.com/ttm/music
for a usage of these implementations within a package and derived routines.
See the file HRTF.py, in this same directory, for the functions that use impulse responses of Head Related Transfer Functions (HRTFs).
This file is a copy of mass/src/aux/functions.py imported in music/utils.py as from .functions import * but it should be integrated into music package more properly.
-
music.core.functions.
AD
(d=2, A=20, D=20, S=-5, R=50, trans='exp', alpha=1, dB=-80, to_zero=1, nsamples=0, sonic_vector=0, fs=44100)¶ Synthesize an ADSR envelope.
ADSR (Atack, Decay, Sustain, Release) is a very traditional loudness envelope in sound synthesis [1].
- d : scalar
- The duration of the envelope in seconds.
- A : scalar
- The duration of the Attack in milliseconds.
- D : scalar
- The duration of the Decay in milliseconds.
- S : scalar
- The Sustain level after the Decay in decibels. Usually negative.
- R : scalar
- The duration of the Release in milliseconds.
- trans : string
- “exp” for exponential transitions of amplitude (linear loudness). “linear” for linear transitions of amplitude.
- alpha : scalar or array_like
- An index to make the exponential fade slower or faster [1]. Ignored it transitions=”linear” or alpha=1. If it is an array_like, it should hold three values to be used in Attack, Decay and Release.
- dB : scalar or array_like
- The decibels deviation to reach before using a linear fade to reach zero amplitude. If it is an array_like, it should hold two values, one for Attack and another for Release. Ignored if trans=”linear”.
- to_zero : scalar or array_like
- The duration in milliseconds for linearly departing from zero in the Attack and reaching the value of zero at the end of the Release. If it is an array_like, it should hold two values, one for Attack and another for Release. Is ignored if trans=”linear”.
- nsamples : integer
- The number of samples of the envelope. If supplied, d is ignored.
- sonic_vector : array_like
- Samples for the ADSR envelope to be applied to. If supplied, d and nsamples are ignored.
- fs : integer
- The sample rate.
- AD : ndarray
- A numpy array where each value is a value of the envelope for the PCM samples if sonic_vector is 0. If sonic_vector is input, AD is the sonic vector with the ADSR envelope applied to it.
T : An oscillation of loudness. L : A loudness transition. F : A fade in or fade out.
>>> W(V()*AD()) # writes a WAV file of a note with ADSR envelope >>> s = H( [V()*AD(A=i, R=j) for i, j in zip([6, 50, 300], [100, 10, 200])] ) # OR >>> s = H( [AD(A=i, R=j, sonic_vector=V()) for i, j in zip([6, 15, 100], [2, 2, 20])] ) >>> envelope = AD(d=440, A=10e3, D=0, R=5e3) # a lengthy envelope
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
ADS
(d=2, A=20, D=20, S=-5, R=50, trans='exp', alpha=1, dB=-80, to_zero=1, nsamples=0, sonic_vector=0, fs=44100)¶ A shorthand to make an ADSR envelope for a stereo sound.
See ADSR() for more information.
-
music.core.functions.
AM
(d=2, fm=50, a=0.4, taba=array([ 0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), nsamples=0, sonic_vector=0, fs=44100)¶ Synthesize an AM envelope or apply it to a sound.
Set fm=0 or a=0 for a constant envelope with value 1. An AM is a linear oscillatory pattern of amplitude [1].
- d : scalar
- The duration of the envelope in seconds.
- fm : scalar
- The frequency of the modultar in Hertz.
- a : scalar in [0,1]
- The maximum deviation of amplitude of the AM.
- tabm : array_like
- The table with the waveform for the tremolo oscillatory pattern.
- nsamples : integer
- The number of samples of the envelope. If supplied, d is ignored.
- sonic_vector : array_like
- Samples for the tremolo to be applied to. If supplied, d and nsamples are ignored.
- fs : integer
- The sample rate.
- T : ndarray
- A numpy array where each value is a PCM sample of the envelope. if sonic_vector is 0. If sonic_vector is input, T is the sonic vector with the AM applied to it.
V : A musical note with an oscillation of pitch. FM : A linear oscillation of fundamental frequency. T : A tremolo, an oscillation of loudness.
>>> W(V()*AM()) # writes a WAV file of a note with tremolo >>> s = H( [V()*AM(fm=i, a=j) for i, j in zip([60, 150, 100], [2, 1, 20])] ) # OR >>> s = H( [AM(fm=i, a=j, sonic_vector=V()) for i, j in zip([60, 150, 100], [2, 1, 20])] ) >>> envelope2 = AM(440, 150, 60) # a lengthy envelope
In the MASS framework implementation, for obtaining a sound with a tremolo (or AM), the tremolo pattern is considered separately from a synthesis of the sound.
The vibrato and FM patterns are considering when synthesizing the sound.
One might want to run this function twice to obtain a stereo reverberation.
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
D
(f=220, d=2, tab=array([-1. , -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), x=[-10, 10], y=[1, 1], stereo=True, zeta=0.215, temp=20, nsamples=0, fs=44100)¶ A simple note with a transition of localization and resulting Doppler effect.
- f : scalar
- The frequency of the note in Hertz.
- d : scalar
- The duration of the note in seconds.
- tab : array_like
- The table with the waveform to synthesize the sound.
- x : iterable of scalars
- The starting and ending x positions.
- y : iterable of scalars
- The starting and ending y positions.
- stereo : boolean
- If True, returns a (2, nsamples) array representing a stereo sound. Else it returns a simple array for a mono sound.
- temp : scalar
- The air temperature in Celsius. (Used to calculate the acoustic velocity.)
- nsamples : integer
- The number of samples in the sound. If not 0, d is ignored.
- fs : integer
- The sample rate.
- s : ndarray
- The PCM samples of the resulting sound.
D_ : a note with arbitrary vibratos, transitions of pitch and transitions of localization. PV_ : a note with an arbitrary sequence of pitch transition and a meta-vibrato.
>>> WS(D()) >>> W(T()*D(stereo=False))
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
D_
(f=[220, 440, 330], d=[[2, 3], [2, 5, 3], [2, 5, 6, 1, 0.4], [4, 6, 1]], fv=[[2, 6, 1], [0.5, 15, 2, 6, 3]], nu=[[2, 1, 5], [4, 3, 7, 10, 3]], alpha=[[1, 1], [1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1]], x=[-10, 10, 5, 3], y=[1, 1, 0.1, 0.1], method=['lin', 'exp', 'lin'], tab=[[array([-1. , -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), array([-1. , -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ])], [array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([-1. , -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ])], [array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ])]], stereo=True, zeta=0.215, temp=20, nsamples=0, fs=44100)¶ A sound with arbitrary meta-vibratos, transitions of frequency and localization.
- f : list of lists of scalars
- The frequencies of the note at each end of the transitions.
- d : list of lists of scalars
- The durations of the pitch transitions and then of the vibratos and then of the position transitions.
- fv : list of lists of scalars
- The frequencies of each vibrato.
- nu : list of lists of scalars
- The maximum deviation of pitch in the vibratos in semitones.
- alpha : list of lists of scalars
- Indexes to distort the pitch deviations of the transitions and the vibratos.
- x : list of lists of scalars
- The x positions at each end of the transitions.
- y : list of lists of scalars
- The y positions at each end of the transitions.
- method : list of strings
- An entry for each transition of location: ‘exp’ for exponential and ‘lin’ (default) for linear.
- stereo : boolean
- If True, returns a (2, nsamples) array representing a stereo sound. Else it returns a simple array for a mono sound.
- tab : list of lists of array_likes
- The tables with the waveforms to synthesize the sound and then for the oscillatory patterns of the vibratos. All the tables for f should have the same size.
- zeta : scalar
- The distance between the ears in meters.
- temp : scalar
- The air temperature in Celsius. (Used to calculate the acoustic velocity.)
- nsamples : scalar
- The number of samples of the sound. If supplied, d is not used.
- fs : scalar
- The sample rate.
- s : ndarray
- A numpy array where each value is a PCM sample of the sound.
PV : A note with a glissando and a vibrato. D : A note with a simple linear transition of location. PVV : A note with a glissando and two vibratos. VV : A note with a vibrato with two oscillatory patterns. N : a basic musical note without vibrato. V : a musical note with an oscillation of pitch. T : a tremolo, an oscillation of loudness. F : fade in and out. L : a transition of loudness.
>>> W(D_()) # writes file with glissandi and vibratos
Check the functions above for more information about how each feature of this function is implemented.
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
F
(d=2, out=True, method='exp', dB=-80, alpha=1, perc=1, nsamples=0, sonic_vector=0, fs=44100)¶ A fade in or out.
Implements the loudness transition and asserts that it reaches zero amplitude.
- d : scalar
- The duration in seconds of the fade.
- out : boolean
- If True, the fade is a fade out, else it is a fade in.
- method : string
- “exp” for an exponential transition of amplitude (linear loudness). “linear” for a linear transition of amplitude.
- dB : scalar
- The decibels from which to reach before using the linear transition to reach zero. Not used if method=”linear”.
- alpha : scalar
- An index to make the exponential fade slower or faster [1]. Ignored it transitions=”linear”.
- perc : scalar
- The percentage of the fade that is linear to assure it reaches zero. Has no effect if method=”linear”.
- nsamples : integer
- The number of samples of the fade. If supplied, d is ignored.
- sonic_vector : array_like
- Samples for the fade to be applied to. If supplied, d and nsamples are ignored.
- fs : integer
- The sample rate. Only used if nsamples and sonic_vector are not supplied.
- T : ndarray
- A numpy array where each value is a value of the envelope for the PCM samples. If sonic_vector is input, T is the sonic vector with the fade applied to it.
AD : An ADSR envelope. L : A transition of loudness. L_ : An envelope with an arbitrary number or loudness transitions. T : An oscillation of loudness.
>>> W(V()*F()) # writes a WAV file with a fade in >>> s = H( [V()*F(out=i, method=j) for i, j in zip([1, 0, 1], ["exp", "exp", "linear"])] ) # OR >>> s = H( [F(out=i, method=j, sonic_vector=V()) for i, j in zip([1, 0, 1], ["exp", "exp", "linear"])] ) >>> envelope = F(d=10, out=0, perc=0.1) # a lengthy fade in
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
FIR
(samples, sonic_vector, freq=True, max_freq=True)¶ Apply a FIR filter to a sonic_array.
- samples : array_like
- A sequence of absolute values for the frequencies (if freq=True) or samples of an impulse response.
- sonic_vector : array_like
- An one-dimensional array with the PCM samples of the signal (e.g. sound) for the FIR filter to be applied to.
- freq : boolean
- Set to True if samples are frequency absolute values or False if samples is an impulse response. If max_freq=True, the separations between the frequencies are fs/(2*N-2). If max_freq=False, the separation between the frequencies are fs/(2*N-1). Where N is the length of the provided samples.
- max_freq : boolean
- Set to true if the last item in the samples is related to the Nyquist frequency fs/2. Ignored if freq=False.
If freq=True, the samples are the absolute values of the frequency components. The phases are set to zero to maintain the phases of the components of the original signal.
-
music.core.functions.
FM
(f=220, d=2, fm=100, mu=2, tab=array([-1., -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), tabm=array([ 0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), nsamples=0, fs=44100)¶ Synthesize a musical note with FM synthesis.
Set fm=0 or mu=0 (or use N()) for a note without FM. A FM is a linear oscillatory pattern of frequency [1].
- f : scalar
- The frequency of the note in Hertz.
- d : scalar
- The duration of the note in seconds.
- fm : scalar
- The frequency of the modulator in Hertz.
- mu : scalar
- The maximum deviation of frequency in the modulator in Hertz.
- tab : array_like
- The table with the waveform for the carrier.
- tabv : array_like
- The table with the waveform for the modulator.
- nsamples : integer
- The number of samples in the sound. If supplied, d is ignored.
- fs : integer
- The sample rate.
- s : ndarray
- A numpy array where each value is a PCM sample of the note.
N : A basic musical note without vibrato. V : A musical note with an oscillation of pitch. T : A tremolo, an oscillation of loudness. AM : A linear oscillation of amplitude (not linear loudness).
>>> W(FM()) # writes a WAV file of a note >>> s = H( [FM(i, j) for i, j in zip([200, 500, 100], [2, 1, 2])] ) >>> s2 = FM(440, 1.5, 600, 10)
In the MASS framework implementation, for a sound with a vibrato (or FM) to be synthesized using LUT, the vibrato (or FM) pattern is considered when performing the lookup calculations.
The tremolo and AM patterns are implemented as separate amplitude envelopes.
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
IIR
(sonic_vector, A, B)¶ Apply an IIR filter to a signal.
- sonic_vector : array_like
- An one dimensional array representing the signal (potentially a sound) for the filter to by applied to.
- A : iterable of scalars
- The feedforward coefficients.
- B : iterable of scalars
- The feedback filter coefficients.
Check [1] to know more about this function.
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
L
(d=2, dev=10, alpha=1, to=True, method='exp', nsamples=0, sonic_vector=0, fs=44100)¶ An envelope for linear or exponential transition of amplitude.
An exponential transition of loudness yields a linean transition of loudness (theoretically).
- d : scalar
- The duration of the envelope in seconds.
- dev : scalar
- The deviation of the transition. If method=”exp” the deviation is in decibels. If method=”linear” the deviation is an amplitude proportion.
- alpha : scalar
- An index to make the transition slower or faster [1]. Ignored it method=”linear”.
- to : boolean
- If True, the transition ends at the deviation. If False, the transition starts at the deviation.
- method : string
- “exp” for exponential transitions of amplitude (linear loudness). “linear” for linear transitions of amplitude.
- nsamples : integer
- The number of samples of the envelope. If supplied, d is ignored.
- sonic_vector : array_like
- Samples for the envelope to be applied to. If supplied, d and nsamples are ignored.
- fs : integer
- The sample rate. Only used if nsamples and sonic_vector are not supplied.
- E : ndarray
- A numpy array where each value is a value of the envelope for the PCM samples. If sonic_vector is supplied, ai is the sonic vector with the envelope applied to it.
L_ : An envelope with an arbitrary number of transitions. F : Fade in and out. AD : An ADSR envelope. T : An oscillation of loudness.
>>> W(V()*L()) # writes a WAV file of a loudness transition >>> s = H( [V()*L(dev=i, method=j) for i, j in zip([6, -50, 2.3], ["exp", "exp", "linear"])] ) # OR >>> s = H( [L(dev=i, method=j, sonic_vector=V()) for i, j in zip([6, -50, 2.3], ["exp", "exp", "linear"])] ) >>> envelope = L(d=10, dev=-80, to=False, alpha=2) # a lengthy fade in
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
L_
(d=[2, 4, 2], dev=[5, -10, 20], alpha=[1, 0.5, 20], method=['exp', 'exp', 'exp'], nsamples=0, sonic_vector=0, fs=44100)¶ An envelope with linear or exponential transitions of amplitude.
See L() for more details.
- d : iterable
- The durations of the transitions in seconds.
- dev : iterable
- The deviation of the transitions. If method=”exp” the deviation is in decibels. If method=”linear” the deviation is an amplitude proportion.
- alpha : iterable
- Indexes to make the transitions slower or faster [1]. Ignored it method[1]=”linear”.
- method : iterable
- Methods for each transition. “exp” for exponential transitions of amplitude (linear loudness). “linear” for linear transitions of amplitude.
- nsamples : interable
- The number of samples of each transition. If supplied, d is ignored.
- sonic_vector : array_like
- Samples for the envelope to be applied to. If supplied, d or nsamples is used, the final sound has the greatest duration of sonic_array and d (or nsamples) and missing samples are replaced with silence (if sonic_vector is shorter) or with a constant value (if d or nsamples yield shorter sequences).
- fs : integer
- The sample rate. Only used if nsamples and sonic_vector are not supplied.
- E : ndarray
- A numpy array where each value is a value of the envelope for the PCM samples. If sonic_vector is supplied, E is the sonic vector with the envelope applied to it.
L : An envelope for a loudness transition. F : Fade in and out. AD : An ADSR envelope. T : An oscillation of loudness.
>>> W(V(d=8)*L_()) # writes a WAV file with a loudness transitions
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
N
(f=220, d=2, tab=array([-1., -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), nsamples=0, fs=44100)¶ Synthesize a basic musical note.
- f : scalar
- The frequency of the note in Hertz.
- d : scalar
- The duration of the note in seconds.
- tab : array_like
- The table with the waveform to synthesize the sound.
- nsamples : integer
- The number of samples in the sound. If not 0, d is ignored.
- fs : integer
- The sample rate.
- s : ndarray
- A numpy array where each value is a PCM sample of the note.
V : A note with vibrato. T : A tremolo envelope.
>>> W(N()) # writes a WAV file of a note >>> s = H( [N(i, j) for i, j in zip([200, 500, 100], [2, 1, 2])] ) >>> s2 = N(440, 1.5, tab=Sa)
In the MASS framework implementation, for a sound with a vibrato (or FM) to be synthesized using LUT, the vibrato pattern is considered when performing the lookup calculations.
The tremolo and AM patterns are implemented as separate amplitude envelopes.
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
N_
(f=220, d=2, phase=0, tab=array([-1., -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), nsamples=0, fs=44100)¶ Synthesize a basic musical note with a phase.
Is useful in more complex synthesis routines. For synthesizing a musical note directly, you probably want to use N() and disconsider the phase.
- f : scalar
- The frequency of the note in Hertz.
- d : scalar
- The duration of the note in seconds.
- phase : scalar
- The phase of the wave in radians.
- tab : array_like
- The table with the waveform to synthesize the sound.
- nsamples : integer
- The number of samples in the sound. If not 0, d is ignored.
- fs : integer
- The sample rate.
- s : ndarray
- A numpy array where each value is a PCM sample of the note.
N : A basic note. V : A note with vibrato. T : A tremolo envelope.
>>> W(N_()) # writes a WAV file of a note >>> s = H( [N_(i, j) for i, j in zip([200, 500, 100], [2, 1, 2])] ) >>> s2 = N_(440, 1.5, tab=Sa)
In the MASS framework implementation, for a sound with a vibrato (or FM) to be synthesized using LUT, the vibrato pattern is considered when performing the lookup calculations.
The tremolo and AM patterns are implemented as separate amplitude envelopes.
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
P
(f1=220, f2=440, d=2, alpha=1, tab=array([ 0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), method='exp', nsamples=0, fs=44100)¶ A note with a pitch transition: a glissando.
- f1 : scalar
- The starting frequency.
- f2 : scalar
- The final frequency.
- d : scalar
- The duration of the sound in seconds.
- alpha : scalar
- An index to begin the transition faster or slower. If alpha != 1, the transition is not of linear pitch.
- tab : array_like
- The table with the waveform to synthesize the sound.
- nsamples : integer
- The number of samples of the sound. If supplied, d is not used.
- method : string
- “exp” for an exponential transition of frequency (linear pitch). “lin” for a linear transition of amplitude.
- fs : integer
- The sample rate.
- s : ndarray
- A numpy array where each value is a PCM sample of the sound.
N : A basic musical note without vibrato or pitch transition. V : A musical note with an oscillation of pitch. T : A tremolo, an oscillation of loudness. L : A transition of loudness. F : Fade in or out.
>>> W(P()) # writes file with a glissando >>> s = H( [P(i, j) for i, j in zip([220, 440, 4000], [440, 220, 220])] ) >>> W(s) # writes a file with glissandi
-
music.core.functions.
PV
(f1=220, f2=440, d=2, fv=4, nu=2, alpha=1, alphav=1, tab=array([ 0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), tabv=array([ 0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), nsamples=0, fs=44100)¶ A note with a pitch transition (a glissando) and a vibrato.
- f1 : scalar
- The starting frequency.
- f2 : scalar
- The final frequency.
- d : scalar
- The duration of the sound in seconds.
- fv : scalar
- The frequency of the vibrato oscillations in Hertz.
- nu : scalar
- The maximum deviation of pitch of the vibrato in semitones.
- alpha : scalar
- An index to begin the transitions faster or slower. If alpha != 1, the transition is not of linear pitch.
- alphav : scalar
- An index to distort the pitch deviation of the vibrato.
- tab : array_like
- The table with the waveform to synthesize the sound.
- tabv : array_like
- The table with the waveform for the vibrato oscillatory pattern.
- nsamples : integer
- The number of samples of the sound. If supplied, d is not used.
- fs : integer
- The sample rate.
- s : ndarray
- A numpy array where each value is a PCM sample of the sound.
P : A glissando. V : A musical note with an oscillation of pitch. N : A basic musical note without vibrato. T : A tremolo, an oscillation of loudness. F : Fade in and out. L : A transition of loudness.
>>> W(PV()) # writes file with a glissando and vibrato >>> s = H( [AD(sonic_vector=PV(i, j)) for i, j in zip([220, 440, 4000], [440, 220, 220])] ) >>> W(s) # writes a file with glissandi and vibratos
-
music.core.functions.
PVV
(f1=220, f2=440, d=2, fv1=2, fv2=6, nu1=2, nu2=0.5, alpha=1, alphav1=1, alphav2=1, tab=array([-1., -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), tabv1=array([ 0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), tabv2=array([ 0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), nsamples=0, fs=44100)¶ A note with a glissando and a vibrato that also has a secondary oscillatory pattern.
- f1 : scalar
- The starting frequency.
- f2 : scalar
- The final frequency.
- d : scalar
- The duration of the sound in seconds.
- fv1 : scalar
- The frequency of the vibrato.
- fv2 : scalar
- The frequency of the secondary pattern of the vibrato.
- nu1 : scalar
- The maximum deviation of pitch in the vibrato in semitones.
- nu1 : scalar
- The maximum deviation in semitones of pitch in the secondary pattern of the vibrato.
- alpha : scalar
- An index to begin the transitions faster or slower. If alpha != 1, the transition is not of linear pitch.
- alphav1 : scalar
- An index to distort the pitch deviation of the vibrato.
- alphav2 : scalar
- An index to distort the pitch deviation of the secondary pattern of the vibrato.
- tab : array_like
- The table with the waveform to synthesize the sound.
- tabv1 : array_like
- The table with the waveform for the vibrato oscillatory pattern.
- tabv2 : array_like
- The table with the waveform for the secondary pattern of the vibrato.
- nsamples : scalar
- The number of samples of the sound. If supplied, d is not used.
- fs : scalar
- The sample rate.
- s : ndarray
- A numpy array where each value is a PCM sample of the sound.
PV : A note with a glissando and a vibrato. VV : A note with a vibrato with two oscillatory patterns. PV_ : A note with arbitrary pitch transitions and vibratos. V : a musical note with an oscillation of pitch. N : a basic musical note without vibrato. T : a tremolo, an oscillation of loudness. F : fade in or out. L : a transition of loudness.
>>> W(PVV()) # writes file with a two simultaneous vibratos and a glissando >>> s = H( [AD(sonic_vector=PVV(fv2=i, nu1=j)) for i, j in zip([330, 440, 100], [8, 2, 15])] ) >>> W(s) # writes a file with two vibratos and a glissando
-
music.core.functions.
PV_
(f=[220, 440, 330], d=[[2, 3], [2, 5, 3], [2, 5, 6, 1, 0.4]], fv=[[2, 6, 1], [0.5, 15, 2, 6, 3]], nu=[[2, 1, 5], [4, 3, 7, 10, 3]], alpha=[[1, 1], [1, 1, 1], [1, 1, 1, 1, 1]], tab=[[array([-1. , -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), array([-1. , -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ])], [array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([-1. , -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ])], [array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ])]], nsamples=0, fs=44100)¶ A note with an arbitrary sequence of pitch transition and a meta-vibrato.
A meta-vibrato consists in multiple vibratos. The sequence of pitch transitions is a glissandi.
- f : list of lists of scalars
- The frequencies of the note at each end of the transitions.
- d : list of lists of scalars
- The durations of the transitions and then of the vibratos.
- fv : list of lists of scalars
- The frequencies of each vibrato.
- nu : list of lists of scalars
- The maximum deviation of pitch in the vibratos in semitones.
- alpha : list of lists of scalars
- Indexes to distort the pitch deviations of the transitions and the vibratos.
- tab : list of lists of array_likes
- The tables with the waveforms to synthesize the sound and for the oscillatory patterns of the vibratos. All the tables for f should have the same size.
- nsamples : scalar
- The number of samples of the sound. If supplied, d is not used.
- fs : scalar
- The sample rate.
- s : ndarray
- A numpy array where each value is a PCM sample of the sound.
PV : A note with a glissando and a vibrato. PVV : A note with a glissando and two vibratos. VV : A note with a vibrato with two oscillatory patterns. N : a basic musical note without vibrato. V : a musical note with an oscillation of pitch. T : a tremolo, an oscillation of loudness. F : fade in and out. L : a transition of loudness.
>>> W(PV_()) # writes file with glissandi and vibratos
-
music.core.functions.
R
(d=1.9, d1=0.15, decay=-50, stat='brown', sonic_vector=0, fs=44100)¶ Apply an artificial reverberation or return the impulse response.
- d : scalar
- The total duration of the reverberation in seconds.
- d1 : scalar
- The duration of the first phase of the reverberation in seconds.
- decay : scalar
- The total decay of the last incidence in decibels.
- stat : string or scalar
- A string or scalar specifying the noise. Passed to noises(ntype=scalar).
- sonic_vector : array_like
- An optional one dimensional array for the reverberation to be applied.
- fs : scalar
- The sampling frequency.
- s : numpy.ndarray
- An array if the impulse response of the reverberation (if sonic_vector is not specified), or with the reverberation applied to sonic_vector.
This is a simple artificial reverberation with a progressive loudness decay of the reincidences of the sound and with two periods: the first consists of scattered reincidences, the second period reincidences is modeled by a noise.
Comparing with the description in [1], the frequency bands are ignored.
One might want to run this function twice to obtain a stereo reverberation.
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
T
(d=2, fa=2, dB=10, alpha=1, taba=array([ 0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), nsamples=0, sonic_vector=0, fs=44100)¶ Synthesize a tremolo envelope or apply it to a sound.
Set fa=0 or dB=0 for a constant envelope with value 1. A tremolo is an oscillatory pattern of loudness [1].
- d : scalar
- The duration of the envelope in seconds.
- fa : scalar
- The frequency of the tremolo oscillations in Hertz.
- dB : scalar
- The maximum deviation of loudness in the tremolo in decibels.
- alpha : scalar
- An index to distort the tremolo pattern [1].
- taba : array_like
- The table with the waveform for the tremolo oscillatory pattern.
- nsamples : integer
- The number of samples of the envelope. If supplied, d is ignored.
- sonic_vector : array_like
- Samples for the tremolo to be applied to. If supplied, d and nsamples are ignored.
- fs : integer
- The sample rate.
- T : ndarray
- A numpy array where each value is a PCM sample of the envelope. if sonic_vector is 0. If sonic_vector is input, T is the sonic vector with the tremolo applied to it.
V : A musical note with an oscillation of pitch. FM : A linear oscillation of fundamental frequency. AM : A linear oscillation of amplitude.
>>> W(V()*T()) # writes a WAV file of a note with tremolo >>> s = H( [V()*T(fa=i, dB=j) for i, j in zip([6, 15, 100], [2, 1, 20])] ) # OR >>> s = H( [T(fa=i, dB=j, sonic_vector=V()) for i, j in zip([6, 15, 100], [2, 1, 20])] ) >>> envelope2 = T(440, 1.5, 60) # a lengthy envelope
In the MASS framework implementation, for obtaining a sound with a tremolo (or AM), the tremolo pattern is considered separately from a synthesis of the sound.
The vibrato and FM patterns are considering when synthesizing the sound.
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
T_
(d=[[3, 4, 5], [2, 3, 7, 4]], fa=[[2, 6, 20], [5, 6.2, 21, 5]], dB=[[10, 20, 1], [5, 7, 9, 2]], alpha=[[1, 1, 1], [1, 1, 1, 9]], taba=[[array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ])], [array([-1. , -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), array([-1. , -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), array([-1. , -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), array([ 0. , 0.0003835 , 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ])]], nsamples=0, sonic_vector=0, fs=44100)¶ An envelope with multiple tremolos.
- d : iterable of iterable of scalars
- the durations of each tremolo.
- fa : iterable of iterable of scalars
- The frequencies of each tremolo.
- dB : iterable of iterable of scalars
- The maximum loudness variation of each tremolo.
- alpha : iterable of iterable of scalars
- Indexes for distortion of each tremolo [1].
- taba : iterable of iterable of array_likes
- Tables for lookup for each tremolo.
- nsamples : iterable of iterable of scalars
- The number of samples or each tremolo.
- sonic_vector : array_like
- The sound to which apply the tremolos. If supplied, the tremolo lines are applied to the sound and missing samples are completed by zeros (if sonic_vector is smaller then the lengthiest tremolo) or ones (is sonic_vector is larger).
- fs : integer
- The sample rate
- E : ndarray
- A numpy array where each value is a value of the envelope for the PCM samples. If sonic_vector is supplied, E is the sonic vector with the envelope applied to it.
L : An envelope for a loudness transition. L_ : An envelope with an arbitrary number of transitions. F : Fade in and out. AD : An ADSR envelope. T : An oscillation of loudness.
>>> W(V(d=8)*L_()) # writes a WAV file with a loudness transitions
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
V
(f=220, d=2, fv=4, nu=2, tab=array([-1., -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), tabv=array([ 0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), alpha=1, nsamples=0, fs=44100)¶ Synthesize a musical note with a vibrato.
Set fv=0 or nu=0 (or use N()) for a note without vibrato. A vibrato is an oscillatory pattern of pitch [1].
- f : scalar
- The frequency of the note in Hertz.
- d : scalar
- The duration of the note in seconds.
- fv : scalar
- The frequency of the vibrato oscillations in Hertz.
- nu : scalar
- The maximum deviation of pitch in the vibrato in semitones.
- tab : array_like
- The table with the waveform to synthesize the sound.
- tabv : array_like
- The table with the waveform for the vibrato oscillatory pattern.
- alpha : scalar
- An index to distort the vibrato [1]. If alpha != 1, the vibrato is not of linear pitch.
- nsamples : integer
- The number of samples in the sound. If supplied, d is ignored.
- fs : integer
- The sample rate.
- s : ndarray
- A numpy array where each value is a PCM sample of the note.
N : A basic musical note without vibrato. T : A tremolo, an oscillation of loudness. FM : A linear oscillation of the frequency (not linear pitch). AM : A linear oscillation of amplitude (not linear loudness). V_ : A shorthand to render a note with vibrato using
a reference frequency and a pitch interval.>>> W(V()) # writes a WAV file of a note >>> s = H( [V(i, j) for i, j in zip([200, 500, 100], [2, 1, 2])] ) >>> s2 = V(440, 1.5, 6, 1)
In the MASS framework implementation, for a sound with a vibrato (or FM) to be synthesized using LUT, the vibrato pattern is considered when performing the lookup calculations.
The tremolo and AM patterns are implemented as separate amplitude envelopes.
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
VV
(f=220, d=2, fv1=2, fv2=6, nu1=2, nu2=4, alphav1=1, alphav2=1, tab=array([-1., -0.99975586, -0.99951172, ..., -0.99951172, -0.99975586, -1. ]), tabv1=array([ 0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), tabv2=array([ 0., 0.0003835, 0.00076699, ..., -0.00115049, -0.00076699, -0.0003835 ]), nsamples=0, fs=44100)¶ A note with a vibrato that also has a secondary oscillatory pattern.
- f : scalar
- The frequency of the note.
- d : scalar
- The duration of the sound in seconds.
- fv1 : scalar
- The frequency of the vibrato.
- fv2 : scalar
- The frequency of the secondary pattern of the vibrato.
- nu1 : scalar
- The maximum deviation of pitch in the vibrato in semitones.
- nu2 : scalar
- The maximum deviation in semitones of pitch in the secondary pattern of the vibrato.
- alphav1 : scalar
- An index to distort the pitch deviation of the vibrato.
- alphav2 : scalar
- An index to distort the pitch deviation of the secondary pattern of the vibrato.
- tab : array_like
- The table with the waveform to synthesize the sound.
- tabv1 : array_like
- The table with the waveform for the vibrato oscillatory pattern.
- tabv2 : array_like
- The table with the waveform for the secondary pattern of the vibrato.
- nsamples : scalar
- The number of samples of the sound. If supplied, d is not used.
- fs : scalar
- The sample rate.
- s : ndarray
- A numpy array where each value is a PCM sample of the sound.
PV : A note with a glissando and a vibrato. PVV : A note with a glissando and a vibrato with two oscillatory patterns. N : A basic musical note without vibrato. V : A musical note with an oscillation of pitch. T : A tremolo, an oscillation of loudness. F : Fade in and out. L : A transition of loudness.
>>> W(VV()) # writes file with a two simultaneous vibratos >>> s = H( [AD(sonic_vector=VV(fv1=i, fv2=j)) for i, j in zip([2, 6, 4], [8, 10, 15])] ) >>> W(s) # writes a file with two vibratos
-
music.core.functions.
W
(sonic_vector=array([ 0.35356651, 0.96444061, 0.11645631, ..., 0.15844934, 0.38238774, 0.22731215]), filename='asound.wav', fs=44100, fades=0, bit_depth=16, remove_bias=True)¶ Write a mono WAV file for a numpy array.
- One can also use, for example:
- import sounddevice as S S.play(__n(array))
- sonic_vector : array_like
- The PCM samples to be written as a WAV sound file. The samples are always normalized by __n(sonic_vector) to have samples between -1 and 1.
- filename : string
- The filename to use for the file to be written.
- fs : scalar
- The sample frequency.
- fades : interable
- An iterable with two values for the milliseconds you want for the fade in and out (to avoid clicks).
- bit_depth : integer
- The number of bits in each sample of the final file.
- remove_bias : boolean
- Whether to remove or not the bias (or offset)
__n : Normalizes an array to [-1,1] W_ : Writes an array with the same arguments and order of them as scipy.io.wavfile. WS ; Write a stereo file.
-
music.core.functions.
WS
(sonic_vector=array([[ 0.92956207, 0.17481337, 0.49301615, ..., 0.26537058, 0.84012122, 0.84421445], [ 0.36646579, 0.644846 , 0.12506887, ..., 0.04606155, 0.97674495, 0.68533196]]), filename='asound.wav', fs=44100, fades=0, bit_depth=16, remove_bias=True, normalize_sep=False)¶ Write a stereo WAV files for a numpy array.
- sonic_vector : array_like
- The PCM samples to be written as a WAV sound file. The samples are always normalized by __n(sonic_vector) to have samples between -1 and 1 and remove the offset. Use array of shape (nchannels, nsamples).
- filename : string
- The filename to use for the file to be written.
- fs : scalar
- The sample frequency.
- fades : interable
- An iterable with two values for the milliseconds you want for the fade in and out (to avoid clicks).
- bit_depth : integer
- The number of bits in each sample of the final file.
- remove_bias : boolean
- Whether to remove or not the bias (or offset)
- normalize_sep : boolean
- Set to True if each channel should be normalized separately. If False (default), the arrays will be rescaled in the same proportion.
__ns : Normalizes a stereo array to [-1,1] W ; Write a mono file.
-
music.core.functions.
W_
(fn, fs, sa)¶ To mimic scipy.io.wavefile input
-
music.core.functions.
convolve
(sig1, sig2)¶
-
music.core.functions.
loc
(sonic_vector=array([-1., -0.98022461, -0.96020508, ..., -0.94018555, -0.96020508, -0.98022461]), theta=0, dist=0, x=0.1, y=0.01, zeta=0.215, temp=20, fs=44100)¶ Make a mono sound stereo and localize it by a very naive method.
See bellow for implementation notes.
- sonic_vector : array_like
- An one dimensional with the PCM samples of the sound.
- x : scalar
- The lateral component of the position in meters.
- y : scalar
- The frontal component of the position in meters.
- theta : scalar
- The azimuthal angle of the position in degrees. If theta is supplied, x and y are ignored and dist must also be supplied for the sound localization to have effect.
- dist : scalar
- The distance of the source from the listener in meters.
- zeta : scalar
- The distance between the ears in meters.
- temp : scalar
- The temperature in Celsius used for calculating the speed of sound.
- fs : integer
- The sample rate.
- s : ndarray
- A (2, nsamples) shaped array with the PCM samples of the stereo sound.
R : A reverberator. loc_ : a less naive implementation of localization by ITD and IID. hrtf : performs localization by means of a Head Related Transfer Function.
>>> WS(loc()) # write a soundfile that is localized >>> WS(H([loc(V(d=1), x=i, y=j) for i, j in ... zip([.1,.7,n.pi-.1,n.pi-.7], [.1,.1,.1,.1])]))
Uses the most naive ITD and IID calculations as described in [1]. A less naive method is implemented in loc_(). Nonetheless, if dist is small enough (e.g. <.3), the perception of theta occurs and might be used. The advantages of this method are:
- It is fast.
- It is simple.
- It is true to sound propagation phenomenon
(although it does not consider the human body beyond the localization of the ears). - It can be used easily for tweaks (such as for a moving source resulting in a Doppler Effect).
When az = tan^{-1}(y/x) lies in the ‘cone of confusion’, many values of x and y have the same ITD and IID [1]. Furthermore, lateral sources have the low frequencies diffracted and reach the opposite ear with a delay of ~0.7s [1]. The height of a source and if it is in front or behind a listener are cues given by te HRTF [1]. These issues are not taken into account in this function.
The value of zeta is ~0.215 for adult humans [1].
This implementation assumes that the speed of sound (in air) is s = 331.3+0.606*temp.
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
loc2
(sonic_vector=array([-1., -0.98022461, -0.96020508, ..., -0.94018555, -0.96020508, -0.98022461]), theta1=90, theta2=0, dist1=0.1, dist2=0.1, zeta=0.215, temp=20, fs=44100)¶ A linear variation of localization
-
music.core.functions.
loc_
(sonic_vector=array([-1., -0.98022461, -0.96020508, ..., -0.94018555, -0.96020508, -0.98022461]), theta=-70, x=0.1, y=0.01, zeta=0.215, temp=20, method='ifft', fs=44100)¶ Make a mono sound stereo and localize it by experimental methods.
See bellow for implementation notes. These implementations are not standard and are only to illustrate the method of using ITD and IID that are frequency dependent.
- sonic_vector : array_like
- An one dimensional with the PCM samples of the sound.
- x : scalar
- The lateral component of the position in meters.
- y : scalar
- The frontal component of the position in meters.
- theta : scalar
- The azimuthal angle of the position in degrees. If theta is supplied, x and y are ignored and dist must also be supplied for the sound localization to have effect.
- dist : scalar
- The distance of the source from the listener in meters.
- zeta : scalar
- The distance between the ears in meters.
- temp : scalar
- The temperature in Celsius used for calculating the speed of sound.
- method : string
- Set to “ifft” for a working method that changes the fourier spectral coefficients. Set to “brute” for using an implementation that sinthesizes each sinusoid in the fourier spectrum separately (currently not giving good results for all sounds).
- fs : integer
- The sample rate.
- s : ndarray
- A (2, nsamples) shaped array with the PCM samples of the stereo sound.
R : A reverberator. loc : a more naive and fast implementation of localization by ITD and IID. hrtf : performs localization by means of a Head Related Transfer Function.
>>> WS(loc_()) # write a soundfile that is localized >>> WS(H([loc_(V(d=1), x=i, y=j) for i, j in ... zip([.1,.7,n.pi-.1,n.pi-.7], [.1,.1,.1,.1])]))
Uses a less naive ITD and IID calculations as described in [1].
See loc() for further notes.
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
noises
(ntype='brown', d=2, fmin=15, fmax=15000, nsamples=0, fs=44100)¶ Return a colored or user-refined noise.
- ntype : string or scalar
Specifies the decibels gain or attenuation per octave. It can be specified numerically (e.g. ntype=3.5 is 3.5 decibels gain per octave) or by strings:
“brown” is -6dB/octave “pink” is -3dB/octave “white” is 0dB/octave “blue” is 3dB/octave “violet” is 6dB/octave “black” is -12/dB/octave but, in theory, is any < -6dB/octaveSee [1] for more information.
- d : scalar
- The duration of the noise in seconds.
- fmin : scalar in [0, fs/2]
- The lowest frequency allowed.
- fmax : scalar in [0, fs/2]
- The highest frequency allowed. It should be > fmin.
- nsamples : integer
- The number of samples of the resulting sonic vector.
The noise is synthesized with components with random phases, with the moduli that are related to the decibels/octave, and with a frequency resolution of
fs/nsamples = fs/(fs*d) = 1/d HzCite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
rhythymToDurations
(durations=[4, 2, 2, 4, 1, 1, 1, 1, 2, 2, 4], frequencies=None, duration=0.25, BPM=None, total_duration=None)¶ Returns durations from rhythmic patterns.
- durations : interable of scalars
- The relative durations of each item (e.g. note).
- frequencies : iterable of scalars
- The number of the entry’s duration that fits into the pulse. If supplied, durations is ignored.
- duration : scalar
- A basic duration (e.g. for the pulse) in seconds.
- BPM : scalar
- The number of beats per second. If supplied, duration is ignored.
- total_duration: scalar
- The total duration of the sequence in seconds. If supplied, both BPM and duration are ignored.
durs : List of durations in seconds.
>>> dt = [4, 2, 2, 4, 1,1,1,1, 2, 2, 4] >>> durs0 = rhythymToDurations(dt, duration=.25) >>> df = [4, 8, 8, 4, 16, 16, 16, 16, 8, 8, 4] >>> durs0_ = rhythymToDurations(frequencies=df, duration=4) >>> dtut = [4,2,2, [8, 1,1,1], 4, [4, 1,1,.5,.5], 3,1, 3,1, 4] >>> durs1 = rhythymToDurations(dtut) >>> dtuf2 = [4,8,8, [2, 3,3,3], 4, [4, 3,3,6,6], 16/3, 16, 16/3, 16, 4] >>> durs1_ = rhythymToDurations(frequencies=dtut2, duration=4)
The durations parameter is considered to be in a temporal notation for durations/rhythm: each entry is a relative duration to be multiplied by the base duration given through duration, BPM or total_duration. >>> durs = [i*duration for i in durations]
The frequencies parameter is considered to be in a frequential notation: each entry is the number of the entry that fits a same duration (also given through duration, BPM or total_duration). >>> durs = [duration/i for i in frequencies]
The examples above yield (two by two) the same sequences of durations by using duration=0.25 when in temporal notation or duration=4 when in frequency notation.
To facilitate the description of rhythms (e.g. for tuplets), some set of durations might be an iterable inside durations or frequencies. In this case:
- ### if mode is temporal:
- total_dur = cell[0]*duration # durations are proportional to remaining values: d_ = [i/sum(cell[1:]) for i in cell[1:]] durs = [i*total_dur for i in d_]
- ### if mode is frequential:
- total_dur = duration/cell[0] # durations are inversely proportional to remaining values: d_ = [i/sum(cell[1:]) for i in cell[1:]] durs = [i*total_dur for i in d_]
An example for achieving the same sequence of durations through temporal or frequential notation and with cells for tuplets is the last two sequences of the examples.
- It might be a good idea to incorporate also this notation:
- d2 = [1, 4, 1, 4] # [quarter note + 4 sixteenth notes] x 2
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)
-
music.core.functions.
trill
(f=[440, 493.8833012561241], ft=17, d=5, fs=44100)¶ Make a trill.
This is just a simple function for exemplifying the synthesis of trills. The user is encouraged to make its own functions for trills and set e.g. ADSR envelopes, tremolos and vibratos as intended.
- f : iterable of scalars
- Frequencies to the iterated.
- ft : scalar
- The number of notes per second.
- d : scalar
- The maximum duration of the trill in seconds.
- fs : integer
- The sample rate.
V : A note with vibrato. PV_ : a note with an arbitrary sequence of pitch transition and a meta-vibrato. T : A tremolo envelope.
- s : ndarray
- The PCM samples of the resulting sound.
>>> W(trill())
Cite the following article whenever you use this function.
[1] Fabbri, Renato, et al. “Musical elements in the discrete-time representation of sound.” arXiv preprint arXiv:abs/1412.6853 (2017)