Giter Site home page Giter Site logo

thadeuluiz / rtspice Goto Github PK

View Code? Open in Web Editor NEW
63.0 3.0 1.0 182 KB

A real-time netlist based audio circuit plugin

License: GNU General Public License v3.0

CMake 13.21% C++ 86.79%
signal-processing digital-signal-processing dsp electronics-engineering electronics-lab electronics-design electronics-tools electronics-enthusiasts electronics-hobbyists cpp cpp17 jack jackaudio audio-processing audio-effect sound-processing sound-effects guitar-processor

rtspice's Introduction

RTspice

A netlist-based realtime audio circuit simulator

Requirements

Getting started

I recommend to obtain the dependencies through your distribution's package manager (Ubuntu has JACK on the default repo and the DBUS version on some PPAs, arch linux also has most of the dependencies on the default repo, and the rest can be installed from AUR). The JACK configuration can be tricky if your distribution depends on PulseAudio, however, the D-Bus version should make it easier to setup.

Once all dependencies are installed, git clone --recurse-submodules this repository into a directory of your choice, create a build directory mkdir build, configure the project with cmake .. -DCMAKE_BUILD_TYPE=Release and make it. Should compilation succeed, you can check that the simulation works with the compiled tests and run the program with ./rtspice and you'll be greeted with the blank entry screen:

home screen

You may then open a netlist file (.net extension), and if the netlist has a proper syntax, you should see the simulation screen:

sim screen

Basic information, such as the circuit's name, the number of nonzero elements in the modified admittance matrix and the number of modified nodes can be seen top left.

Information regarding JACK processing load, ports and connections lies top right. Once you've chosen the appropriate input and output connections, press 'Activate' to begin simulation.

For circuits containing parametrized components (i.e. variable resistors, capacitors or inductors), knobs will be visible on the bottom of the screen. The 'Log' checkbox switches the knob control pattern from linear to logarithmic.

How it works?

Traditional circuit simulation programs are based on modified nodal analysis, where the node voltages and some branch currents are the unknowns in a (usually sparse) linear system, and can be obtained through regular linear system solvers.

Circuits that contain dynamic components such as capacitors require modelling of the dynamic behavior based on some integration method, being reduced to sources and time-varying resistances. For now, we use trapezoidal integration for both capacitors and inductors.

Circuits that contain nonlinear components require solving a nonlinear system of equations, however using the Newton-Raphson method, this also reduces to solving iterations of linear systems.

Based on this, this program provides an interface for a computer's audio ports to act as signal sources or measurements for electronic circuits. A difficulty arises in the needed time to solve said linear systems rapidly enough to keep up with the sound samples: for instance, a 44.100 kHz sampling rate requires the solution to be calculated in less than 23 μs. Considering this, it can be expected this software to work better with modest-sized circuits, however, the actual size you'll be able to consistently simulate will depend on your hardware.

Netlist syntax

The circuits are described through a netlist, representing which components should be added and which nodes the components are connected to. Our netlist syntax is similar but not exactly the same as SPICE's:

  • The first line of the netlist is a special comment containing the circuit name:
    • My little circuit
  • Lines beginning with asterisks(*) are considered comments and are ignored:
    • *Some witty comment
  • The rest of the lines are considered statements and go towards the circuit definition:
    • RL 0 1 2.2k
  • Multiline statements can be made prepending the sequenced lines with +:
    • Vin NODE_A NODE_B
      +EXT IN

Components

The currently supported components are listed below:

Component Type Syntax Example Notes
DC Voltage V{ID} {NODE+} {NODE-} DC {VALUE} Vcc 1 0 DC 12 VALUE in Volts
Sinusoidal Voltage V{ID} {NODE+} {NODE-} SINE {AMPLITUDE} {FREQUENCY} {PHASE} Vac p 0 SINE 120 60 0 AMPLITUDE in Volts, FREQUENCY in Hertz and PHASE in degrees
External Voltage V{ID} {NODE+} {NODE-} EXT {INPUT} VIN 1 0 EXT INPUT INPUT defines the name of an input port to be connected
DC Current I{ID} {NODE+} {NODE-} DC {VALUE} Ibias b 0 DC 1u VALUE in Amperes, flows from NODE+ to NODE-
Sinusoidal Current I{ID} {NODE+} {NODE-} SINE {AMPLITUDE} {FREQUENCY} {PHASE} If p 0 SINE 1n 10k 90 AMPLITUDE in Amperes, FREQUENCY in Hertz and PHASE in degrees
External Current I{ID} {NODE+} {NODE-} EXT {INPUT} IIN 1 0 EXT I_INPUT INPUT defines the name of an input port to be connected
Linear Voltage Amplifier E{ID} {OUT+} {OUT-} {IN+} {IN-} {Av} E1 0 x 1 0 100
Linear Current Amplifier F{ID} {OUT+} {OUT-} {IN+} {IN-} {Ai} F1 2 9 h u -3
Linear Transconductance G{ID} {OUT+} {OUT-} {IN+} {IN-} {Gm} G1 6 0 1 0 10u Gm in Siemens
Linear Transresistance H{ID} {OUT+} {OUT-} {IN+} {IN-} {Rm} H5 8 0 t u -3 Rm in Ohms
Linear Resistor R{ID} {NODE_A} {NODE_B} {VALUE} Rload 0 X 22k VALUE in Ohms
Variable Resistor R{ID} {NODE_A} {NODE_B} EXT {MAX_VALUE} {PARAM} Rvol OUT 0 EXT 500k Volume MAX_VALUE in Ohms, PARAM defines the name of a knob
Linear Capacitor C{ID} {NODE_A} {NODE_B} {VALUE} Rbypass 23 A 10u VALUE in Farads
Linear Inductor L{ID} {NODE_A} {NODE_B} {VALUE} Lchoke vcc c 10m VALUE in Henrys
Ideal OPAMP U{ID} {OUT+} {OUT-} {IN+} {IN-} OPAMP U1 out 0 in out OPAMP Usually, OUT- should be grounded
Basic Diode D{ID} {ANODE} {CATHODE} IS={IS} N={N} D1 cut 0 IS=4.3n N=1.9 IS is saturation current in Amperes, N is the emission coefficient
Bipolar NPN Q{ID} {COLLECTOR} {BASE} {EMITTER} NPN IS={IS} BF={BF} BR={BR} Q1 c b e NPN IS=3.84e-14 BF=324.4 BR=8.29 BF is forward beta, BR is reverse beta
Bipolar PNP Q{ID} {COLLECTOR} {BASE} {EMITTER} PNP IS={IS} BF={BF} BR={BR} Q1 c b e PNP IS=3.84e-14 BF=324.4 BR=8.29
PROBE PROBE {NODE} PROBE OUT PROBE is how output variables are defined. For each PROBEd node, an output port becomes available to the user

Inputs, Outputs and Params

The netlist not only describes the circuit, but it also defines where the inputs are located. For each different {INPUT} for external voltages and currents, an input port will be available to connection, corresponding to that given source.

For potentiometers, each different {PARAM} corresponds to a knob that will be available on the control screen.

For the outputs, the special component PROBE marks a node voltage (or branch current) that will serve as an output port for the system.

TODO

  • Proper potentiometer

    • Currently one can emulate a potentiometer: Rpot X Y Z POT VAL PARAM as:
      RpotX X @XY VAL
      RpotY @XY Y EXT -VAL PARAM
      RpotZ Y Z EXT VAL PARAM
  • Subcircuit models (i.e. compensated OPAMP)

  • JFET and MOSFETs

  • Nonlinear dynamic components

  • A graphical circuit editor

rtspice's People

Contributors

thadeuluiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

longjohncoder

rtspice's Issues

CMake can't find JACK

I am quite inexperienced with Linux, so I'm sure the problem is on my end, but I'm having an issue with CMake finding JACK. I'm fairly certain I haven't setup JACK properly, but I can't figure out how so. See below:

$ cmake .. -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Boost version: 1.65.1
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found CUDA: /usr (found version "9.1")
-- Found OpenMP_C: -fopenmp (found version "4.5")
-- Found OpenMP_CXX: -fopenmp (found version "4.5")
-- Found OpenMP: TRUE (found version "4.5")
-- Checking for one of the modules 'jack'
CMake Error at /usr/share/cmake-3.10/Modules/FindPkgConfig.cmake:645 (message):
  None of the required 'jack' found
Call Stack (most recent call first):
  CMakeLists.txt:19 (pkg_search_module)


-- Configuring incomplete, errors occurred!
See also "/home/chroe/github/RTspice/build/CMakeFiles/CMakeOutput.log".
See also "/home/chroe/github/RTspice/build/CMakeFiles/CMakeError.log".

I'm running Ubuntu 18.04 on Windows Subsystem for Linux. apt list --installed | grep jack gives me:

jack/bionic,now 3.1.1+cvs20050801-29.2 amd64 [installed]
jackd/bionic,now 5 all [installed]
jackd2/bionic,now 1.9.12~dfsg-2 amd64 [installed]
jackd2-firewire/bionic,now 1.9.12~dfsg-2 amd64 [installed,automatic]
libjack-jackd2-0/bionic,now 1.9.12~dfsg-2 amd64 [installed,automatic]
qjackctl/bionic,now 0.4.5-1ubuntu1 amd64 [installed]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.