Simulating Analog Audio Cicuits

Problem: been reading LAU

Idea: feed the great SPICE simulator with audio-data.

Solution: add a libsndfile voltage-source to SPICE ;)

general information

A new version of the software and this document is now available at SpiceSound

It's yet a quick experiment, and requires patching the SPICE source-code. Initial tests show that it might be realistic to simulate simple schematics in real-time1). Although the spice command is already named jack it's yet only a file-reader. For testing, there is a tool txt2snd to convert spice .print lines into wav files 2).

one (of the many) issues is running spice in audio-samplerate time-steps… - it's work in progress.

prepare

spice syntax

The patched spice knows a new type of voltages-source jack with the optional argument file.

an example netlist entry connecting the sound-source /tmp/test.wav to pin 4(Signal) and pin 0 (GND) with a range of [-1..+1] Volts looks like:

V_V2 4 0 file /tmp/test.wav jack 0 0 1.0 0

Syntax:

jack <id> <v_offset> <v_mult> <t_off>
file <filename>
  • <id> an integer identifier 0 to 2
  • <v_offset> offset added in Volts
  • <v_mult> the multiplier when converting sndfile-float [0..1] to Volts
  • <t_off> offset in milliseconds added when seeking the sound-file
  • NOTE: The option file must precede the option jack to take affect.
  • default files are id=0:/tmp/test.wav id=1:/tmp/test1.wav id=2:NULL

txt2snd

txt2snd allows to convert spice output int wav files - it's yet rather simple but has a built-in help.

It reads 4 tabulator separated values per line in the format:

<idx/int> <time|ms/float> <ignored/float> <value/float>

example:

11      8.916652e-05    1.846313e-02    -7.477363e-01

this format can easily be generated by SPICE. in the following example 20 seconds of net 5 are printed at 48kSPS:

.print tran  v(4) v(5)
.tran 2.08333e-05 20.0 0 2.08333e-05
.op

Note: Rounding (spice-milliseconds to audio-sample) is buggy and txt2snd includes an only sometimes working workaround (use –verbose to investigate skipped/missing frames).

the following script might come in handy..

#!/bin/sh
INFILE=example.netlist
OUTFILE=/tmp/spice.txt
WAVFILE=/tmp/spice.wav
echo "# writing data to $OUTFILE"
ngspice -b $INFILE | awk 'BEGIN{go=0;} /^-------------------------------------/{go=1;} /^[0-9]/{if (go==1) print $0;}' > $OUTFILE
echo "# txt to snd"
cat $OUTFILE | txt2snd $WAVFILE
echo "# done."

Example

spice3 sound example

V_V2 1 0 file /tmp/test.wav jack 0 0 1.0 0
R_R1 1 0 1M

.print tran  v(1) v(1)
.tran 2.08333e-05 2.0 0 2.08333e-05
.op
 
.END

Save this example script to example.net; save a 48k wav file to /tmp/test/wav and launch with ngspice -b example.net. this prints the values (and some spice debug output) to stdout (see script above). pipe the cleaned spice output into txt2wav to produce a wav file again (also see script above).

foxxfuzz

foxx.oregano.gz is modeled after:

NOTEs:

  • The simulated Diodes and NPNs are not the original, but the default models available with oregano.
  • the gain/sustain pot is modeled in R50/R51 - sum 50k
  • the tone pot is modeled in R60/R61 - sum 50k
  • flip the octave switch, by removing diode D1. w/o Diode = off

Beware: it's not yet debugged…

Stay tuned for a SPICE netlist and soundfiles, tweaks & screenshots.

aliki/jace

ToDo - a good way to verify..

  • measure response of a simple circuit and document with aliki (and use in realtime with jace..)
  • compare aliki w/ spice impulse response analysis.
  • compare spice processed audio and jace processed audio.

References

1) simulating 1sec audio of the foxx-effect at 48ksps on a intel core P6 1.6GHz takes about 4sec
2) txt2snd writes yet only 16-bit signed-int-LE wave files
 
wiki/spicesound.txt · Last modified: 31.05.2007 19:32 by rgareus