Problem: been reading LAU
Idea: feed the great SPICE simulator with audio-data.
Solution: add a libsndfile voltage-source to SPICE ;)
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.
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-filefile
must precede the option jack
to take affect./tmp/test.wav
id=1:/tmp/test1.wav
id=2:NULL
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."
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:
Beware: it's not yet debugged…
Stay tuned for a SPICE netlist and soundfiles, tweaks & screenshots.
aliki/jace
ToDo - a good way to verify..