{"id":613,"date":"2017-05-26T00:30:31","date_gmt":"2017-05-26T07:30:31","guid":{"rendered":"http:\/\/www.earlevel.com\/main\/?p=613"},"modified":"2019-02-24T15:18:55","modified_gmt":"2019-02-24T23:18:55","slug":"guitar-amp-simulation","status":"publish","type":"post","link":"https:\/\/www.earlevel.com\/main\/2017\/05\/26\/guitar-amp-simulation\/","title":{"rendered":"Guitar amp simulation"},"content":{"rendered":"<p>In this article, I\u2019ll sketch a basic guitar amp simulator. For one, questions on the topic come up often, and also, it will be a good example of a typical use of working at a higher sample rate.<\/p>\n<p>The most basic guitar amp simulator has gain, with saturation, tone controls, and a speaker cabinet simulator. Because saturation is a non-linear process, the results are different whether the tone controls come before or after\u2014more on this later. The speaker cabinet, of course, comes last, and is an important part of the tone. Gain with saturation (the overdriven &#8220;tube&#8221;) is the tricky part\u2014we&#8217;ll start there.<\/p>\n<h3>Gain with saturation<\/h3>\n<p>Gain is simply a multiply. But we like to overdrive guitar amps. That means gain and some form of clipping or softer limiting\u2014that\u2019s what generates the overdrive distortion harmonics we want. Typically, we\u2019d ease into the clipping, more like tube saturation behaves, but the more overdrive gain you use, the closer it gets to hard clipping, as more of the signal is at\u00a0the hard limit.<\/p>\n<p>That&#8217;s where we hit our first DSP problem. Clipping creates harmonics, and there&#8217;s no way to say, \u201cPlease, only generate harmonics below half the sample rate.\u201d We <em>will<\/em> have aliasing. The added harmonics fall off in intensity (in much the same way as harmonics of a rectangular wave do), as they extend higher in frequency, but at typical digital audio sample rates, the Nyquist Frequency comes too soon. Aliased images extend back down into the audio range. We can\u2019t filter them out, because they mix with harmonics we want to keep. And because the guitar notes played aren\u2019t likely the be an integer multiple of the sample period, the aliased\u00a0harmonics are out of tune. Worse, if you bend a guitar note up, the aliased harmonics bend down\u2014that\u2019s where aliasing becomes painfully\u00a0apparent.<\/p>\n<p>Can we calculate clipping overtones and create just the ones we want? Can we analyze the input and output and remove frequencies that we don\u2019t want? That is not an easy task (left as an exercise for the reader!).<\/p>\n<h3>The oversampled solution<\/h3>\n<p>To mitigate the aliasing issue, the most practical solution is to give ourselves more frequency headroom <em>before<\/em> generating distortion harmonics with our saturation stage. If the sample rate is high enough, aliased images are spread far enough apart that the tones extending\u00a0into our audio range from above are diminished to the point they are obscured\u00a0by\u00a0the din of our magnificent, thick, overdriven guitar sound. And when we play delicately or with little\u00a0overdrive gain, so is the aliasing lessened.<\/p>\n<h3>How much headroom?<\/h3>\n<p>How much headroom do we need? I\u2019d like to leave that to your situation and experimentation\u2014mostly. But since I started doing this in the days when\u00a0every DSP cycle was a precious commodity, I can tell you that\u2014for 44.1 kHz sample rate, typically the worst case that we care about\u2014the minimum acceptable oversampling factor is 6x. 8x is a good place to start, and will be adequate for many uses, at a reasonable cost. (Do multistage oversampling for efficiency&#8230;but that&#8217;s another story.)<\/p>\n<p>Raising the sample rate &#8220;8x&#8221; sounds like we&#8217;ll have eight times the bandwidth, but it&#8217;s better than that. At our original 44.1 kHz sample rate, we\u00a0have a usable bandwidth of about 20 kHz (allowing for the conversion filters), and little\u00a0addition frequency headroom. If we go past 24.1 kHz\u00a0(44.1 kHz &#8211; 20 kHz),\u00a0aliasing\u00a0extends below 20 kHz. But by raising the rate to 8 times\u00a0the original, we have headroom of 352.8 kHz &#8211; 20 kHz, or 332.8 kHz.\u00a0That&#8217;s more than 80 times our original headroom.<\/p>\n<p>The idea is that we upsample the signal (removing anything not in our original audio band), run it though our tube simulator (clipper\/saturator), then drop the sample rate back to the original rate (part of this process is again removing frequencies higher than out original audio band).<\/p>\n<h3>How much gain?<\/h3>\n<p>Real guitar amps have a lot of gain. Don\u2019t think that if your overdrive is adjustable from 0-2 gain factor, you\u2019ll get some good overdrive distortion. That\u2019s only a maximum of 6 dB. More like 60 dB (0-1024)! Maybe up to something like 90 dB for modern, screaming high-gain amps. That&#8217;s equivalent to a shift of 15 bits, so I hope you&#8217;re using something better than a 16-bit converter (or tracks) to input your raw guitar sound.<\/p>\n<h3>The tube<\/h3>\n<p>My intent here is not to guide you down the road of yet another guitar amp simulator plugin, but to give an example of a task that needed more frequency headroom, requiring processing at a higher sample rate. But it\u2019s worth going into just a bit of detail on the tube (saturation) element. Again, we\u2019re talking about \u201cfirst approximations\u201d\u2014a hard clipper, or a soft one.<\/p>\n<p>A hard clipper is trivial. If a sample is greater than 1, change it to 1. If less than -1, change it to\u00a0-1.<\/p>\n<pre>if (samp &gt; 1.0)\r\n samp = 1.0;\r\nelse if (samp &lt; -1.0)\r\n  sample = -1.0;<\/pre>\n<p>Here\u2019s the transfer function\u2014for input sample values along the x axis, the output is on the y axis. For input { 0.5, 0.8, 1.0, 1.3, 4.2 }, the output is { 0.5, 0.8, 1.0, 1.0, 1.0 }.<\/p>\n<p><a href=\"\/main\/wp-content\/uploads\/2017\/05\/clipperTF-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-633\" src=\"\/main\/wp-content\/uploads\/2017\/05\/clipperTF-1.png\" alt=\"\" width=\"296\" height=\"127\" \/><\/a><\/p>\n<p>But for this use we\u2019d probably like a softer clip\u2014a transfer function that eases in to the limit. samp = samp &gt; 1 ? 1 : (samp &lt;= -1 ? -1 : samp * (2 &#8211; fabs(samp))); This is just a compact way of saying,<\/p>\n<pre>if (samp &gt; 1.0)\r\n  samp = 1.0;\r\nelse if (samp &lt; -1.0)\r\n  sample = -1.0;\r\nelse\r\n  samp = samp * (2 - fabs(samp));<\/pre>\n<p>This is a very mild, symmetrical x-squared curve. It\u2019s just an example, but you\u2019ll find it produces useful\u00a0results. You could try a curve that stays straighter, then curves quicker near +\/-1. Or a curve that\u2019s not symmetrical for positive and negative excursions. The harder the curve, the closer we get to our original hard-clipping.<\/p>\n<p><a href=\"\/main\/wp-content\/uploads\/2017\/05\/smoothTF.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-635\" src=\"\/main\/wp-content\/uploads\/2017\/05\/smoothTF.png\" alt=\"\" width=\"307\" height=\"127\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/smoothTF.png 307w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2017\/05\/smoothTF-300x124.png 300w\" sizes=\"(max-width: 307px) 100vw, 307px\" \/><\/a><\/p>\n<p>One detail worth noting: If you\u2019ve spent much time looking at discussions of this sort of non-linear transfer function on the web, usenet, or mailing lists, invariably someone points out that we know exactly what order of harmonics will be created, and therefore how much oversampling we might need, based on the polynomial degree. This is wrong\u2014in fact we\u2019re only using the polynomial between the bounds of x from -1 to 1, and substituting a hard clip for all other points. For a use such as this, the input is driven far into the hard clip region, so the polynomial degree is no longer relevant.<\/p>\n<h3>Tone controls<\/h3>\n<p>We know IIR filters well, so this part is easy. Typically, a guitar amp might have bass, mid, and treble controls. One catch is that if you want to sound like a particular vintage amp, they used passive filters that result in control interaction. That is, not active circuitry that isolate the components from each other. So, adjusting the bass band might affect the mid filtering as well. But that\u2019s fairly easy to adjust for.<\/p>\n<h3>More about overdrive and tone<\/h3>\n<p>Something worth noting. It you really want to scream with gain, you need to make some architectural adjustments. If you\u2019ve played much with raw distortion pedals with different instruments, you\u2019ve probably noticed that you get a \u201cflatulent\u201d sound with heavy clipping of bass. And high-gain distortion of signals with a lot of highs can sound pretty shrill. Guitar solos really scream when they have a lot of midrange distortion. So, if you really want to go for a screaming lead with loads of distortion without it falling apart into useless grunge, one thing you can do is roll off the lows and highs before the tube sim (distortion) stage. But then the result lacks body\u2014compensate by boost the lows and high back up, after the distortion stage. The point here is that you have three choices of where to put EQ for your amp tone: before the tube, after, or both.<\/p>\n<p>Some of your tone choices can be a property of the amp model\u2014not everything needs to be a knob for the user to control. These choices are what give a particular guitar amp its characteristics. A Fender Twin does not sound like a Marshall Plexi. The reason that well-known guitar amps are the basis of DSP-based simulation is that the choices of their designers have withstood the test of time. Countless competitors faded from memory, often because there choices were as compelling.<\/p>\n<h3>Cabinet<\/h3>\n<p>Similarly, guitar speakers gained familiar configurations not because the industry got together and chose, but these are the ones that worked out well.<\/p>\n<p>One characteristic of speakers for guitar amps is that they are not full range\u2014you\u2019ll find no tweeters in guitar cabinets. The highs of the large speakers used (most often 10&#8243; and 12&#8243;) drop off very quickly. A clean guitar tone doesn\u2019t have strong high frequency harmonics, and the highest note on a guitar is typically below 1 kHz. Overdrive distortion creates powerful high frequency harmonics, but we really don\u2019t want to hear them up very high\u2014extremely harsh and fatiguing to listen to.<\/p>\n<p>The first approximation of a speaker cabinet is simply a lowpass filter, set to maybe 5 kHz. I didn\u2019t say it would be a great cabinet, but it would start to sound like a real guitar amp combo. The next step might be to approximate the response of a real speaker cabinet, miked, with multiple filters.<\/p>\n<p>But if you\u2019re serious, a better start might be to generate impulse responses of various cabinets (4 x 12&#8243;, 2 x 10&#8243;, etc.), miked at typical positions (center, edge, close, far), with selected mics (dynamic, condenser). Then use convolution to recreate the responses.<\/p>\n<h3>Followup<\/h3>\n<p>To\u00a0moderate the size of this article, I&#8217;ll follow with images depicting the oversampling process in the next article.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, I\u2019ll sketch a basic guitar amp simulator. For one, questions on the topic come up often, and also, it will be a good example of a typical use of working at a higher sample rate. The most &hellip; <a href=\"https:\/\/www.earlevel.com\/main\/2017\/05\/26\/guitar-amp-simulation\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,4,6],"tags":[],"_links":{"self":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/613"}],"collection":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/comments?post=613"}],"version-history":[{"count":24,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/613\/revisions"}],"predecessor-version":[{"id":845,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/613\/revisions\/845"}],"wp:attachment":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/media?parent=613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/categories?post=613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/tags?post=613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}