iconEuler Reference



Routines for sound.

Sound with Euler

Euler can generate sound with its matrix language. You need a time vector t to generate a sound, and then generate the sound with trigonometric functions or other functions. Sound can be played, saved or loaded in WAV format. Moreover, there some functions to analyzes sound via windowed FFT graphically.

function soundsec (n:number, rate=none)
  n seconds of parameter t with rate/sec ticks.
  >t=soundsec(2); playwave(sin(440*t));
playwave (Sounds),
savewave (Sounds)
function savewave (filename:string, v:real, rate=none,
    bits=16, normalize=true)
  Save a vector of sound data in WAV format.
  This functions saves a vector of sound amplitudes into a file.
  It returns the length of the sample in seconds, which does of
  course depend on the rate. For simple application, use the default
  rate with rate=none.
  rate : If not none, it determines the number of sound items per
  bits : should be 8 or 16
  normalize : prevents overload
  >t=soundsec(2); s=sin(440*t)*(4+sin(t^2/3));
  >file=eulerhome()+"test.wav"; savewave(file,s);
soundsec (Sounds),
playwave (Sounds),
loadwave (Sounds)
function loadwave (filename:string, saverate=true)
  Read a WAV file.
  This very raw function can read mono or stereo wav files with any
  sample rate. It can handle 8 or 16 bit per channel.
  Returns {w,rate}
  w : 1xn or 2xn (for stereo) sound.
  saverate : remember the rate as defaultsoundrate.
savewave (Sounds),
playwave (Sounds)
function analyzesound (w:real vector, fmin=10, fmax=1500,
    rate=none, points=2^16)
  Make a frequency plot of the signal w with sampling rate.
  The function makes an FFT of the first points of f, by default 2^16
  points. If there are less points, the program takes a power of 2,
  if the parameter points is not specified.
  fmin, fmax : range of frequencies to show in the plot
  spectral : use spectral colors instead of grays
mapsound (Sounds)
function mapsound (w:real vector, dt=0.1, fmin=100, fmax=1500,
    rate=none, spectral=true)
  Plots a sound map for a sound.
  It does an FFT at time increments dt. rate is the sampling rate.
  fmin, fmax : range of frequencies to show in the plot
  spectral : use spectral colors instead of grays
analyzesound (Sounds)
function overwrite playwave (s, rate=none, normalize=true)
  Plays either a file with name s, or a vector of sound s.
  This calls a built-in function playwave(file), which uses system
  routine to play the wave. The format is "*.wav" in stereo and 16
  rate : Sound rate. The default rate is 44100.
  normalize : Normalize the volume.
soundsec (Sounds)
function soundpulse (t) := sign(sin(t)); // Pulse sound
function soundsaw (t) := pi-mod(t,2*pi); // Saw wave sound
function soundtriangle (t) := 2*abs(pi-mod(t,2*pi))-pi; // Triangle wave sound

Documentation Homepage