Routines for sound.

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.

functionsoundsec(n:number, rate=none)

n seconds of parameter t with rate/sec ticks. >t=soundsec(2); playwave(sin(440*t)); See:

playwave (Sounds),

savewave (Sounds)

functionsavewave(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 second. 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); >playwave(file); See:

soundsec (Sounds),

playwave (Sounds),

loadwave (Sounds)

functionloadwave(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. See:

savewave (Sounds),

playwave (Sounds)

functionanalyzesound(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 Example: >t=soundsec(0.8); >s=soundpulse(440*t); >analyzesound(s,1,4000): See:

mapsound (Sounds)

functionmapsound(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 Example: >t=440*soundsec(1); >s=soundpulse(t)|soundsaw(t)|soundtriangle(t); >mapsound(s,0.1,1,2400): See:

analyzesound (Sounds)

functionoverwrite 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 bit. rate : Sound rate. The default rate is 44100. normalize : Normalize the volume. See:

soundsec (Sounds)

functionsoundpulse(t) := sign(sin(t)); // Pulse sound

functionsoundsaw(t) := pi-mod(t,2*pi); // Saw wave sound

functionsoundtriangle(t) := 2*abs(pi-mod(t,2*pi))-pi; // Triangle wave sound