Signals Guide - Quefumas/gensound GitHub Wiki
Here we cover the most basic Signals that are available in Gensound. Read here how to define your own Signals.
Oscillators
Mathematically-produced waveforms that have a distinct fundamental frequency. These are the main building blocks of much of audio synthesis, and their implementations share several features.
The four main kinds are Sine, Triangle, Square, Sawtooth
.
This chart from Wikipedia gives a visual demonstration of these four kinds.
They all have the same arguments:
frequency
- a number, representing Hz; or a string indicating a note name or even entire melodic sequenceduration
- behaves differently according to type (int
`float`; see syntax guide)phase
- starting phase of the oscillator; any real number (by convention between 0 and2*Pi
), orNone
(see below)
Typically, only the first two arguments are needed, though these have default values (220 Hz
and 5e3
), mainly for speedy testing.
The
phase
argument defaults toNone
, which activates phase inference, a feature enabling seamless concatenation ofOscillator
s, such that the ending phase of the first carries into the starting phase of the next. This is automatically activated any time two Oscillators are concatenated directly to one another (though the actual circumstances are slightly more involved), and this also happens whenever we generate a melodic sequence using the shorthand notation. In the same situation, settingphase
to a number (instead ofNone
) will force each Signal in the sequence to start from the specified initial phase, regardless of the previous Signal.
Raw Audio
WAV
The WAV
Signal is used for all audio loaded from files (not necessarily wave files). Use it with the syntax: WAV(filename)
.
Gensound version 0.4 supports loading files of formats wav,wave,aiff,aif,aifc
, some particular encodings may not work. In the future, more formats will be supported.
WAV
objects, in general, don't care about the sample rate of the loaded audio: if they are played or exported using a different sample rate, they will not warn the user or attempt conversion. This means that in such cases the pitch content of the audio and its duration will be affected. If you wish to resample the audio, call WAV.resample(sample_rate)
function, which converts the loaded audio to the desired rate.
WAV
audio is cached; this means that each file will be loaded only once, even if it is used in multipleWAV
objects. Furthermore, this means that ifresample
is called for any of the objects using the same filename, all of them will be resampled. If you want to play the same audio in multiple rates at the same time, use theStretch
Transform instead.
Raw
The class Raw(audio)
is similar to WAV
, except that it does not expect to receive audio from a file, but rather audio obtained from a previously defined Signal instance.
Usage example: Raw(someSignal.realise(sample_rate))
. This generates actual audio from the previously defined Signal someSignal
with the given sample rate, and treats this raw audio as a new Signal.
This is more of a helper class, which can be used for incremental realisation of the audio. Since Gensound only evaluates the Signals when attempting to playback or export, this class can be used to force earlier evaluation for parts of the Signal, which could reduce the computation workload for complex signals with CPU-heavy transforms.
Others
-
Silence(duration)
- an empty Signal with the specified duration. However, if you wish to append silence to an existing signal, the preferred way is using the syntaxSignal | number
, which appends silence of durationnumber
(in ints or floats, as usual). This can also be used in the opposite order to add silence to the beginning. Yet another way is to use theExtend
transform. -
WhiteNoise(duration)
- generates white noise with the desired duration. Currently this is implemented as generating a suitable number of floating-point samples in the range of[-1,1]
.
TODO
Step
Wavetables, pulse
Mix, Sequence
probably don't belong here; user shouldn't touch them.