FLOSS Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

CSOUND Español

Csound: FOURIERSPECTRAL

FOURIER TRANSFORMATION / SPECTRAL PROCESSING

TRANSFORMACIÓN DE FOURIER / PROCESAMIENTO ESPECTRAL

 

A Fourier Transformation (FT) is used to transfer an audio-signal from the time-domain to the frequency-domain. This can, for instance, be used to analyze and visualize the spectrum of the signal appearing in a certain time span. Fourier transform and subsequent manipulations in the frequency domain open a wide area of interesting sound transformations, like time stretching, pitch shifting and much more.

Una Transformación de Fourier (FT) se utiliza para transferir una señal de audio del dominio del tiempo al dominio de la frecuencia. Esto puede utilizarse, por ejemplo, para analizar y visualizar el espectro de la señal que aparece en un cierto intervalo de tiempo. La transformada de Fourier y las manipulaciones posteriores en el dominio de la frecuencia abren una amplia área de transformaciones sonoras interesantes, como el estiramiento de tiempo, el cambio de tono y mucho más.

How does it work? ¿Como funciona?

The mathematician J.B. Fourier (1768-1830) developed a method to approximate periodic functions by using sums of trigonometric functions. The advantage of this was that the properties of the trigonometric functions (sin & cos) were well-known and helped to describe the properties of the unknown function.

El matemático J.B. Fourier (1768-1830) desarrolló un método para aproximar funciones periódicas usando sumas de funciones trigonométricas. La ventaja de esto era que las propiedades de las funciones trigonométricas (sin & cos) eran bien conocidas y ayudaron a describir las propiedades de las función desconocida.

In audio DSP, a fourier transformed signal is decomposed into its sum of sinoids. Put simply, Fourier transform is the opposite of additive synthesis. Ideally, a sound can be dissected by Fourier transformation into its partial components, and resynthesized again by adding these components back together again.

En DSP de audio, una señal transformada de Fourier se descompone en su suma de elementos sintéticos. En pocas palabras, la transformada de Fourier es lo opuesto a la síntesis aditiva. Idealmente, un sonido puede ser disecado por la transformación de Fourier en sus componentes parciales, y resynthesized otra vez agregando estos componentes detrás juntos otra vez.

On account of the fact that sound is represented as discrete samples in the computer, the computer implementation of the FT calculates a discrete Fourier transform (DFT). As each transformation needs a certain number of samples, one key decision in performing DFT is about the number of samples used. The analysis of the frequency components will be more accurate if more samples are used, but as samples represent a progression of time, a caveat must be found for each FT between either better time resolution (fewer samples) or better frequency resolution (more samples). A typical value for FT in music is to have about 20-100 "snapshots" per second (which can be compared to the single frames in a film or video).

Debido al hecho de que el sonido se representa como muestras discretas en el ordenador, la implementación informática del FT calcula una transformada discreta de Fourier (DFT). Como cada transformación necesita un cierto número de muestras, una decisión clave en la realización de DFT es sobre el número de muestras utilizadas. El análisis de los componentes de la frecuencia será más preciso si se utilizan más muestras, pero como las muestras representan una progresión de tiempo, se debe encontrar una advertencia para cada FT entre mejor resolución temporal (menos muestras) o mejor resolución de frecuencia (más muestras) . Un valor típico para FT en música es tener alrededor de 20-100 instantáneas por segundo (que se puede comparar con los fotogramas individuales en una película o video).

At a sample rate of 48000 samples per second, these are about 500-2500 samples for one frame or window. It is normal in DFT in computer music to use window sizes which are a power-of-two in size, such as 512, 1024 or 2048 samples. The reason for this restriction is that DFT for these power-of-two sized frames can be calculated much faster. This is called Fast Fourier Transform (FFT), and this is the standard implementation of the Fourier transform in audio applications.

A una tasa de muestreo de 48000 muestras por segundo, estas son aproximadamente 500-2500 muestras para un marco o ventana. Es normal en DFT en la música de computadora para utilizar tamaños de ventana que son un poder de dos en tamaño, como 512, 1024 o 2048 muestras. La razón de esta restricción es que DFT para estos cuadros de tamaño de dos de potencia se puede calcular mucho más rápido. Esto se denomina Transformada Rápida de Fourier (FFT), y esta es la implementación estándar de la Transformada de Fourier en aplicaciones de audio.

How is FFT done in Csound?

¿Cómo se hace FFT en Csound?

As usual, there is not just one way to work with FFT and spectral processing in Csound. There are several families of opcodes. Each family can be very useful for a specific approach to working in the frequency domain. Have a look at the "Spectral Processing" overview in the Csound Manual. This introduction will focus on the so-called "Phase Vocoder Streaming" opcodes. All of these opcodes begin with the characters "pvs". These opcodes became part of Csound through the work of Richard Dobson, Victor Lazzarini and others. They are designed to work in realtime in the frequency domain in Csound and indeed they are not just very fast but also easier to use than FFT implementations in many other applications.

Como de costumbre, no hay una sola manera de trabajar con FFT y procesamiento espectral en Csound. Hay varias familias de opcodes. Cada familia puede ser muy útil para un enfoque específico para trabajar en el dominio de la frecuencia. Echa un vistazo a la descripción general del procesamiento espectral en el manual Csound. Esta introducción se centrará en el llamado Phase Vocoder Streaming opcodes. Todos estos opcodes comienzan con los caracteres pvs. Estos opcodes se convirtieron en parte de Csound a través de la obra de Richard Dobson, Victor Lazzarini y otros. Están diseñados para trabajar en tiempo real en el dominio de la frecuencia en Csound y de hecho no son muy rápidos sino también más fáciles de usar que las implementaciones FFT en muchas otras aplicaciones.

Changing from Time-domain to Frequency-domain

Cambiar de dominio de tiempo a dominio de frecuencia

For dealing with signals in the frequency domain, the pvs opcodes implement a new signal type, the f-signals. Csound shows the type of a variable in the first letter of its name. Each audio signal starts with an a, each control signal with a k, and so each signal in the frequency domain used by the pvs-opcodes starts with an f.

Para tratar las señales en el dominio de frecuencia, los opcodes pvs implementan un nuevo tipo de señal, las señales f. Csound muestra el tipo de una variable en la primera letra de su nombre. Cada señal de audio comienza con una a, cada señal de control con un k, y por lo tanto cada señal en el dominio de frecuencia usado por los pvs-opcodes comienza con un f.

There are several ways to create an f-signal. The most common way is to convert an audio signal to a frequency signal. The first example covers two typical situations:

Hay varias formas de crear una señal f. La forma más común es convertir una señal de audio en una señal de frecuencia. El primer ejemplo cubre dos situaciones típicas:

the audio signal derives from playing back a soundfile from the hard disc (instr 1)

La señal de audio deriva de reproducir un archivo de sonido del disco duro (instr 1)

the audio signal is the live input (instr 2)

La señal de audio es la entrada en directo (instr 2)

(Caution - this example can quickly start feeding back. Best results are with headphones.)

(Precaución: este ejemplo puede comenzar rápidamente a retroalimentarse. Los mejores resultados son con los auriculares.)

EXAMPLE 05I01_pvsanal.csd 1 

<CsoundSynthesizer>
<CsOptions>
-i adc -o dac
</CsOptions>
<CsInstruments>
;Example by Joachim Heintz
;uses the file "fox.wav" (distributed with the Csound Manual)
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

;general values for fourier transform
gifftsiz  =         1024
gioverlap =         256
giwintyp  =         1 ;von hann window

instr 1 ;soundfile to fsig
asig      soundin   "fox.wav"
fsig      pvsanal   asig, gifftsiz, gioverlap, gifftsiz*2, giwintyp
aback     pvsynth   fsig
          outs      aback, aback
endin

instr 2 ;live input to fsig
          prints    "LIVE INPUT NOW!%n"
ain       inch      1 ;live input from channel 1
fsig      pvsanal   ain, gifftsiz, gioverlap, gifftsiz, giwintyp
alisten   pvsynth   fsig
          outs      alisten, alisten
endin

</CsInstruments>
<CsScore>
i 1 0 3
i 2 3 10
</CsScore>
</CsoundSynthesizer> 

You should hear first the "fox.wav" sample, and then the slightly delayed live input signal. The delay (or latency) that you will observe will depend first of all on the general settings for realtime input (ksmps, -b and -B: see chapter 2D), but it will also be added to by the FFT process. The window size here is 1024 samples, so the additional delay is 1024/44100 = 0.023 seconds. If you change the window size gifftsiz to 2048 or to 512 samples, you should notice a larger or shorter delay. For realtime applications, the decision about the FFT size is not only a question of better time resolution versus better frequency resolution, but it will also be a question concerning tolerable latency.

Deberá oír primero la muestra fox.wav y, a continuación, la señal de entrada viva ligeramente retrasada. El retardo (o latencia) que observará dependerá en primer lugar de los ajustes generales para la entrada en tiempo real (ksmps, -b y -B: véase el capítulo 2D), pero también se añadirá mediante el proceso FFT. El tamaño de la ventana aquí es de 1024 muestras, por lo que el retraso adicional es 1024/44100 = 0.023 segundos. Si cambia el tamaño de la ventana gifftsiz a 2048 oa 512 muestras, debe notar un retraso mayor o menor. Para las aplicaciones en tiempo real, la decisión sobre el tamaño de la FFT no es sólo una cuestión de mejor resolución temporal frente a una mejor resolución de frecuencia, sino que también será una cuestión relacionada con la latencia tolerable.

What happens in the example above? Firstly, the audio signal (asig, ain) is being analyzed and transformed to an f-signal. This is done via the opcode pvsanal. Then nothing more happens than the f-signal being transformed from the frequency domain signal back into the time domain (an audio signal). This is called inverse Fourier transformation (IFT or IFFT) and is carried out by the opcode pvsynth.2 In this case, it is just a test: to see if everything works, to hear the results of different window sizes and to check the latency, but potentially you can insert any other pvs opcode(s) in between this analysis and resynthesis:

¿Qué sucede en el ejemplo anterior? En primer lugar, la señal de audio (asig, ain) está siendo analizada y transformada en una señal f. Esto se hace a través del opcode pvsanal. Entonces no sucede nada más que la señal f que se transforma de la señal de dominio de frecuencia de nuevo en el dominio del tiempo (una señal de audio). Esto se denomina transformación inversa de Fourier (IFT o IFFT) y se lleva a cabo por el opcode pvsynth.2 En este caso, es sólo una prueba: para ver si todo funciona, para escuchar los resultados de diferentes tamaños de ventana y para comprobar la latencia , Pero potencialmente puede insertar cualquier otro código de operaciones de pvs entre este análisis y la resíntesis:


 

 

Pitch shifting Cambio de tono

Simple pitch shifting can be carried out by the opcode pvscale. All the frequency data in the f-signal are scaled by a certain value. Multiplying by 2 results in transposing by an octave upwards; multiplying by 0.5 in transposing by an octave downwards. For accepting cent values instead of ratios as input, the cent opcode can be used.

El cambio de tono simple puede realizarse mediante el opcode pvscale. Todos los datos de frecuencia en la señal f son escalados por un cierto valor. Multiplicar por 2 resultados en la transposición de una octava hacia arriba; Multiplicando por 0,5 en la transposición por una octava hacia abajo. Para aceptar valores de centavos en lugar de proporciones como entrada, se puede usar el código de operación de centavo.

EXAMPLE 05I02_pvscale.csd

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
;example by joachim heintz
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

gifftsize =         1024
gioverlap =         gifftsize / 4
giwinsize =         gifftsize
giwinshape =        1; von-Hann window

instr 1 ;scaling by a factor
ain       soundin  "fox.wav"
fftin     pvsanal  ain, gifftsize, gioverlap, giwinsize, giwinshape
fftscal   pvscale  fftin, p4
aout      pvsynth  fftscal
          out      aout
endin

instr 2 ;scaling by a cent value
ain       soundin  "fox.wav"
fftin     pvsanal  ain, gifftsize, gioverlap, giwinsize, giwinshape
fftscal   pvscale  fftin, cent(p4)
aout      pvsynth  fftscal
          out      aout/3
endin

</CsInstruments>
<CsScore>
i 1 0 3 1; original pitch
i 1 3 3 .5; octave lower
i 1 6 3 2 ;octave higher
i 2 9 3 0
i 2 9 3 400 ;major third
i 2 9 3 700 ;fifth
e
</CsScore>
</CsoundSynthesizer>

Pitch shifting via FFT resynthesis is very simple in general, but rather more complicated in detail. With speech for instance, there is a problem because of the formants. If you simply scale the frequencies, the formants are shifted, too, and the sound gets the typical 'helium voice' effect. There are some parameters in the pvscale opcode, and some other pvs-opcodes which can help to avoid this, but the quality of the results will always depend to an extend upon the nature of the input sound.

El cambio de tono mediante resíntesis FFT es muy simple en general, pero más complicado en detalle. Con el habla, por ejemplo, hay un problema debido a los formantes. Si simplemente escala las frecuencias, los formantes se desplazan, también, y el sonido obtiene el típico efecto de voz de helio. Hay algunos parámetros en el opcode pvscale, y algunos otros pvs-opcodes que pueden ayudar a evitar esto, pero la calidad de los resultados siempre dependerá de una extensión sobre la naturaleza del sonido de entrada.

Time-stretch/compress

Tiempo-estirar / comprimir

As the Fourier transformation separates the spectral information from its progression in time, both elements can be varied independently. Pitch shifting via the pvscale opcode, as in the previous example, is independent of the speed of reading the audio data. The complement is changing the time without changing the pitch: time-stretching or time-compression.

Como la transformación de Fourier separa la información espectral de su progresión en el tiempo, ambos elementos se pueden variar independientemente. El cambio de tono a través del código de operación pvscale, como en el ejemplo anterior, es independiente de la velocidad de lectura de los datos de audio. El complemento está cambiando el tiempo sin cambiar el tono: tiempo de estiramiento o compresión de tiempo.

The simplest way to alter the speed of a sampled sound is using pvstanal (new in Csound 5.13). This opcode transforms a sound stored in a function table (transformation to an f-signal is carried out internally by the opcode) with time manipulations simply being done by altering its ktimescal parameter.

La manera más simple de alterar la velocidad de un sonido muestreado es utilizando pvstanal (nuevo en Csound 5.13). Este código de operación transforma un sonido almacenado en una tabla de funciones (la transformación en una señal f es llevada a cabo internamente por el código de operación) con manipulaciones de tiempo simplemente haciéndose alterando su parámetro ktimescal.

EXAMPLE 05I03_pvstanal.csd

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
;example by joachim heintz
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

;store the sample "fox.wav" in a function table (buffer)
gifil     ftgen     0, 0, 0, 1, "fox.wav", 0, 0, 1

;general values for the pvstanal opcode
giamp     =         1 ;amplitude scaling
gipitch   =         1 ;pitch scaling
gidet     =         0 ;onset detection
giwrap    =         0 ;no loop reading
giskip    =         0 ;start at the beginning
gifftsiz  =         1024 ;fft size
giovlp    =         gifftsiz/8 ;overlap size
githresh  =         0 ;threshold

instr 1 ;simple time stretching / compressing
fsig      pvstanal  p4, giamp, gipitch, gifil, gidet, giwrap, giskip,
                    gifftsiz, giovlp, githresh
aout      pvsynth   fsig
          out       aout
endin

instr 2 ;automatic scratching
kspeed    randi     2, 2, 2 ;speed randomly between -2 and 2
kpitch    randi     p4, 2, 2 ;pitch between 2 octaves lower or higher
fsig      pvstanal  kspeed, 1, octave(kpitch), gifil
aout      pvsynth   fsig
aenv      linen     aout, .003, p3, .1
          out       aenv
endin

</CsInstruments>
<CsScore>
;         speed
i 1 0 3   1
i . + 10   .33
i . + 2   3
s
i 2 0 10 0;random scratching without ...
i . 11 10 2 ;... and with pitch changes
</CsScore>
</CsoundSynthesizer>

 

Cross Synthesis

Síntesis cruzada

Working in the frequency domain makes it possible to combine or 'cross' the spectra of two sounds. As the Fourier transform of an analysis frame results in a frequency and an amplitude value for each frequency 'bin', there are many different ways of performing cross synthesis. The most common methods are:

Trabajar en el dominio de la frecuencia hace posible combinar o cruzar el espectro de dos sonidos. Como la transformada de Fourier de una trama de análisis da como resultado una frecuencia y un valor de amplitud para cada bandeja de frecuencia, existen muchas maneras diferentes de realizar síntesis cruzada. Los métodos más comunes son:

Combine the amplitudes of sound A with the frequencies of sound B. This is the classical phase vocoder approach. If the frequencies are not completely from sound B, but represent an interpolation between A and B, the cross synthesis is more flexible and adjustable. This is what pvsvoc does.

Combine las amplitudes del sonido A con las frecuencias del sonido B. Este es el enfoque clásico del vocoder de fase. Si las frecuencias no son completamente del sonido B, sino que representan una interpolación entre A y B, la síntesis cruzada es más flexible y ajustable. Esto es lo que hace pvsvoc.

Combine the frequencies of sound A with the amplitudes of sound B. Give user flexibility by scaling the amplitudes between A and B: pvscross.

Combinar las frecuencias del sonido A con las amplitudes del sonido B. Dar flexibilidad al usuario escalando las amplitudes entre A y B: pvscross.

Get the frequencies from sound A. Multiply the amplitudes of A and B. This can be described as spectral filtering. pvsfilter gives a flexible portion of this filtering effect.

Obtenga las frecuencias del sonido A. Multiplique las amplitudes de A y B. Esto se puede describir como filtrado espectral. Pvsfilter proporciona una parte flexible de este efecto de filtrado.

This is an example of phase vocoding. It is nice to have speech as sound A, and a rich sound, like classical music, as sound B. Here the "fox" sample is being played at half speed and 'sings' through the music of sound B:

Este es un ejemplo de vocoder de fase. Es agradable tener el habla como sonido A, y un sonido rico, como música clásica, como sonido B. Aquí la muestra del zorro se está jugando a media velocidad y canta a través de la música del sonido B:

EXAMPLE 05I04_phase_vocoder.csd

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
;example by joachim heintz
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

;store the samples in function tables (buffers)
gifilA    ftgen     0, 0, 0, 1, "fox.wav", 0, 0, 1
gifilB    ftgen     0, 0, 0, 1, "ClassGuit.wav", 0, 0, 1


;general values for the pvstanal opcode
giamp     =         1 ;amplitude scaling
gipitch   =         1 ;pitch scaling
gidet     =         0 ;onset detection
giwrap    =         1 ;loop reading
giskip    =         0 ;start at the beginning
gifftsiz  =         1024 ;fft size
giovlp    =         gifftsiz/8 ;overlap size
githresh  =         0 ;threshold

instr 1
;read "fox.wav" in half speed and cross with classical guitar sample
fsigA     pvstanal  .5, giamp, gipitch, gifilA, gidet, giwrap, giskip,\
                     gifftsiz, giovlp, githresh
fsigB     pvstanal  1, giamp, gipitch, gifilB, gidet, giwrap, giskip,\
                     gifftsiz, giovlp, githresh
fvoc      pvsvoc    fsigA, fsigB, 1, 1	
aout      pvsynth   fvoc
aenv      linen     aout, .1, p3, .5
          out       aenv
endin

</CsInstruments>
<CsScore>
i 1 0 11
</CsScore>
</CsoundSynthesizer>

 

The next example introduces pvscross:

El siguiente ejemplo introduce pvscross:

EXAMPLE 05I05_pvscross.csd

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
;example by joachim heintz
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

;store the samples in function tables (buffers)
gifilA    ftgen     0, 0, 0, 1, "BratscheMono.wav", 0, 0, 1
gifilB    ftgen     0, 0, 0, 1, "fox.wav", 0, 0, 1

;general values for the pvstanal opcode
giamp     =         1 ;amplitude scaling
gipitch   =         1 ;pitch scaling
gidet     =         0 ;onset detection
giwrap    =         1 ;loop reading
giskip    =         0 ;start at the beginning
gifftsiz  =         1024 ;fft size
giovlp    =         gifftsiz/8 ;overlap size
githresh  =         0 ;threshold

instr 1
;cross viola with "fox.wav" in half speed
fsigA     pvstanal  1, giamp, gipitch, gifilA, gidet, giwrap, giskip,\
                    gifftsiz, giovlp, githresh
fsigB     pvstanal  .5, giamp, gipitch, gifilB, gidet, giwrap, giskip,\
                     gifftsiz, giovlp, githresh
fcross    pvscross  fsigA, fsigB, 0, 1	
aout      pvsynth   fcross
aenv      linen     aout, .1, p3, .5
          out       aenv
endin

</CsInstruments>
<CsScore>
i 1 0 11
</CsScore>
</CsoundSynthesizer>

The last example shows spectral filtering via pvsfilter. The well-known "fox" (sound A) is now filtered by the viola (sound B). Its resulting intensity is dependent upon the amplitudes of sound B, and if the amplitudes are strong enough, you will hear a resonating effect:

El último ejemplo muestra el filtrado espectral a través de pvsfilter. El conocido zorro (sonido A) es ahora filtrado por la viola (sonido B). Su intensidad resultante depende de las amplitudes del sonido B, y si las amplitudes son lo suficientemente fuertes, se oirá un efecto de resonancia:

EXAMPLE 05I06_pvsfilter.csd

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>
;example by joachim heintz
sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

;store the samples in function tables (buffers)
gifilA    ftgen     0, 0, 0, 1, "fox.wav", 0, 0, 1
gifilB    ftgen     0, 0, 0, 1, "BratscheMono.wav", 0, 0, 1

;general values for the pvstanal opcode
giamp     =         1 ;amplitude scaling
gipitch   =         1 ;pitch scaling
gidet     =         0 ;onset detection
giwrap    =         1 ;loop reading
giskip    =         0 ;start at the beginning
gifftsiz  =         1024 ;fft size
giovlp    =         gifftsiz/4 ;overlap size
githresh  =         0 ;threshold

instr 1
;filters "fox.wav" (half speed) by the spectrum of the viola (double speed)
fsigA     pvstanal  .5, giamp, gipitch, gifilA, gidet, giwrap, giskip,\
                     gifftsiz, giovlp, githresh
fsigB     pvstanal  2, 5, gipitch, gifilB, gidet, giwrap, giskip,\
                     gifftsiz, giovlp, githresh
ffilt     pvsfilter fsigA, fsigB, 1    
aout      pvsynth   ffilt
aenv      linen     aout, .1, p3, .5
          out       aenv
endin

</CsInstruments>
<CsScore>
i 1 0 11
</CsScore>
</CsoundSynthesizer>

There are many more tools and opcodes for transforming FFT signals in Csound. Have a look at the Signal Processing II section of the Opcodes Overview for some hints.

Hay muchas más herramientas y opcodes para transformar señales FFT en Csound. Eche un vistazo a la sección Signal Processing II de la Opcodes Overview para algunas sugerencias.

 

All soundfiles used in this manual are free and can be downloaded at www.csound-tutorial.net^

  1. In some cases it might be interesting to use pvsadsyn instead of pvsynth. It employs a bank of oscillators for resynthesis, the details of which can be controlled by the user.^

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.