LiveSPICE, my real time circuit simulator project

Started by dsharlet, November 13, 2013, 09:25:03 PM

Previous topic - Next topic

dsharlet

Hello,

I wanted to share with you all a project I think you might find interesting. I've been working on a circuit simulator that runs the simulation in real time on a live audio signal. The motivation for this project is to simulate guitar effects and amps on a live guitar signal with minimal latency. Currently, it can simulate some popular pedal designs effectively in real time. I can't tell you if it actually matches the sound of the real deal because I both do not own the pedals and I suck at playing the guitar, but I can tell you that they are pretty fun to noodle around with, and they certainly sound plausibly correct :)

Note that it is completely free/open source, I'm not trying to sell you anything, not even ad views. This is purely a hobby project I'm doing for fun.

I was hoping to get your feedback and experience when trying out the project so far. Note that it is quite early in development, so you will find lots of bugs! I still have a lot to do:

- I still have many major optimizations I can make to the simulation, meaning larger/more complex circuits can be simulated in real time.
- The component library is pretty small currently. You could help me here by telling me which components I should prioritize adding.
- Supporting controls (pots, etc.) for adjustment during simulation (instead of only at circuit design time).
- Export VST plugins for use in other applications.
- Import/export SPICE netlists.
- This list basically goes on forever. Your feedback will help me prioritize!

There are some examples that show what it is currently capable of simulating, as well as more information about the project here: http://www.livespice.org Tell me what you think! Even if you think it's totally useless (I'm not convinced it isn't...)

defaced

Oh, this isn't useless in the slightest.  It's one of the most commonly asked questions, and let downs, for those getting into simulation.  I unfortunately can't run it (.NET Framwork 4.5 does not support the XP 64 System I have at the moment), but just that you're doing this and putting it out there as an Open Source project is awesome and I wholly commend your efforts. I can't wait to check it out. 
-Mike

armdnrdy

Look at you go Dillon!

Great work!

It looks like the Government healthcare website could have used you on their design team!  :icon_wink:

I don't know anything about spice....but it's something I have on my list of things I have to learn how to do.

Is your system compatible with spice component models?
I just designed a new fuzz circuit! It almost sounds a little different than the last fifty fuzz circuits I designed! ;)

tubegeek

I don't think you're going to be able to convince me it is useless, either. Wish I had a PC here to check it out with....  :icon_sad:
"The first four times, we figured it was an isolated incident." - Angry Pete

"(Chassis is not a magic garbage dump.)" - PRR

dsharlet

Quote from: armdnrdy on November 13, 2013, 09:54:11 PM
Look at you go Dillon!

Great work!

It looks like the Government healthcare website could have used you on their design team!  :icon_wink:
I can't stand developing websites, even the simple www.livespice.org site was frustrating enough!
QuoteI don't know anything about spice....but it's something I have on my list of things I have to learn how to do.
I warn you that this tool's name might be slightly misleading, I would not consider it a stepping stone for learning SPICE. But, LiveSPICE is pretty simple to use (IMO of course), there is a step by step tutorial for building a simple circuit on the site, and extending that to more complex circuits should be clear. If anything is not clear, I'd like to know about it so I can fix it/document it!
QuoteIs your system compatible with spice component models?
It is not. It is something I've had on the back of my mind and I plan to do it at some point, but I have not done it yet. It will likely be an incremental process (simple netlists/models supported at first, some more complex models may never be supported).


Sorry to hear about the troubles with Windows/.Net, hopefully that isn't too big of a stumbling block for many people.

ashcat_lt

Yes please absolutely!  I'm going to keep my eye on this one.  Looks like it's gonna be cool, especially when we can port models to VST. 

Just one thing from reading the website:  Is there some reason that you aren't using the actual voltage at the input, rather than scaling it to 0dbfs = 1V?  It might require something in the config to tell it what the actual input sensitivity is, but it seems to me like it might be more useful.

dsharlet

Quote from: ashcat_lt on November 13, 2013, 11:17:03 PM
Yes please absolutely!  I'm going to keep my eye on this one.  Looks like it's gonna be cool, especially when we can port models to VST.
Glad to hear you are interested!
QuoteJust one thing from reading the website:  Is there some reason that you aren't using the actual voltage at the input, rather than scaling it to 0dbfs = 1V?  It might require something in the config to tell it what the actual input sensitivity is, but it seems to me like it might be more useful.
I agree it would be simpler to have a control for this. I just arbitrarily assigned it 1V because you can't actually get the voltage from any of the input devices I have (or at least I don't know how). Note that there is a gain control on each input channel so you can get what you want already, I will probably just relabel the input/output channel gain adjustments to be controls on the voltage at 0dB since that is probably more intuitive.

This brings up a good question that I've had for a long time: what actually *is* the voltage of a typical guitar signal? I'm totally betraying the fact that I'm a math/theory nerd and I've never actually gotten my hands dirty with a real guitar circuit...

psychedelicfish

Quote from: dsharlet on November 13, 2013, 11:32:07 PM
This brings up a good question that I've had for a long time: what actually *is* the voltage of a typical guitar signal? I'm totally betraying the fact that I'm a math/theory nerd and I've never actually gotten my hands dirty with a real guitar circuit...
It depends heavily on the pickup, what it's driving, and how the guitar is played. A humbucker will have a bigger signal than a single coil pickup, a guitar driving a fuzz face will have a lower voltage than one driving a tube screamer, and a guitar played in a funk style will get larger voltages in the initial attack than a guitarist lightly strumming some chords.
If at first you don't succeed... use bigger transistors!

MaxPower

How about a LiveTina-Ti? I also don't have NET 4.5 so that's that, but it is a cool idea.
What lies behind us and what lies before us are tiny matters, compared to what lies within us - Emerson

PRR

> what actually *is* the voltage of a typical guitar signal?

Under 20mV to over 1V.

You would not expect much "fuzz" for signals under 20mV, though the very-low (mostly decay) signal is important in other ways (perhaps compressors).

Very few pickups and players will hit 1V; however we also stack pedals and just one LPB or most wide-open fuzzes will blow over a Volt easy.

_I_ can read dB re:1V and know where I am, but I suspect many pedal-players won't.

100mV may be a good default. You expect most distorters to be distortable with a 100mV signal, but it isn't at all "excessive" such that a guitar alone couldn't get there.

> which components I should prioritize

Silicon transistors are all the same except Beta. Give something like a 2N3904 but with hFE variable 30 to 900. (You are realy unlikely to find a small Silicon as bad as 30, but you can use a huge part like 2N3055 at very-small current and get very-small gain.)

Likewise Zeners are all the same except their breakover voltage. Some difference in knee sharpness as you get under 6Vz; when you get bored, look-up some parts and scale the knee.

Diodes vary much more than theory explains. And the usual spec-sheet does NOT give the true performance, only a worst-case reject-line. Search this forum, the last few weeks, my user-name and "diode", I posted a graph with a few diode-plots.
  • SUPPORTER

dsharlet

Quote from: MaxPower on November 14, 2013, 01:09:04 AM
How about a LiveTina-Ti? I also don't have NET 4.5 so that's that, but it is a cool idea.
Is this something that exists? I can't tell for sure, it seems like their real time hardware interface might do what this does...
Quote from: PRR> what actually *is* the voltage of a typical guitar signal?

Under 20mV to over 1V.

You would not expect much "fuzz" for signals under 20mV, though the very-low (mostly decay) signal is important in other ways (perhaps compressors).

Very few pickups and players will hit 1V; however we also stack pedals and just one LPB or most wide-open fuzzes will blow over a Volt easy.

_I_ can read dB re:1V and know where I am, but I suspect many pedal-players won't.

100mV may be a good default. You expect most distorters to be distortable with a 100mV signal, but it isn't at all "excessive" such that a guitar alone couldn't get there.
This explains why I generally have to turn down the input gain on my simulations quite a bit to get reasonable amounts of distortion from the circuits I've tried simulating so far (tube screamer, boss SD1, etc.). I will adjust the default voltage mapping for the next release!

Quote from: PRRSilicon transistors are all the same except Beta. Give something like a 2N3904 but with hFE variable 30 to 900. (You are realy unlikely to find a small Silicon as bad as 30, but you can use a huge part like 2N3055 at very-small current and get very-small gain.)

Likewise Zeners are all the same except their breakover voltage. Some difference in knee sharpness as you get under 6Vz; when you get bored, look-up some parts and scale the knee.

Diodes vary much more than theory explains. And the usual spec-sheet does NOT give the true performance, only a worst-case reject-line. Search this forum, the last few weeks, my user-name and "diode", I posted a graph with a few diode-plots.
Thanks for the info!

To explain a little more about what I do in LiveSPICE, I have generic models of the components (Ebers-Moll for transistors, Shockley for diodes, etc.) where you can set any of the model parameters to any value you want. Then, I have specializations of these models in the library with preset values for the model parameters.

So, the worst case scenario is that you can add the generic Ebers-Moll transistor (or Koren triode, or similar for another component) and set up the gain you want. But, I still do want to add specializations for common components as I think most users (including myself!) do not want to hunt down the right gain value to use when building a circuit.

MaxPower

What lies behind us and what lies before us are tiny matters, compared to what lies within us - Emerson

alphadog808

#12
dsharlet,
 This is cool!!  However, I got this error when compiling your test low pass filter.  I think I did it right...sorry it's sloppy, it was the 4th time I redid the circuit.. :icon_mrgreen:

What did I screw up?



Here's the verbose output.
Building circuit...
Build: 0 errors, 0 warnings
Building solution for circuit 'X1', h=2.83 μs
[94.8 μs] Performing MNA on circuit...
[2.91 ms] Performing steady state analysis...
[45.8 ms] Performing transient analysis...
[53.9 ms] System solved, 1 solution sets for 5 unknowns.
[2.84 μs] Defining sample processing function...
Error: An item with the same key has already been added.
Building solution for circuit 'X1', h=2.83 μs
[94.8 μs] Performing MNA on circuit...
System of 5 equations and 5 unknowns = { _x1[t], _v1[t], _v0[t], _v2[t], _x2[t] }
  -1*_v0[t] + _v1[t] == V1[t]
  _x2[t] == -1*_v0[t] + _v2[t]
  _v0[t] == 0
  0.001*_v1[t] - 0.001*_v2[t] + _x1[t] == 0
  -0.001*_v1[t] + 0.001*_v2[t] + 1E-06*D[_x2[t], t] == 0

Found 0 simulation parameters = {}
[3.14 ms] Performing steady state analysis...
Initial conditions:
  _x1[0] -> 0
  _v1[0] -> 0
  _v0[0] -> 0
  _v2[0] -> 0
  _x2[0] -> 0

[6.45 ms] Performing transient analysis...
Differential equations:
  1E-06*D[_x2[t], t] + -0.001*_v1[t] + 0.001*_v2[t]

Integrated solutions:
  _x2[t] == 0.00141723*_v1[t] + 0.00141723*_v1[t0] - 0.00141723*_v2[t] - 0.00141723*_v2[t0] + _x2[t0]

Discretized system:
  -1*_v0[t] + _v1[t] == V1[t]
  _x2[t] == -1*_v0[t] + _v2[t]
  _v0[t] == 0
  0.001*_v1[t] - 0.001*_v2[t] + _x1[t] == 0
  _x2[t] == 0.00141723*_v1[t] + 0.00141723*_v1[t0] - 0.00141723*_v2[t] - 0.00141723*_v2[t0] + _x2[t0]

Linear solutions:
  _x2[t] -> 0.998585*_x2[t0] + 0.00141523*(V1[t] + _v1[t0]) - 0.00141523*_v2[t0]
  _v2[t] -> 0.998585*_x2[t0] + 0.00141523*(V1[t] + _v1[t0]) - 0.00141523*_v2[t0]
  _v0[t] -> 0
  _v1[t] -> V1[t]
  _x1[t] -> -0.000998585*V1[t] + 0.000998585*_x2[t0] + 1.41523E-06*_v1[t0] - 1.41523E-06*_v2[t0]

[19.2 ms] System solved, 1 solution sets for 5 unknowns.
[3.65 μs] Defining sample processing function...
Inputs = { V1[t], V1[t] }
Outputs = { -1*_v0[t] + _v2[t], -1*_v0[t] + _v2[t] }
Parameters = {  }
Error: An item with the same key has already been added.

dsharlet

#13
Thank you for trying it out!!

You definitely found a bug. The problem is most likely that you have two input channels, and more specifically that you have two input channels that are both mapped to the same input component.

There's a new release up on github that should fix this problem :)

It also has a new compiler that is up to 2.5x faster for some circuits! All of the sample circuits now run very comfortably in real time for me. For the first time since I started working on this, I can run every pedal circuit I've tried so far without lowering the oversampling factor!

This is something I need to fix, but in the meantime, I suspect the problem would be resolved if you went back to the audio configuration, and only turned on one channel at a time. You can use the test mode to make sure you have the right channel selected (the one that has the input signal you want).

Please let me know if that resolves it! I will post a new build in the next few days that will hopefully fix this problem the right way.


alphadog808

cool, I'll retry it tonight.  Did you have any default/standard layouts I could load for common circuits(tubescreamer, etc)?  It's not hard, but it would be nice to have a vanilla template already built.  This thing looks very cool!

ashcat_lt

With a basic consumer soundcard you might not be able to easily tell what voltage corresponds to what level ITB.  More serious interfaces will tell you, though you might have to do some math.  One of mine, for example, has nominal level = +4dbu with 18db headroom, which I take to mean that 0dbfs = +22dbu ~ 26V peak to peak.

dsharlet

Quote from: alphadog808 on November 14, 2013, 12:27:20 PM
cool, I'll retry it tonight.  Did you have any default/standard layouts I could load for common circuits(tubescreamer, etc)?  It's not hard, but it would be nice to have a vanilla template already built.  This thing looks very cool!
Yes, in My Documents\LiveSPICE\Examples there should be a few complete pedal circuits, pretty much the circuits I used as examples on the website. There's also a few other random example circuits in there.

I look forward to hearing about your experience!

PRR

> I have generic models of the components (Ebers-Moll

Cool. Fundamental. But it needs real-part numbers.

Here's a truncated list of numbers in a handy SPICE model:

.model Q2N3906-X PNP
Is=1.41f
Bf=180.7
Ne=1.5
Xtb=1.5
Br=4.977
Rc=2.5
Cjc=9.728p
Tr=33.42n
Rb=10

Is is actually critical, and roughly related to device-size, but "never" much use in the real world. Its effects are indirect and log. It is, in a sense, the "smallest" current we'll ever see, and many orders of magnitude below "normal currents". We get the other parameters near normal current. 

Bf, forward Beta, is the big deal. Old and high-voltage parts have Bf close to 50. General-purpose is 100-250, because that's plenty for most design. High-gain parts 200-800 or so.

Ne and/or XTB *may* be a fudge on how Beta varies with current. Beta falls at high and low current; one due to inefficient collection, the other because the crystal gets stuffed-up with carriers. The numbers in old models are often very pessimistic compared to modern production. Beta may change little from 10uA to 50mA. Which covers the range we expect in small-audio.

Br is (I think) reverse Beta. This matters in some pedals and switch-circuits. It is not a 4-digit-precision number. Assuming Br=2 will usually work.

Rc is intrinsic collector resistance and 2 Ohms is "nothing" for small-audio. You want a value so the math can't blow-up with "infinite" current. Rb, base resistance, affects low-hiss design but we almost never see anything other than a default "10" here (real values 2 to 50). I don't expect it to affect waveforms.

The many "C" parameters will affect extreme treble in high impedance circuits. Mostly swamped by other circuit capacitance.

Tr *may* be what we call Amplification Factor in vacuum triode. In modern BJTs the "amp factor" is at least 1000, and often much higher. Very unusual for it to affect voltage gain, and when it "is" the limit (as in CC-loaded stages) we can't realistically count on any specific number.

So I think if you grab sensible defaults for all parameters, and a Beta slider, it will quickly emulate the range of devices and circuits found in small audio.
  • SUPPORTER

dsharlet

Quote from: PRR on November 14, 2013, 11:51:22 PM
Cool. Fundamental. But it needs real-part numbers.

Here's a truncated list of numbers in a handy SPICE model...
Agreed! Thanks for the info. Looking more closely at the SPICE model you grabbed, I see that the parameters I support are a subset of the parameters of the SPICE model! This means it should be easy to just parse SPICE models and dump the parameters into my model. This way, I don't need to add specific parts, you should be able to just go get the spice model and drop it in a folder to use it.

I won't be able to distribute the models with LiveSPICE this way, but I think this is a common problem with SPICE. I've had to hunt down third party models for LTspice a few times before.

Also, thanks PRR and psychedelicfish for the info about real signal voltage. I'm going to change up the signal IO interface a bit in addition to that info. I also realized the GUI probably should allow you to choose audio channels for each component, not the other way around. This should also make it easy to enter test signal expressions for input components (instead of the actual audio channel).

PRR

http://bwrcs.eecs.berkeley.edu/Classes/IcBook/SPICE/UserGuide/elements_fr.html

"BJT Models
"The bipolar junction transistor model in SPICE is an adaptation of the integral charge control model of Gummel and Poon. This modified Gummel-Poon model extends the original model to include several effects at high bias levels. The model automatically simplifies to the simpler Ebers-Moll model when certain parameters are not specified. The parameter names used in the modified Gummel-Poon model have been chosen to be more easily understood by the program user, and to reflect better both physical and circuit design thinking.
"The dc model is defined by the parameters IS, BF... ... ... ... ..."


"Integral charge control"... Any fool can quickly estimate the DC actions. SPICE was developed to model FAST logic systems, basically to model how fast they can go. So there is a lot of attention to "charge", roughly the number of electrons (carriers) and how they move.

Post-1975 BJTs are much-much faster than audio. And we don't need the exact rise-shape of a pulse into a logic threshold, just the general decline at high frequencies. So a LOT of the available parameters in a full-fledged SPICE model are not too important to us.

One thing which is often not implemented in traditional SPICE BJT models, but can be important in dartboard-designed pedal circuits: emitter-base reverse breakdown voltage. In modern Silicon this is almost always 7V. If you put a base-emitter backward across 9V (with a limiting resistor!) it should show 7V. It should also hiss, reliably, but I would not expect general-purpose models to simulate that. Even with just 9V supply, a gain-stage or two into a grounded-emitter stage "could" put the E-B junction into breakdown, Zener mode. If not modeled, the peaks are not clamped and the distortion is less than real life.

Huh. I never noticed that EG, activation energy, can be forced to Germanium's value. I don't think that is all you have to do to model Ge transistors, especially the older ones which were far from "ideal". Also I suspect that IS is typically very different, and I don't know a good "typical".
  • SUPPORTER