Sunday, July 19, 2015

pd48. The keyup object in Pure Data

The keyup object sends the ASCII of the key which is pressed and then released, to its outlet.

The ASCII of '0' is 48, '1' is 49, and so on.

First press Reset to clear float. Then press 3 numbers, such as 7, 9, 2. They will be properly routed by the demux and incrementing index to the 3 number boxes. Any further input will not be recorded, unless Reset is pressed again.

pd47. The demux object in Pure Data

The demux object takes index of outlet from the right inlet. Then whatever data is sent to left inlet is then sent to proper outlet. Because the index has to be sent first (default will be 0), the bang is connected to index message first and then the list message. You can make clear the order, visually speaking, by using trigger object.

The data that is sent to outlet 0 or outlet 1 is a list of 2 numbers. Here, the number of outlets is 2 since that is the number of arguments.

It is unpacked and sent to number boxes.

Friday, July 17, 2015

pd46. Discrete Fourier Transform in Pure Data

For the audio signal of last example, the Discrete Fourier Transform (DFT) is found using rfft~.

The amplitude of the DFT for a blocksize of 1024 is found. The default block size is 64. The amplitude is shown on right channel. Here for each 1024 samples or (1024/44100 seconds), we have Fourier Amplitude of the block.

Even thought the DFT takes only a block, theoretically the block is treated as one period in infinite wave. The left and right boundaries of a block will be different in general. Thus there is a discontinuity as each new period begins, and this affects the Fourier coefficients for high-frequency terms. For realistic analysis, you should window the audio signal with a hamming window, etc. These windows will ensure the two boundaries are near 0 or identically 0. However, this will require overlapping of audio. For 1 minute audio with overlapping of 2, you will have to analyze two minutes.

The left channel shows the input audio signal, which is the same as last example. The right channel show the amplitude of different frequencies.

pd45. Phase Modulation in Pure Data

Frequency modulation is an example of phase modulation, and which we covered earlier.

An osc~ object is the same as phasor~ object connected to a cos~ object. The phasor~ provides the phase, 0 to 1 in Pure Data (corresponding 0 to 2 pi in the real world).

Here, we use a sqrt~ object to change the phase. This leads to audio with a large frequency bandwidth. With phase modulation, it is possible to get complicated sounds with only a few changes.

By looking at the audio waveform we can see the low-frequency parts (slowly changing) and high-frequency parts (changing quickly). We could confirm by plotting Spectrum from Analysis menu in Audacity.

pd44. The samphold~ object in Pure Data

The samphold~ object samples the left inlet audio signal whenever the control signal on right inlet is decreasing.

A toggle switch, operating at 10 ms, forces sampling whenever it is undergoing 1->0 transition, and the sampled audio will go to the left channel.

The audio signal is a sinusoidal at 5-Hz, too low to be heard by humans. The audio objects throw~ and catch~ are used so are our connections are cleaner. The thrown audio forms the right channel.

The audio waveform shows the effect of the samphold~:

Thursday, July 16, 2015

pd43. List split and append objects in Pure Data

We can use a list of numbers to provide timed control signals to an audio generator or synth. Here, the audio generator is just osc~, but in general it might be anything.

We have a list of frequencies and delays. The freq is 110 Hz for first 50 ms, 220 Hz for next 50 ms, 330 Hz for next 50 ms, and 440 for the last 50 ms of this 200-ms audio.

The bang sends the entire list, and after each delay the list is smaller by 2. The first outlet of list split 2 will have the first 2 values of list, second (middle) outlet will have the remaining list. This is fed into list append, which is triggered by the delay. Since you are appending an empty list with the remaining list, the new list is the remaining list, which is again fed into list split 2. This will continue until all numbers are used.

The audio signal shows increasing frequencies after every 50 milliseconds:

Wednesday, July 15, 2015

pd42. The wrap~ object in Pure Data

The wrap~ object keeps the fractional part of audio. If the signal is 1.5, it will be wrapped to 0.5. Without wrapping, it would be clipped off.

The input audio signal from osc~ is multiplied by 2 so it is a 2*cos signal. The signal is thus between -2 and +2. The two clip~ objects pass either the positive part of the signal or negative part of the signal.

Each of the signal is wrapped. The positive is immediately wrapped. For the negative, we first adjust the sign so it is again positive. The wrap is done and then it is multiplied by -1, yielding back a negative signal. Finally, the positive and negative signals are summed. This summation is implied since two audio signals are flowing to only one audio channel.

The final audio signal is shown here.