====== Simulating Analog Audio Cicuits ======
{{wiki:spicesound.png?250 }}
Problem: been reading [[http://linuxaudio.org/pipermail/linux-audio-user/2007-May/045851.html|LAU]]
Idea: feed the //great// [[sf>ngspice|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 [[:oss:spicesound:start|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-time((simulating 1sec audio of the foxx-effect at 48ksps on a intel core P6 1.6GHz takes about 4sec)). 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 ((txt2snd writes //yet// only 16-bit signed-int-LE wave files)).
one (of the many) issues is running spice in audio-samplerate time-steps... - **it's work in progress**.
===== prepare =====
* patch spice: {{wiki:ng-spice-rework-17-sndfile.diff}}
* compile {{wiki:txt2snd-0.1.tgz}}
* prepare some libsndfile readable audio file.
===== 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
file
* '''' an integer identifier 0 to 2
* '''' offset added in Volts
* '''' the multiplier when converting sndfile-float [0..1] to Volts
* '''' 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: