### 28.2.1 Creating audio clips

The createwav command creates an audio object with specified parameters.

- createwav takes its arguments as key=value pairs, in no particular order. The following arguments are all optional:
  - size=n resp. duration=T, where n resp. T is the total number of samples resp. the length in seconds.
  - bit_depth=b, where b is the number of bits reserved for each sample value and may be 8, 16 or 24 (by default 16).
  - samplerate=r, where r is the number of samples per second (by default 44100).
  - channels=c where c is the number of channels (by default 1).
  - D or channel_data=D, where D is a list or a matrix.

    If D is a matrix, it should contain the kth sample in the jth 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 (this effect is called clipping and it will distort the signal).

    If D is a single list, it is copied across channels.

    D may be truncated or padded with zeros to match the appropriate number of samples or seconds.

  - normalize=db, where db≤ 0 is a real number representing the amplitude peak level in dB FS (decibel “full scale”) units. If this option is given, audio data is normalized to the specified level prior to conversion. This can be used to avoid clipping. By default, the resulting audio is normalized to the −1 dB level.
- createwav(⟨keys=values⟩) returns an audio object with the requested parameters.
- If no sound data is provided, the resulting audio will be silent (all samples will be initialized to 0).

#### Examples

(See Section 28.2.14 for a description of playsnd and Section 28.2.7 for a description of soundsec.)

playsnd(createwav(channel_data=sin(2*pi*440*soundsec(2)),samplerate=48000))

Output: Two seconds of the 440 Hz sine wave at rate 48000.

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

Output: Three seconds of a vibrato effect on a sine wave (stereo).