Simulating Analog Audio Circuits Part II

With minor modifications the ngSpice-sound libsndfile/libsamplerate wrapper source can just be compiled with other Software. Here's an experiment with qUCS1).

Patch

You need to get the build-dependencies for QUCS which includes admsXml''. You can start-off by patching the debian source which is easier to accomplish as it includes those as prebuild maintainer-files: sudo apt-get build-dep qucs, apt-get source qucs and continue to patch in ./qucs-0.0.11/qucs-core Note: the patch is just a quick hack and experiment: The one to be thrown away.

cd /tmp
wget http://downloads.sourceforge.net/qucs/qucs-0.0.11.tar.gz
wget http://gareus.org/_media/oss/spicesound/qucs-0.0.11-core-snd-v1.1.diff
tar xzf qucs-0.0.11.tar.gz
cd qucs-0.0.11/qucs-core
patch -p1 < ../../qucs-0.0.11-core-snd-v1.1.diff
cd ..
./autogen.sh
#CXXFLAGS="-Wall -g -O3" CFLAGS="-g -O2 -Wall" ./configure '--host=i486-linux-gnu' \
 '--build=i486-linux-gnu' '--prefix=/usr' '--mandir=/usr/share/man' \
 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu' && make
./configure && make
sudo make install

Syntax

The Audio-Source is represented by a voltage source in the circuit and the Audio-Sink is implemented as transient analysis command.

Audio Source Syntax:

Vsnd:V1 _net0 gnd U="1 V" TimeOffset="0.0" Samplerate="48000" Channel="0" Oversampling="64" File="test.wav"

Vsnd is a spin-off from Vac and has similar syntax in the netlist. The parameters are:

  • U (default 1V) - Voltage multiplier when converting the audio-floating point value to Volts
  • UOffset (default 0.0V) - Voltage offset
  • TimeOffset (default 0s) - offset in seconds added to the simulation-time when seeking the source-file.
  • Samplerate (default 48000) - Samplerate to use when converting time to samples
  • Oversampling (default 64) - upsampling factor
  • Channel (default 0) - audio-channel of the source file to use
  • File (default “in.wav”) - audio file to use

Note:

  • qUCS syntax is very restrictive and does only allow the following characters [A-Z][a-z][0-9]_. as options. This limits the path to input/output files to the current working directory!
  • Only the qUCS parser has been patched to allow audio-IO; qUCS can import and parse other netlist formats but audio-IO is not available for them.

Audio Sink:

the TR transient analysis command has been re-used. TSOUND is equivalent to TR but has a few extra options and writes an audio-file instead of XML.

.TSOUND:TR1 Type="lin" Start="100ms" Stop="200ms" Points="76802" IntegrationMethod="Trapezoidal" Order="2" InitialStep="1 ns" MinStep="1e-8" MaxIter="150" reltol="0.001" abstol="1 pA" vntol="1 uV" Temp="26.85" LTEreltol="1e-3" LTEabstol="1e-6" LTEfactor="1" Solver="CroutLU" relaxTSR="no" initialDC="yes" MaxStep="0" Oversampling="16" File="test_out2.wav"

Parameters:

  • File (default out.wav) - Output-File to write
  • Samplerate (default 48000) - Samplerate of the file to write
  • Umult (default 1.0 [1/V]) - multiplier when converting Volts into audio samples
  • Uoffset (default 0.0 V) - zero Volts offset
  • Format (default “wav24”) - Audio format to write. numeric of text shortcut
    • -1:default (wav 24 bit/sample little endian)
    • 0: aliki .ald data file
    • >0 : libsndfile numeric format SF_FORMAT_XXX - example: (SF_FORMAT_WAV | SF_FORMAT_PCM_24) = 0x010000 | 0x003 = 65539
    • currently the following txt shortcuts are defined: wav16, wav24, wav32, aiff and aliki. =
  • Oversampling (default 64) - downsample output by this factor

Note: set TSOUNDs Points parameter to ((Stop-Start)*Samplerate*Oversampling)+2

Examples

# Qucs 0.0.11 
.TSOUND:TR1 Type="lin" Start="100ms" Stop="200ms" Points="76802" IntegrationMethod="Trapezoidal" Order="2" InitialStep="1 ns" MinStep="1e-8" MaxIter="150" reltol="0.001" abstol="1 pA" vntol="1 uV" Temp="26.85" LTEreltol="1e-3" LTEabstol="1e-6" LTEfactor="1" Solver="CroutLU" relaxTSR="no" initialDC="yes" MaxStep="0" Oversampling="16" File="sw4.wav"
#.TR:TR1 Type="lin" Start="100ms" Stop="200ms" Points="76802" IntegrationMethod="Trapezoidal" Order="2" InitialStep="1 ns" MinStep="1e-8" MaxIter="150" reltol="0.001" abstol="1 pA" vntol="1 uV" Temp="26.85" LTEreltol="1e-3" LTEabstol="1e-6" LTEfactor="1" Solver="CroutLU" relaxTSR="no" initialDC="yes" MaxStep="0"
#.AC:AC1 Type="lin" Start="20Hz" Stop="20 kHz" Points="100" Noise="no"
Vsnd:V1 _net0 gnd U="1 V" TimeOffset="0.0" Samplerate="48000" Channel="0" Oversampling="64" File="slin5s48k_F.wav"
R:R3 _net0 _net1 R="200 Ohm" Temp="26.85" Tc1="0.0" Tc2="0.0" Tnom="26.85"
C:C2 gnd _net1 C="1 uF" V=""
C:C1 _net1 sound C=".1 uF" V=""
R:R4 gnd sound R="10 kOhm" Temp="26.85" Tc1="0.0" Tc2="0.0" Tnom="26.85"

Save the stanza above as bandpass.txt copy an audio-file to slin5s48k_F.wav in the same folder. Executing qucsator -i bandpass.txt will write sw4.wav: a 3 channel audio-file corresponding to the voltages on _net0 _net1 and sound

References

1) QUCS: quite universal circuit simulator
 
oss/spicesound/qucs.txt · Last modified: 23.12.2011 21:26 (external edit)