Previous Up Next

28.2.9  Setting samples in audio clips

The set_channel_data command sets the audio clip samples to desired values.

Example

In the following example we create an audio clip containing the sine wave and add random noise to its portion.

snd:=createwav(sin(2*pi*440*soundsec(4)))
     
a sound clip with 176400 samples at 44100 Hz (16 bit, mono           

We extract the data after the first and before the third second of the audio.

data:=channel_data(snd,0,range=1.0..3.0):;

Now we create the noise which fades in and out.

noise:=hamming_window(ranv(length(data),normald(0,0.1))):;

Finally we replace the portion of the original clip with the mix of the sine wave and noise.

snd1:=set_channel_data(snd,noise+data,44100,0)
     
a sound clip with 176400 samples at 44100 Hz (16 bit, mono)           

Previous Up Next