Introduction: Analog Sound Synthesis on Your Computer
Like the sound of those old analog synthesizers? Want to play with one on your own time, at your own place, for as long as you want, for FREE? Here is where your wildest Moog dreams come true. You can become an electronic recording artist or just make some cool, trippy sounds to listen to on your mp3 player. All you need is a computer!
It's all done through the magic of a free circuit simulator called LTSpice. Now I know you're probably saying "Gee willikers, Tyler, I don't know anything about running a circuit simulator- that sounds HARD!". Don't worry, Bunky! It's easy and I'll give you a few templates to start with and modify to make whatever weird noises you want.
Not sure it's worth the effort? Here's a link to a ready to play sound file (it is made from "composition_1.asc" in step 7 of this 'ible) that you can try out. I converted it from .wav to mp3 to reduce the download time. http://www.rehorst.com/mrehorst/instructables/composition_1.mp3
There's some low bass in it the sound so listen with headphones or good speakers.
If you like what you see, vote for me!
Note: I have attached schematic files for LTSpice that you can run on your computer, but for some reason when you try to download them the names and extensions get changed. The contents of the files look OK, so after downloading the files just change the names and extensions and they should work. The correct names and extensions are shown on the icons you click to download.
Step 1: First Things First
LTSpice is a windows program, but don't let that get you down. It runs fine under Wine in linux. I suspect there are no problems running it in VMWare client, VirtualBox, or other virtualization tools under linux, and probabaly on Macs too.
Download a copy of LTSpice for Windows (ugh!) here:
What is LTSpice? It is a time-domain circuit simulator that every electronics hobbyist ought to know how to use. I'm not going to provide a detailed tutorial on how it works here, but I will explain a few things you'll need to know as we go along.
One word of warning- it is easily possible to produce frequencies that are too low or too high to hear. If you do that and drive your expensive speakers with a high powered amp you may just blow your speakers/amp to bits. ALWAYS look at the waveforms before you play them back and be careful to limit the volume when you play back a file for the first time just to be safe. It is always a good idea to play the files via cheap headphones at low volume before trying speakers.
Step 2: Input
Input to the simulator is in the form of a schematic diagram. You select components, place them on the schematic, then wire them together. Once your circuit is complete, you tell the simulator how you want it to simulate the circuit and what sort of output you want.
Take a look at the schematic called resistors.asc. You'll see there is a circuit that includes a voltage source, a pair of resistors, a labeled output node, a ground, and a text command line. Let's look at each one. Now is a good time to open the circuit file linked below.
This is the MOST CRITICAL component on your schematic. You MUST have a ground connected to at least one point on your circuit or you will get very strange results from your simulations.
The voltage source:
If you are putting a voltage in a circuit, you need to tell it whether it is AC or DC (or something more complex), what the voltage is, the "internal resistance" of the source, etc. You can enter those parameters by right clicking with the pointer on the source. All you really need is the resistance for simple simulations.
The resistors are pretty easy to understand. Just right-click to set value of resistance. Ignore any other parameters that might be hiding there.
Labeled input and output nodes:
Just names for nodes in the circuit that are user friendly.- use names like "output", "input", etc.
The simulation directive:
the .tran statement tells the simulator how you want the circuit to be simulated. This is a time-domain simulator which means it analyzes the circuit at different points in time. You need to tell it what the maximum time step should be and how long the simulation should run in "circuit-time", not real time. If you tell the simulator to run for 10 seconds of circuit-time and you set the maximum time step to 0.001 seconds, it will analyze the circuit at least 10,000 times (10 sec/0.001 sec) then stop.
When the simulation runs, the voltage at every node in the circuit and the currents into and out of every node will be calculated and saved at each time step. All that info will be available to plot on a display like an oscilloscope screen (time of the horizontal axis, voltage or current on the vertical axis. Alternatively, you can also send the output to a .wav audio file that you can play on a computer, burn to a CD, or convert to mp3 to play on your mp3 player. More on that later...
Step 3: Output
Output can be a graphical plot of voltage vs time, voltage vs voltage, etc., or a text file consisting of a bunch of voltages or currents at each time step, or a .wav audio file that we are going to use a lot in this instructable.
Download and open the file "resistors.asc". Click the little running man symbol (upper left part of the screen) and the circuit should run. Now click on the "OUT" label in the circuit. You'll see the voltage labeled "output" displayed on the graphical output along a horizontal axis that represents time. That is the voltage measured relative to ground (that's why you need at least one ground in every circuit!).
Those are the basics. Try changing one of the resistor values or the voltage then rerun the simulation and see what happens to the output voltage. Now you know how to run a circuit simulator. Easy wasn't it?
Step 4: Now Some Sound!
Open the circuit called "dizzy.asc". This one is a weird noise maker that uses a modulator and a couple voltage sources to produce a CD quality (16 bits, 44.1 ksps, 2 channels) audio file that you can play with.
The modulator component is an actually an oscillator. Frequency and amplitude are both adjustable like a VCO and VCA in a real analog synthesizer. The wave form is always sinusoidal, but there are ways to alter it- more on that later.
The frequency limits are set by the mark and space parameters. Mark is the frequency when the FM input voltage is 1V and space is the frequency when the FM input voltage is 0V. The output frequency is a linear function of the FM input voltage, so the frequency will be half way between the mark and space frequencies when the FM input voltage is 0.5V and will be 2x the mark frequency when the FM input voltage is 2V.
The modulator can also be amplitude modulated via the AM input pin. The modulator (oscillator) output amplitude will match the voltage applied to the AM voltage input. If you use a DC source with a voltage of 1, the output amplitude will be 1V (that means it will swing between -1 and +1 V).
The modulator has two outputs- sine and cosine. The waveforms are exactly the same except they are 90 degrees out of phase. This can be fun for stereo audio applications.
There is a .tran statement that tells the simulator the maximum time step and the duration of the simulation. In this case, circuit-time (total simulation time) = audio file time. That means if you run the simulation for 10 seconds you'll get an audio file that is 10 seconds long.
The .save statement is used to minimize the amount of data the simulator will save as it runs the simulation. Normally it saves the voltages at every node and the currents into and out of every component. That can add up to a LOT of data if your circuit gets complicated or you run a long simulation. When you run the simulation, just select one voltage or current from the list in the dialog box and the data file (.raw) will be small, and the simulation will run at maximum speed.
Finally, the .wave statement tells the simulator to create a CD quality stereo audio file (16 bits per sample, 44.1 ksps, two channels) putting the voltage at "OUTL" in the left channel and the voltage at "OUTR" in the right channel. The .wav file consists of 16 bit samples. Full scale output in the .wav file (all 16 bits in a sample turned on) occurs when the voltage being output is exactly +1 Volt or -1 Volt. Your synthesizer circuit should be set up to generate voltages no more than +/- 1V out to each channel, otherwise the output in the .wav file will be "clipped" whenever the voltage exceeds +1 or -1 V.
Since we are making an audio file that is sampled at 44.1 ksps, we need the simulator to simulate the circuit at least 44,100 times per second, so we set the maximum time step to 1/44,100 sec or about 20 microseconds (us).
Step 5: Other Types of Voltage Sources, Other Types of Sounds.
An analog synthesizer needs a source of random noise. You can generate noise using a "behavioral voltage source" (bv) and you can switch it on and off using a "voltage controlled switch" (sw).
Using the bv component to generate noise involves defining the voltage based on a formula. The formula for generating noise looks like this: V=white(time*X)*Y The white function creates a random voltage between -0.5 and +0.5 V using the current time value as a seed. Setting Y to 2 gives a +/- 1V swing. Setting X between 1,000 (1e3) and 100,000 (1e5) affects the spectrum of the noise and changes the sound.
The voltage controlled switch also needs some parameters to be set in a .model statement. You can use multiple voltage controlled switches and multiple model statements to make each one behave differently if you want. You have to tell the simulator the "on" and "off" resistances and the threshold voltage at which it switches. Vh is "hysteresis voltage". Set it to some positive value like 0.4V and there won't be any clicking sounds when the switch opens and closes.
>>>Update: here's an even easier way to make a gated noise source- just multiply the noise voltage by a pulsed source- see easy_gated_noise.asc, below.
Step 6: Bells, Drums, Cymbals, Plucked Strings
Bells, drums, cymbals, and plucked strings are all percussive. They have a relatively fast rise time and an exponential decay time. Those are easy to create using sine and behavioral voltage sources combined with some simple circuits.
Look at the schematic "bell_drum_cymbal_string.asc". The pulsed voltage sources with the resistor, capacitor and diode create the fast rise and slow exponential decay waveforms needed. Those output voltages modulate the outputs of behavioral sources set up as random noise or sine wave sources. When the pulsed source voltage rises it quickly charges the capacitor. The capacitor then discharges through the resistor. The diode keeps the voltage source from discharging the capacitor when the source voltage is at zero. Bigger resistor values increase the discharge time. You can specify the rise time of the pulsed source - the cymbal is a nise source with a very fast rise time. The drum is also a noise source that operates at lower frequency and has a slower rise time. The bell and string use sine wave sources that are modulated by pulsed sources too. The bell operates at higher frequency and has a faster rise time than the string.
Run the simulation and listen to the result. Note that the drum appears in both channels while all the other sounds are either right or left channel. The two resistors at the drum output are responsible for putting the sound into both channels.
Step 7: Putting It All Together
OK, now you've seen how to make some sounds and how to shape the envelopes and frequency modulate them. Now it's time to put a few different sources together in a single schematic and generate something interesting to listen to.
How do you get that noise source to come into the composition at 33 seconds? How do you turn on that chiming bell at 16 seconds, then turn it off, then turn it on again at 42 seconds? One way is to use a behavioral voltage source to make the desired sound then turn it on and off by multiplying the sound generating voltage by another voltage that turns the sound on and off, as was done in bell_drum_cymbal_string.asc. You can do the same sort of thing to fade sounds in and out.
The idea here is to set up repeating sounds then use additional source(s) to add those sounds to your composition at desired times by multiplying their voltages by the sound voltages. You can include as many voltages in the final sound output as you want, just keep multiplying them (same as logical "and") together. By starting the sounds up all at once they will remain in perfect sync throughout the composition so they will never be early or late in the time of the music.
Look at composition_1.asc. There are two bells, one in each channel. The pulse_bell voltages operate throughout the simulation but the sounds only show up in the output when V(bell_r) and V(bell_l) are not equal to 0.
Step 8: Exponential Ramp
Update 7/10- scroll to bottom
Here's a circuit that generates an exponential ramp applied to a pair of noise sources. V1 and V2 generate linear ramps that start at 0 and rise to X volts (left channel) and Y volts (right channel) in periods prd_l and prd_r. B1 and B3 use a formula to convert the linear ramps to exponential ramps with maximum amplitudes of 1V. B2 and B4 generate random noise that is amplitude modulated by the exponential ramps and by parameters amp_l and amp_r (simple level controls).
I have attached an mp3 file generated by this circuit so you can hear what it sounds like. You'll probably have to rename the file to get it to play.
X and Y set the voltage limits of the linear ramps. Eventually both channel's ramps get scaled to 1V, but by setting X and Y you can control the steepness of the exponential ramp. A small number like 1 gives a nearly linear ramp, and a large number like 10 gives a very steep exponential ramp.
The ramp periods are set using parameters prd_l and prd_r. The linear ramp rise time is set to the prd_l or prd_r value minus 5 ms, and the fall time is set to 5 ms. The longish fall-time prevents clicking at the end of each ramp as the amplitude drops back to zero.
out_l and out_r are the products of the time-based random noise voltages, the exponential ramp voltages, and the parameters amp_l and amp_r. Note the right channel random noise value uses a different "seed" than the left channel. That keeps the noise in each channel random and different from the opposite channel. If you use the same seed, at the same time value you'll get the same random value and the sound will end up in the center instead of being perceived as two different sources, one in each channel. This could be an interesting effect to play with...
Update: notice that the waveform goes from 0V to some positive value. It is better for the voltage to swing between equal positive and negative values. I reworked the schematic to do just that but it increased the complexity of the equation that defines the waveform a little. Download the exponential_ramp_noise.asc (remember that the Instructables server will change the name and extension when you save it).
Step 9: Exponential Ramp Applied to a Sine Wave
This page shows how to use the exponential ramp from the previous step to modulate a sine source (actually, sine and cosine). The behavioral voltage source is used to turn a linear ramp into an exponential ramp that drives the FM input on a modulate2 component.
The amplitude is modulated by both a fast exponential ramp and a slow sine wave.
Listen to the sample file- it sounds pretty weird.
Step 10: Suggestions
1) You can vary the total simulation time - keep it short while you're playing with components and when you get the sound you like, then set the simulator to run for 30 minutes (1800 sec) or however long you like. You can copy circuits from one page to another and you can make subcircuits so you can just connect little circuit modules together like using a patch board on a real synthesizer.
2) A CD sample rate is 44.1 ksps. If you keep the maximum time-step down to 20 us you'll get a "clean" output because the simulator will have data available for each new sample. If you use a smaller time-step the simulation will be slow and probably won't have any effect on the sound. If you use a longer time-step you may hear some aliasing that you may or may not like.
3) use the .save dialogbox statement on your schematic and when you run the simulation and select just one of the voltages or currents to keep the size of the.raw file small. If you don't make a selection, ALL the voltages and currents will be saved and the .raw file will get VERY large.
4) try using very low frequencies to modulate higher frequencies
5) try using higher frequencies to modulate lower frequencies.
6) combine outputs from some low frequency sources with some high frequency sources to make things interesting.
7) use a pulsed voltage source to modulate a sine or other source to provide rhythm.
8) use analog circuits to shape voltage pulses into something you want.
9) use mathematical expressions to define the output of a behavioral voltage source