Page 1 of 2
Tube stage emulation.
Posted: Mon Jul 24, 2023 11:26 am
by Emil
Not long ago I came across the article "Digital Modeling of Guitar Amplifier Preamp Distortion" (
https://www.ampbooks.com/mobile/dsp/preamp/). There, as an example, the waveshaper included in the Line 6 patent is given. I was interested in the transfer function consisting of three mathematical expressions. On closer examination, it turned out that the mathematical expressions presented in the article, intentionally or not, contained an inaccuracy in the description of the first function.
After some effort, this expression was refined and rewritten. Writing the triode emulation function in C++ was easy, but transferring the function to Flowstone DSP Code took much more effort. Anyway, I could not find a detailed manual on how to use Flowstone DSP. In the end, here is my solution. Spice simulation from the same article was added to the file.
Re: Tube stage emulation.
Posted: Mon Jul 24, 2023 7:52 pm
by martinvicanek
Hey Emil,
thanks for sharing, and welcome to the forum! Yes, FS documentation is a bit incomplete, but you seem to have succeeded anyway.

In case of doubts you can always ask on this forum and people will be glad to help. All in all, we are a nice crowd.
Curious to see more from you here!
Re: Tube stage emulation.
Posted: Mon Jul 24, 2023 9:40 pm
by Emil
martinvicanek wrote:Hey Emil,
thanks for sharing, and welcome to the forum! Yes, FS documentation is a bit incomplete, but you seem to have succeeded anyway.

In case of doubts you can always ask on this forum and people will be glad to help. All in all, we are a nice crowd.
Curious to see more from you here!
Thank you very much for your support! I am not a programmer, but a musician with some experience in making tube guitar amplifiers. Now the task is to improve and build the obtained waveshapers into a guitar amplifier simulator with full-fledged dynamics. But before that it is necessary to work out guitar Tone Stacks. I think 40% of the sound depends on them. Besides, there are SAG, DUMP, DEPTH, etc. in the Power amplifier. The ultimate goal is to make VST Amp Sim. That's actually why I chose FS. This is not a commercial project, so I will publish everything I create on the forum. And I would like to have feedback.
Re: Tube stage emulation.
Posted: Tue Jul 25, 2023 6:50 pm
by martinvicanek
I agree that filtering (pre and post) is very important. In the meantime, since you asked for feedback, I have simplified your wave shaper math somewhat and also provided optimized ASM implementations. You can check the transfer curves inside. I have also included 4x oversampling. You can see that it removes aliasing at high gain quite a bit.
Keep it up!
Re: Tube stage emulation.
Posted: Wed Jul 26, 2023 6:04 am
by Emil
martinvicanek wrote:I agree that filtering (pre and post) is very important. In the meantime, since you asked for feedback, I have simplified your wave shaper math somewhat and also provided optimized ASM implementations. You can check the transfer curves inside. I have also included 4x oversampling. You can see that it removes aliasing at high gain quite a bit.
Keep it up!
I am impressed with the optimization of the DSP code and converting it to assembler! The FFT Display clearly shows even harmonics and the oversampling removes odd harmonics as far as possible, although it increases the CPU load. And if the number of tube stages as in modern amplifiers is 4 or 5, won't the processor be overloaded?
Re: Tube stage emulation.
Posted: Wed Jul 26, 2023 8:26 am
by R&R
I REALLY have no business being in this thread at all since i'm not versed in these advanced matters. MV knows
But had to take a listen to your distortion Emil

sounds nice...
Noticed also the math was very cpu taxing even after MV's magic
CPU spike is enough to crash my FS 3.08 on initialization of ASIO out... well, if I don't increase latency (for ASIO4ALL). But it might be a bit better performing on real ASIO sound device?
FS4 alpha handles it better but CPU is round 12% on my light laptop (11th gen i7)
Makes me curious (for my own learning as well) what operation in the math (or the logic rather) that FS has trouble with...
Emil wrote:And if the number of tube stages as in modern amplifiers is 4 or 5, won't the processor be overloaded?
Would be from the distortion/tube stages themselves. Unlikely MV's oversampling is loading on the CPU. I use atleast 3 of them in my synth plugin without even putting a dent on CPU (atleast to speak of).
All stages would be placed inbetween/inside only one 4x oversampling I guess... am I right?
Re: Tube stage emulation.
Posted: Wed Jul 26, 2023 9:39 am
by adamszabo
The CPU usage is caused by the analyzers (spectrum analyzer and the scope). If you delete them I only get around 1% cpu on my very old laptop. If you use them in an actual plugin without the analyzers it shouldnt use any cpu at all.
Re: Tube stage emulation.
Posted: Wed Jul 26, 2023 9:57 am
by martinvicanek
Emil wrote:The FFT Display clearly shows even harmonics and the oversampling removes odd harmonics as far as possible
No, oversampling does not remove odd harmonics, it removes aliases. Play with the Frequency knob holding down the Shift key and watch the direction in which each of the peaks goes. Those that move backwards are aliases. You should also be able to hear it, especially those below the fundamental.
Here is a linear frequency plot:

- 4x_oversampling.png (103.61 KiB) Viewed 24532 times

- no_oversampling.png (108.7 KiB) Viewed 24532 times
The harmonics, whichever even or odd, are not affected by oversampling. The second image shows a multitude of frequencies in addition to the harmonic series. They are all aliases, the red arrows highlight the most prominent ones.
Emil wrote:if the number of tube stages as in modern amplifiers is 4 or 5, won't the processor be overloaded?
I don't think so. On my laptop readings are 1.5% for the non oversampled and 2.5% for the oversampled waveshaper. The increase is not necessarily proportional as you add more stages, and yes, the up- and downsamplers would probably be used only once, while everything in between would be oversampled. The details depend on what else you want to incorporate, but at this pont I would not be concerned about CPU load.
Oh, one thing: When you do measurements, remove everything that is not needed: the "Transfer Curves" module, the FFT and the Scope!
Re: Tube stage emulation.
Posted: Wed Jul 26, 2023 10:40 am
by R&R
adamszabo wrote:The CPU usage is caused by the analyzers (spectrum analyzer and the scope). If you delete them I only get around 1% cpu on my very old laptop. If you use them in an actual plugin without the analyzers it shouldnt use any cpu at all.
LOL

bad observation, sorry about that! Yep I get only 1-2% cpu without that spectrum analyzer
Re: Tube stage emulation.
Posted: Thu Jul 27, 2023 12:09 pm
by Emil
Hi all! Some time ago I read an article about replacing vintage Fender 12AX7 input stage with a solid-state (
https://runoffgroove.com/fetzervalve.html#toc) and assembled the circuit shown there. I looked at the oscillogram and decided to repeat it using DSP means. Here's what I got. Oscillograms practically coincide.