Previous Up Next

5.24.1  Creating audio clips : createwav

createwav takes the following arguments (all optional), in no particular order:

Additionally, passing the desired number of samples n as a single argument produces a single-channel clip on 16 bits/44100 Hz containing n samples initialized to zero.

Data matrix should contain the k-th sample in the j-th channel at position (j,k). The value of each sample must be a real number in range [−1.0,1.0]. Any value outside this interval is clamped to it (the resulting effect is called clipping). If the data is provided as a single list, it is copied across channels. If the number of samples or seconds is provided alongside the data list/matrix, the rows are truncated or padded with zeros to match the desired length.

If the option normalize is given, audio data is normalized to the specified level prior to conversion. This can be used to avoid clipping.

For example, input :

s:=createwav(duration=3.5):; playsnd(s)

Output :

three and a half seconds of silence at rate 44100

Input :

wave:=sin(2*pi*440*soundsec(2)):;
s:=createwav(channel_data=wave,samplerate=48000):;
playsnd(s)

Output :

two seconds of the 440 Hz sine wave at rate 48000

Input :

t:=soundsec(3):;
L,R:=sin(2*pi*440*t),sin(2*pi*445*t):;
s:=createwav([L,R]):; playsnd(s)

Output :

3 secs of a vibrato effect on a sine wave (stereo)

Previous Up Next