sample.evaluation.random module

Random generation of modal-like sounds

class sample.evaluation.random.BeatsGenerator(f_min: float = 200, f_max: float = 2000, f_a: float = 2, f_b: float = 2, amp_min: float = -10, decay_min: float = 0.5, decay: float = 1, onlybeat: bool = False, beat_min: float = 1.8, beat_max: float = 18, beat_a: float = 2, beat_b: float = 2, delta_min: float = 1.5, delta_max: float = 4, delta_a: float = 2, delta_b: float = 4, snr: float = 45, rng: Optional[Generator] = None, seed: Optional[int] = None)

Bases: object

Random generator for audio with beats. It generates audio with three partials and noise, where two of the partials are close enough to beat.

Parameters:
  • f_min (float) – Minimum frequency in Hertz

  • f_max (float) – Maximum frequency in Hertz

  • f_a (float) – Alpha coefficient for beta distribution of frequencies

  • f_b (float) – Beta coefficient for beta distribution of frequencies

  • amp_min (float) – Minimum amplitude value before normalization in dB

  • decay_min (float) – Minimum value for exponential distribution of decays

  • decay (float) – Expected value for exponential distribution of decays

  • onlybeat (bool) – If True, then set the amplitude of the non-beating partial to zero

  • beat_min (float) – Minimum beat frequency difference in Hz

  • beat_max (float) – Maximum beat frequency difference in Hz

  • beat_a (float) – Alpha coefficient for beta distribution of beat frequency differences

  • beat_b (float) – Beta coefficient for beta distribution of beat frequency differences

  • delta_min (float) – Minimum frequency difference between beating and non-beating partials in Bark

  • delta_max (float) – Maximum frequency difference between beating and non-beating partials in Bark

  • delta_a (float) – Alpha coefficient for beta distribution of frequency differences between beating and non-beating partials

  • delta_b (float) – Beta coefficient for beta distribution of frequency differences between beating and non-beating partials

  • snr (float) – Signal-to-Noise Ratio in decibel

  • rng (numpy.random.Genarator) – Random number generator instance

  • seed (int) – Random number generator seed

amps(*, size: Optional[int] = None)

Sample 3 modal amplitude values from a uniform distribution and normalize the sum

Parameters:

size (int) – Number of amplitude triplets to draw

Returns:

Random amplitude values

audio(dur: Optional[float] = None, fs: Optional[float] = 44100, *, size: Optional[int] = None)

Generate random audio with beats

Parameters:
  • dur (float) – Audio duration in seconds

  • fs (float) –

  • size (int) – Number of audio signals to generate

Returns:

Audio array, sample rate, and the tuple of frequency, decay, amplitude, and phase parameters

beta_twosides(a: float, b: float, left: float = 0, right: float = 1, positive: float = 0.5, *, size: Optional[int] = None, **kwargs)

Sample a value from a parametrized Beta distribution and randomly multiply it by either +1 or -1

Parameters:
  • a (float) –

  • b (float) –

  • left (float) – Minimum value for beta distibution

  • right (float) – Maximum value for beta distibution

  • positive (float) – Probability of multiplying by +1, instead of -1

  • size (int) – Number of samples to draw

  • kwargs – Keyword arguments for numpy.random.Genarator.beta()

Returns:

Random samples from the distribution

decays(*, size: Optional[int] = None)

Sample 3 modal decay values from an exponential distribution

Parameters:

size (int) – Number of decay triplets to draw

Returns:

Random decay values

freqs(*, size: Optional[int] = None)

Sample 3 modal frequency values

Parameters:

size (int) – Number of frequency triplets to draw

Returns:

Random frequency values

noise(nsamples: int, *, size: Optional[int] = None)

Sample white Gaussian noise

Parameters:
  • nsamples (int) – Number of noise samples to draw per realization

  • size (int) – Number of WGN realizations to draw

property noise_amp: float

Amplitude of noise component

property sine_amp: float

Amplitude of sinusoidal component

property snr_amp: float

Linear SNR