Circuit modeled filter, how to?

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

Physics Simulations is exactly what I've done in the past and by reading this I've been learning how applicable it is to circuit modelling for audio signals.

It seems like our approaches are from opposite sides and I'm trying to find out where the best place is for those to meet.

Previously, my main concern has been accuracy, but I've had computers costing 6 figures behind me so I've not had to worry about processing power.

I've recently been running the same code on home PC's and found them acceptable but unable to run multiple instances.

By finding out what approximations have been tried, I can find out how relevant my current code is.

BTW: My research was on modelling the noise levels in RF circuits and applying solutions from Chaos Theory (the time evolution of non-linear differential equations) to error analysis.

I also juggle (but not very well).

Cheers,
Nigel

Post

"I applogise if I confused you in my previous post by textually getting the circuit not quite right, hopefully the graphical circuit will remove any ambiguities in what I was trying to say."

edit/remove: i'm ranting on here. i'll just write the code to demonstrate and post that once i have. my point is just that in order to get that effect from code, the code must do the same thing as the circuit. there isnt any magic going on in the circuit, it just requires that you apply the table in a difference place, other than at the output of the integrator. (hint: inside the integrator. hint: delta.)

Post

aciddose wrote:there isnt any magic going on in the circuit, it just requires that you apply the table in a difference place, other than at the output of the integrator. (hint: inside the integrator. hint: delta.)
What gave you the impression "magic" was going on in the first place? Not sure what point you are trying to make here.

Making simplifications to the way you model things is step 4 in my list that I posted previously. I'm not trying for a quick fix solution here but hopefully it will help people get a handle on things. Posting psuedo code like: lp += gain*shaper(in - lp) doesn't give much insight into analog modeling imho. Such psuedo code skims past the fact that to generate the shaper function you need some tricky maths.

Shall we try and focus on giving a fuller and more rounded take on analog modeling so that people can learn for themselves instead of posting tidbits of information and pretending that things are way easier than they are for people learning this stuff? If they want a quick fix perhaps they should just pay you for some code and ignore the pesky problem of analog modeling all together?

Andrew

Post

"Such psuedo code skims past the fact that to generate the shaper function you need some tricky maths."

what, you mean like shaper(n)=n*(2-abs(n))

for a majority of situations that shaper is accurate enough. certainly for the ota filter he is talking about in this case. the major issues are with the functions to handle the four sample delay of the feedback. more complex shaper functions are just going to be a few of the one above in-series shifted around and scaled, the results can be stored in a small table.

i understand your points here, maybe you do not understand mine. for a beginner, let's not over complicate the issues at hand and make ourselves look like wizards. dsp is not magic, nor is electronics engineering. if you have better code to share to show him how simple things are i'd also be one who would love to see it.

i'll add another paragraph because i feel this is really important:

the guy has never seen a schematic before. he has never worked with electronics and possibly never used any analog synthesizer. he has never written a filter taking into account any of the factors that are important in 'modelling' before. he has however seen all the marketing BS and technical jive-talk people use to blow up their egos and make themselves feel important. the majority of filters out there could have been written by a preschooler, including mine. the facts are that in reality there is no real "modeling" going on most of the time and when there is it barely gets noticed. don't lead the guy on into this BS myth, of "virtual analog" and so on. most of the coders around are still patting themselves on the back for merely implementing the simplest possible functions.

if you've got code to prove me wrong, show it.

Post

by the way andy, if my post seems angry, it is a bit but that isnt aimed at you. it's aimed at the state-of-mind in general around a lot of dsp stuff. you know what i mean when i refer to the marketing BS that gets put out there. it's one thing when somebody says "i decided to make teh best plugin evar!!!11oneone" and you learn they dont even know c, but in this case everybody seems to talk a whole lot about how amazingly difficult this stuff is and they're happy to list off a ton of things you "need" without posting any helpful advice or code examples.

if these people making these lists of what you need to know, know all these things on those lists, why dont they start by posting some code examples?

that was my point really. and also: it isnt nearly as complicated as many people make it out to be. even the top-of-the-line code out in view is child's play here in dsp - obviously i dont know what some closed code looks like but the products out there are not all that much better from the stuff based upon well known functions either. if you or anybody else has some code they'd like to share to show all these amazing models and so forth i can tell you there are a lot of people who would be happy to read that code and listen to everything the author has to say on the subject.

Post

aciddose wrote:the guy has never seen a schematic before. he has never worked with electronics and possibly never used any analog synthesizer. he has never written a filter taking into account any of the factors that are important in 'modelling' before. he has however seen all the marketing BS and technical jive-talk people use to blow up their egos and make themselves feel important.
...do you find schematics useful?

Post

yes.. in general. it depends really upon what you're referring to though. do i find them much useful for 'modeling'? no, because generally cpu use is a far greater concern than accuracy and i'm very happy to have simple code that works and does so at a reasonable speed.

for electronics? i design my own circuits and draw my own schematics.. schematics in general are obviously useful yes. "schematic" is really just another term for "technical drawing". do i find schematics of existing electronics useful? i used to when i was first learning the basics of electronics engineering, but i find fewer and fewer unique circuits these days. once in a while you'll find a really good circuit idea out there, but for the most part once you've got things down looking at the designs of others isnt so useful anymore. when i'm comparing my designs to others however, just out of curiosity for the most part, yes i've found it to be useful to verify that i'm on the right track with my designs.

the other day for example i was curious about how the sh- synths provide lfo delay triggering. you must retrigger the lfo delay on cv changes except when the final key is released. the sh- series uses summation of the trigger (generated from cv delta) and gate signals so that negative gate cancels out the trigger occurring at that point. my implementation is different: i use a trigger shaper/delay circuit followed by a AND of gate+trigger to produce triggers which only occur during positive gate. my implementation is far more accurate and far more stable, however the sh- implementation requires fewer semiconductors meaning less pins on the layout and it for the most part "just works" in a fixed system. i would definitely use my circuit in a modular, however i may switch to using a similar trig+gate summation method where accuracy isnt important.

yes, schematics are useful. when you're just beginning to learn about these things however, it's my opinion that a very simplified dsp method should be used and the nuances of more/less accurate methods should be learned later on. for somebody who doesnt have electronic experience i think schematics might confuse the person like hell, which is never good.

Post

aciddose wrote:...what, you mean like shaper(n)=n*(2-abs(n)), for a majority of situations that shaper is accurate enough...
Not for me it isn't. I'm not into skimping on sound quality to save a few cycles. I'm all about high quality models. If you don't have enough cpu, but another one. If you still don't have enough then freeze the track or render the high quality version offline and just preview with the low quality one. Did you listen to any of the example .mp3 files I posted? Have you checked out the free synth Orca that I wrote? Or are you just happy to blaze away at me in the mistaken belief that I'm one of those "marketing BS and technical jive-talk people use to blow up their egos and make themselves feel important" types? I'm trying to write high quality synths and effects, and it does take effort and it does take maths, I'm not going to pretend otherwise.
aciddose wrote:...the major issues are with the functions to handle the four sample delay of the feedback...
Yes. Like I said previously all the nonlinear stuff takes a back seat to getting the linear version working first for all you tuning of resonance and frequency. Wait a second shall I copy that here as well so we can say the same thing N times: "In the end all models linear or not will have a unit sample delay in feedback loops (which are always in analog circuits) that you will need to compensate for."

I'm not trying to make things sound any different than they are. I have stated clear steps you should take to do a high quality analog model. I am letting those that read decide at what level they want to approach this stuff, I'm not assuming anything.
aciddose wrote:... more complex shaper functions are just going to be a few of the one above in-series shifted around and scaled, the results can be stored in a small table...


I would recommend that you use the qucs table export function and simply use linear interpolation for complex waveshaper functions.

aciddose wrote: i understand your points here, maybe you do not understand mine. for a beginner, let's not over complicate the issues at hand and make ourselves look like wizards. dsp is not magic, nor is electronics engineering.
It seems you are obsessed with magic, I'm way more practical than that sorry. I have not overcomplicated anything, I have stated clear steps so that people can know what is involved and work it out for themselves. Posting code does not help people work things out. When you post code you are un-helping people since they don't know how to derive the code. How is someone supposed to know if a waveshaper function is good enough or not? How do they know to waveshape the voltage difference on the capacitance when using forward euler (which can be unstable at high frequencies) to integrate a circuit? It seems you want to preach to these people and only offer them little chunks of code since they are too stupid to sort it out themselves by your own admissions.

I have loads of algorithms that I will be sharing in the future about SVF corrections, x-pander filter taps, the ms-20 filter and more. I'll be writing these papers as soon as some products are out the door and I have some time to dedicate to adding to the shared knowledge base. I have posted code before about the svf code, but I think it did more harm than good. People just copy and paste it without any understanding or furthering of dsp, there are now just millions of crappy sounding filter plugins is all. Great.


aciddose wrote: i'll add another paragraph because i feel this is really important:

the guy has never seen a schematic before. he has never worked with electronics and possibly never used any analog synthesizer. he has never written a filter taking into account any of the factors that are important in 'modelling' before.
So are you saying in short "the guy" doesn't stand a snowflakes chance in hell of understanding circuits and doing a high quality model of one? Nice. Very helpful of you.

aciddose wrote:... the facts are that in reality there is no real "modeling" going on most of the time and when there is it barely gets noticed... if you've got code to prove me wrong, show it.
I definitely notice it. If you are talking about the majority of KVR users I agree, they don't know the difference most of the time. Marketing BS is very shitty and annoys the crap out of me to no end. I am not a marketing crap kinda guy. You want some code? How about the backward euler solution to a stereo envelope follower type circuit? Wow this will help everyone so much:

http://rafb.net/p/sIIGbI90.html

Andrew

Post

Hey Andy,

Thanks for the insight! It's definately helpful for me!

I suppose that AD simply doesn't know who you are, what you do and how. Hope to see you at Messe - maybe I'm gonna introduce you to George. He is still reluctant on picking up analogue models but after meeting you he'll probably obey.

Cheers,

;) Urs

Post

Urs wrote:Hey Andy,

Thanks for the insight! It's definately helpful for me!

I suppose that AD simply doesn't know who you are, what you do and how. Hope to see you at Messe - maybe I'm gonna introduce you to George. He is still reluctant on picking up analogue models but after meeting you he'll probably obey.

Cheers,

;) Urs
No worries Urs, my pleasure. Lets definitely meet up at Messe, I won't be at a booth, just free wheeling. Hopefully I'll have some fun new toys for you to play with. :)

Andrew

Post

"since they are too stupid to sort it out themselves by your own admissions."

i've never said such a thing - this is YOUR problem.

i know exactly who you are and i've heard your software. i was specifically talking about it. who the hell is going to use complicated methods for very simple functions like those? it's rediculous to have to pay thousands of dollars for a system just to run a little titty envelope follower, "modeled" or not.

Code: Select all

#include <stdio.h>
#include <math.h>

const double pi = 3.1415926535897932384626433832795;

inline float aprox1(float i, float d, float r)
{
 i /= r;
 return r * i * fabsf(i);
}

inline float aprox2(float i, float d, float r)
{
 i /= r;
 return r * (i / (fabsf(i) + d)) * (1.0+d);
}

int main()
{
 double ihz = 440.0;
 double i = 0.0;
 long cps = (long)(48000 / ihz);
 double id = 2.0 / (double)cps; 

 long samples = 2000;
 
 {
  FILE *o = 0;
  if (!(o = fopen("output.raw", "wb"))) ;
  else
  {
   i = 0.0;
   long n = samples + 1;
   float a = 0.0;
   float f = 1.0 / 10.0;
   short sample = 0;
   while (--n > 0) 
   {
    i += id;
    if (i > 1.0) i -= 2.0;
    float in = sin(i*3.1415)*0.5;
 
    float d = in - aprox1(a, -1.08, 0.7);
    a += f * d;

    sample = (short)(d * 32767.0);
    fwrite(&sample, 1, 2, o);
    sample = (short)(a * 32767.0);
    fwrite(&sample, 1, 2, o);
   }
   fclose(o);
  }
 }

 return 0;
}
whoopdie doo, real complicated. i've wasted quite a bit of time trying to fiddle with the "real diode equation" but for all practical purposes even the first 'approximation' of n*n is accurate enough. after 30 minutes i decided "who gives a shit" and didnt include the correctly tuned diode equation.

Post

explaination for the above code for others, which doesnt try to sound like some wizardry:

the voltage stored across the integrating capacitor is not clipped by the diode clamp, however the voltage seen across the resistor which decides current flowing into that capacitor IS. therefore we simply apply the saturation function to the stored level, or 'a' in the code and this gives perfect results.

Post


Post

aciddose wrote:"since they are too stupid to sort it out themselves by your own admissions."

i've never said such a thing - this is YOUR problem.
You posted psuedo code, why? If they could work it out themselves you wouldn't need to post psuedo code would you?
aciddose wrote:i know exactly who you are and i've heard your software. i was specifically talking about it. who the hell is going to use complicated methods for very simple functions like those? it's rediculous to have to pay thousands of dollars for a system just to run a little titty envelope follower, "modeled" or not.
I love it when people give maths euphemisms like "titty", I would prefer nippley myself but thanks. (removed a bit about thousands since I worked out you meant for a computer to run it on - see the "not optimised code" comment please)

So. I posted code like you asked. This code is in no way optimised and I currently don't use it in any products. All the little v1, v2 etc are voltages, all the little variables like id1, id2 are currents, you can probe them, graph them, check against the analog hardware with them etc. In short, it's an "analog model". Is this proof enough?

Once you understand what is going on in the circuit you can make simplifications to suite how much cpu you want to use, and which bits of the circuit are the most critical to spend cpu on for your application. In fact I have already simplified the diode equations in the code I posted to not include the reverse breakdown, self noise, etc, but I'm not pretending this stuff doesn't exist and isn't important, that is a judgment call that each particular dsp developer needs to make for themselves, and not have someone who thinks they know better make it for them.

In a compressor circuit the exact shape of the attack is critical to the sound. Being able to solve for this with less than one sample feedback loops is also critical for some compressors. All this an more you can do with analog modeling, and all of it isn't too hard, but it does take work and some maths.
aciddose wrote:(schematics)...useful for 'modeling'? no, because generally cpu use is a far greater concern than accuracy and i'm very happy to have simple code that works and does so at a reasonable speed.
I think schematics are a fantastic source of inspiration to take on board when doing dsp, people have worked long and hard on these things and I value their work.

I love all these dogmatic statements you keep coming up with. Have you done market research to back up such statements like "cpu use is a far greater concern than accuracy"? You seem quite young and passionate, which is a good thing, and I look forward to you releasing some serious plugins. If you have done so already please let me know what they are so I can check them out.

Well it seems BFD2 is doing ok, and people like the sound of the compressors in it. I haven't done any market research, but musician friends of mine can definitely hear the difference between cpu friendly approximations and high quality circuit models. Even if many people can't tell the difference I'm happy to push in what I view as a good direction for the quality of audio processing in the future as processors become more and more powerful.

Aciddose, good luck to you in the future, and all the best,

Andrew

Post

what i posted wasnt pseudo code though, it is functional code. i didnt assume he was "stupid", i assumed he was intelligent enough to plug in the missing bits himself. he has written quite a lot of code.

the currents/voltages thing is interesting and all, but are you simulating a circuit, or doing dsp? nobody is going to give a damn about accurate currents and voltages inside your code because they never see them. nobody will even give a damn about currents and voltages in hardware because most of the time they never see them. if you were doing a modular, or a synth designed to be modified by it's owners who are electronics hobbyists that is one thing, but you're dealing in software here.

my code does the same thing, only it doesnt need to meddle with voltages and current. the 'd' delta value represents current, in a way, and the 'a' value represents voltage across the capacitor. sure, if you wanted to do a complicated emulation of a organ for example where envelope circuits are constantly being switched in/out and in some cases the stored _charge_ across the capacitor actually matters that is another thing all together. i just really do not see the use in telling a guy like williamk that he needs to go through an electrical engineering course for several years to write a nipply little piece of code, as you'd prefer i phrase it.

yes, yes, there are issues with accuracy. in dsp however i think we need to be more concerned with what we hear, not with the numbers running around in the cpu. a simulation taking into account currents, voltages and all possible minor environmental effects in a circuit isnt always going to sound reasonably improved against an approximate version. it's all an issue of diminishing cost vs. benefit. i appreciate very much if you try to make things as accurate as possible in your software, at the expense of extra cpu power or whatever else. that is your decision to make and if it produces results you're satisfied with by all means, it's a good direction for _you_ to go in.

i just have really serious doubts that the OP intended that sort of stuff when he posted the thread. he asked "how to", not "which courses should i take for the next five years".

if you're interested in any of the nonsense i've done it should be easy to locate via google or here on kvr. when i say nonsense i really mean it as i do not take software all that seriously. i'm actually not one to take audio stuff in general all that seriously as i fear when you do so you're leaning into the $5,000 wooden knobs and gold plated blingbling $10,000 speaker cables direction. in my opinion instruments and audio processing gear, outside of serious industrial or scientific communities, are only toys. the primary issue is going to be how fun the toys are, not how accurate the "V-ELECTRIX patented analog modeling technology (tm)" is.

- unless you're appealing to that crowd who believe those things are important. the $10,000 speaker cable crowd. hey man, if you're making the bucks off those people i'm not going to say you're a bad guy; you're a smart guy.

Post Reply

Return to “DSP and Plugin Development”