clip — Clips a signal to a predefined limit.
Clips an a-rate signal to a predefined limit, in a “soft” manner, using one of three methods.
imeth -- selects the clipping method. The default is 0. The methods are:
0 = Bram de Jong method (default)
1 = sine clipping
2 = tanh clipping
ilimit -- limiting value
iarg (optional, default=0.5) -- when imeth = 0, indicates the point at which clipping starts, in the range 0 - 1. Not used when imeth = 1 or imeth = 2. Default is 0.5.
asig -- a-rate input signal
The Bram de Jong method (imeth = 0) applies the algorithm:
|x| > a: f(x) = sin(x) * (a+(x-a)/(1+((x-a)/(1-a))2 |x| > 1: f(x) = sin(x) * (a+1)/2
This method requires that asig be normalized to 1.
The second method (imeth = 1) is the sine clip:
|x| < limit: f(x) = limit * sin(π*x/(2*limit)) f(x) = limit * sin(x)
The third method (imeth = 3) is the tanh clip:
|x| < limit: f(x) = limit * tanh(x/limit)/tanh(1) f(x) = limit * sin(x)
Note | |
---|---|
Method 1 appears to be non-functional at release of Csound version 4.07. |
Here is an example of the clip opcode. It uses the file clip.csd.
Example 72. Example of the clip opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform ; Audio out Audio in No messages -odac -iadc -d ;;;RT audio I/O ; For Non-realtime ouput leave only the line below: ; -o clip.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> ; Initialize the global variables. sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 ; Instrument #1. instr 1 ; Generate a noisy waveform. arnd rand 44100 ; Clip the noisy waveform's amplitude to 20,000 a1 clip arnd, 2, 20000 out a1 endin </CsInstruments> <CsScore> ; Play Instrument #1 for one second. i 1 0 1 e </CsScore> </CsoundSynthesizer>