{"id":914,"date":"2019-04-30T16:33:54","date_gmt":"2019-04-30T23:33:54","guid":{"rendered":"https:\/\/www.earlevel.com\/main\/?p=914"},"modified":"2020-10-01T20:51:26","modified_gmt":"2020-10-02T03:51:26","slug":"waveutils-updated","status":"publish","type":"post","link":"https:\/\/www.earlevel.com\/main\/2019\/04\/30\/waveutils-updated\/","title":{"rendered":"WaveUtils updated"},"content":{"rendered":"<p><a href=\"https:\/\/www.earlevel.com\/main\/2013\/03\/03\/replicating-wavetables\/\">WaveUtils<\/a> needed only a minor change for compatibility with the <a href=\"\/main\/2019\/04\/28\/wavetableosc-optimized\/\">WaveTableOsc update<\/a>\u2014addWaveTable changes to AddWaveTable. But I added something new while I was at it.<\/p>\n<p>The original wave table articles advocated minimizing the number of tables necessary\u2014one per octave\u2014by allowing a reasonable amount of aliasing. Aliasing that is not only difficult to hear, but is normally be removed in typically synthesizer applications by the synth&#8217;s lowpass filter.<\/p>\n<p>But that is simply a choice of the individual wave tables and how much of the spectrum we&#8217;re willing to let each cover. We could use more wave tables and allow no aliasing at all.<\/p>\n<p>In addition to the fillTables function, which builds active wave tables. I&#8217;ve added fillTables2, which accepts a minimum top frequency, and a maximum top frequency. For instance, we might want to support a minimum of 18 kHz, using a value of 18000 divided by the sample rate, so that harmonics are supported to at least that frequency. If we use 0.5 for the maximum, then no aliasing is allowed. Higher values allow aliasing. For instance, a value of 0.6 allows a top frequency of 0.6 times the sample rate, or 26460 Hz at 44.1 kHz sampling. That&#8217;s 4410 above half the sample rate, so aliasing can extend down to 17640 Hz (22050 &#8211; 44100). Another way to look at it is to subtract the value from 1 and multiply by the sample rate to get the alias limit, (1 &#8211; 0.6) * 44100 = 17640.<\/p>\n<p>Here are some examples. First, the original octave tables. To understand the spectrograms, time is left to right\u2014a 20 second sweep from 20 Hz to 20 kHz of a sawtooth. You can see the aliasing as harmonic frequencies bend down at the top, although the algorithm minimizes the aliasing with advantageous choices of switching frequencies at the highest sweep frequencies, where there is the least masking. This uses ten wave tables to sweep the ten octaves of audio from 20 Hz to 20 kHz.<\/p>\n<p><a href=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/Octave.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-917\" src=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/Octave.png\" alt=\"\" width=\"914\" height=\"486\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/Octave.png 914w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/Octave-300x160.png 300w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/Octave-768x408.png 768w\" sizes=\"(max-width: 914px) 100vw, 914px\" \/><\/a><\/p>\n<!--[if lt IE 9]><script>document.createElement('audio');<\/script><![endif]-->\n<audio class=\"wp-audio-shortcode\" id=\"audio-914-1\" preload=\"none\" style=\"width: 100%;\" controls=\"controls\"><source type=\"audio\/wav\" src=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/Saw-sweep-one-third-band-old-method-10-tables.wav?_=1\" \/><a href=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/Saw-sweep-one-third-band-old-method-10-tables.wav\">https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/Saw-sweep-one-third-band-old-method-10-tables.wav<\/a><\/audio>\n<p>I think the aliasing is masked pretty well. But if the idea of aliasing bothers you, and you want at least 18 kHz coverage, 34 wave tables will get you this, at 44.1 kHz sample rate:<\/p>\n<p><a href=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/18-kHz-no-alias.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-916\" src=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/18-kHz-no-alias.png\" alt=\"\" width=\"914\" height=\"486\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/18-kHz-no-alias.png 914w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/18-kHz-no-alias-300x160.png 300w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/18-kHz-no-alias-768x408.png 768w\" sizes=\"(max-width: 914px) 100vw, 914px\" \/><\/a><\/p>\n<audio class=\"wp-audio-shortcode\" id=\"audio-914-2\" preload=\"none\" style=\"width: 100%;\" controls=\"controls\"><source type=\"audio\/wav\" src=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/saw-sweep-18kHz-no-aliasing-34-wave-tables.wav?_=2\" \/><a href=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/saw-sweep-18kHz-no-aliasing-34-wave-tables.wav\">https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/saw-sweep-18kHz-no-aliasing-34-wave-tables.wav<\/a><\/audio>\n<p>Now for an asymmetrical example. If you want 18 kHz, but are willing to accept aliasing above 20 kHz, 24 wave tables will do it:<\/p>\n<p><a href=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/18-kHz-alias-20-kHz.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-915\" src=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/18-kHz-alias-20-kHz.png\" alt=\"\" width=\"914\" height=\"486\" srcset=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/18-kHz-alias-20-kHz.png 914w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/18-kHz-alias-20-kHz-300x160.png 300w, https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/18-kHz-alias-20-kHz-768x408.png 768w\" sizes=\"(max-width: 914px) 100vw, 914px\" \/><\/a><\/p>\n<audio class=\"wp-audio-shortcode\" id=\"audio-914-3\" preload=\"none\" style=\"width: 100%;\" controls=\"controls\"><source type=\"audio\/wav\" src=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/oscillator-test-18kHz-aliasing-above-20kHz-24-wave-tables.wav?_=3\" \/><a href=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/oscillator-test-18kHz-aliasing-above-20kHz-24-wave-tables.wav\">https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/oscillator-test-18kHz-aliasing-above-20kHz-24-wave-tables.wav<\/a><\/audio>\n<p><a href=\"https:\/\/www.earlevel.com\/main\/wp-content\/uploads\/2019\/04\/WaveUtils2.zip\">WaveUtils source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WaveUtils needed only a minor change for compatibility with the WaveTableOsc update\u2014addWaveTable changes to AddWaveTable. But I added something new while I was at it. The original wave table articles advocated minimizing the number of tables necessary\u2014one per octave\u2014by allowing &hellip; <a href=\"https:\/\/www.earlevel.com\/main\/2019\/04\/30\/waveutils-updated\/\">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":[26,24],"tags":[],"_links":{"self":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/914"}],"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=914"}],"version-history":[{"count":10,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/914\/revisions"}],"predecessor-version":[{"id":984,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/posts\/914\/revisions\/984"}],"wp:attachment":[{"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/media?parent=914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/categories?post=914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.earlevel.com\/main\/wp-json\/wp\/v2\/tags?post=914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}