Ubuntu: soundin Opcode Causes Segmentation Fault

In my last post, Seven Things I Learned About FM Synthesis, I mentioned I would be trying to use one audio signal to modulate another. This activity came to an abrupt halt when, upon rendering my experimental orchestra on this Ubuntu box, I received the error message:Csound tidy up: Segmentation fault
Fortunately, this was a previously reported, documented bug. The comments on the bug record suggested users build from source which, I did with a little trouble.
I had to edit ./Opcodes/dssi4cs/src/dssi.h and change the line
#include <alsa/seq_event.h>

#include "seq_event.h"

Maybe I’m missing some piece of the puzzle but, It seems to work find so far and, I was quite pleased that I was actually able to fix a c++ build problem – I haven’t compiled a non trivial c++ program in about 8 years!

The other step I needed to do, (as did others), is to copy a script like this: cp custom.py custom.py.mkg (For now, I don’t plan to install my build of CSound.)

At any rate, here are some of the experiments. The idea was to use a swept sine wave in each channel as the “carrier” and then, modulate that using an audio signal. I like the A and B experiments most. Experiment C is an attempt to reduce what I thought was massive clipping and aliasing of the other two experiments.

Audio Modulator Experiment A

Audio Modulator Experiment B

Audio Modulator Experiment C

Seven Things I’ve Learned About FM Synthesis

I’ve played around with CSound’s foscil opcode before but, I wasn’t satisfied I really understood what was going on. This article summarizes my learning of Frequency Modulation (FM) synthesis in seven key ideas.

A PDF version of Seven Things I’ve Learned About FM Synthesis that includes some math is available. I hope it can serve as a gentle introduction for others.

  1. We can think of frequency as a function of time rather than a constant. It can be helpful to describe instantaneous frequency as a sum of a fixed carrier frequency and a scaled modulating function.
  2. Simple FM has a modulating function that is a fixed frequency sinusoidal signal.
  3. The modulation index indicates, as you might guess, the degree of modulation. For simple FM, the index is the ratio of the frequency deviation, to the modulation frequency.
  4. Frequency Modulation is essentially the same thing as Phase Modulation (PM). Well, that’s an overstatement. They are not interchangeable. For example a radio receiver built to decode phase modulated signals, will not be able to decode a signal from an FM transmitter. But, for synthesis purposes we are interested in the modulated signal, rather than the modulating signal. In this case, we can achieve the same effects with PM that we can with FM, provided the modulating signal is sinusoidal.
  5. The effect of simple frequency modulation is the addition of sidebands that are centered at the carrier frequency and spaced at multiples of the modulating frequency. There are theoretically an infinite number of sidebands. But almost all of the power of the resulting spectrum is contained in the first (modulationIndex + 1 ) sidebands. This means when the modulation index is elevated, the power will be spread out to a larger number of sideband frequencies.
    Care must be taken to insure that the frequency of the sidebands do not exceed the Nyquist criteria unless aliasing is a desired effect.
    When the ratio of the modulation to carrier frequency is rational, sidebands belong to a harmonic series. If the ratio is irrational, the sound is metallic or possibly noisy at high levels of modulation index.
  6. CSound’s foscil opcode implements simple FM. Its parameters are:
    1. xamp: amplitude
    2. kcps: carrier frequency
    3. kcarfac: carrier frequency divided by kcps. (Hence I often use 1)
    4. kmodfac: modulation frequency divided by kcps
    5. kindex: the modulation index
    6. ifn: function table number, should be a sine for simple FM
    7. iphase: (optional) initial phase into lookup table
  7. Simple FM can be extended by:
    • Modulating the modulation function (cascade) to create additional sidebands
    • Feedback (self modulation)
    • Summing multiple sinusoidal modulators (Parallel modulators)
    • Non sinusoidal carriers and/or modulators: noise, audio, etc…

    While some of these algorithms are available in commercial synthesizers, all of them provide the FM synthesis student inspiration for further study and experimentation.

After some basic exploration of foscil, I have begun my own experiments with some simple CSound instruments that modulate a sine wave with an audio signal. Its a very interesting effect. When I get a decent example. I’ll post here and maybe at the bigwinky page on the freesound project.


Benson, Dave. Music: a Mathematical Offering. Cambridge: Cambridge UP, 2007. Music: a Mathematical Offering. 9 Mar. 2008 <http://www.maths.abdn.ac.uk/~bensondj/html/music.pdf>.

Lesurf, Jim. “Frequency Modulation, Phase Modulation, and FM Spectra.” Scot’s Guide to Electronics. 15 June 2005. University of St. Andrews. 5 Mar. 2008 <http://www.st-andrews.ac.uk/~jcgl/Scots_Guide/RadCom/part12/page1.html>.

Pinkston, Russell. “FM Synthesis in CSound.” The CSound Book. Ed. Richard Boulanger. Cambridge, Massachusetts: The MIT P, 2000. 261-270.

Reid, Gordon. “Synth Secrets.” Sound on Sound. Apr. 2000. 9 Mar. 2008 <http://www.soundonsound.com/sos/apr00/articles/synthsecrets.htm>.

Schottstaedt, Bill. “An Introduction to FM.” CCRMA. 11 Feb. 2008. Stanford University. 7 Mar. 2008 <http://ccrma.stanford.edu/software/snd/snd/fm.html>.

Vercoe, Barry, and Et Al. “Foscil.” Csounds.Com. 1992. MIT Media Lab. 10 Mar. 2008 <http://www.csounds.com/manual/html/foscil.html>.

Wikipedia contributors. “Phase modulation” [Internet]. Wikipedia, The Free Encyclopedia; 08:10 16 February 2008 UTC<http://en.wikipedia.org/wiki/Phase_modulation> [accessed 2008 Mar 7].

Wikipedia contributors. “Frequency modulation”, Wikipedia, The Free Encyclopedia, 21:37 2 March 2008 UTC <http://en.wikipedia.org/wiki/Frequency_modulation> [accessed 2008 Mar 7].