waterjump / volca-share

:zap::musical_keyboard::zap: Share patches for the Korg Volca Bass synthesizer.
GNU General Public License v3.0
41 stars 6 forks source link

Ring modulation aliasing on keys emulator #43

Open waterjump opened 2 weeks ago

waterjump commented 2 weeks ago

TLDR: Ring mod causes frequencies above the audible frequency range that could result in audible harmonics because the sample rate is not twice as high as them. Impact: Medium to low Feasibility of fix: Uncertain give limitations of JS sample rate control.

Reddit user Lopiano suggested in a comment there's a potential for aliasing when ring mod is in use. I looked into it and I think it's possible and I observed the issue using the keys emulator using Audacity, not my ears.

Description of problem To over-simplify, when two waves are a part of a ring modulation algorithm, harmonics are added at the sum and the difference of the carrier wave and modulating wave. For example a 500 Hz carrier wave modulated by a 700Hz wave will result in harmonics at 1200 Hz and 200 Hz. In some scenarios, the harmonics created by modulation might exceed 22050 Hz, which is the Nyquist frequency of the standard 44100 sample rate of most Web Audio environments. When frequencies above the Nyquist frequency are sampled, they can result in aliasing, which would take the form of a harmonic at the value of 22010 minus the difference between it and the exceeding harmonic. Eg. - A 43100 Hz wave sampled at 44100 Hz would produce an alias wave at 1000 Hz. Image via "What is aliasing and the Nyquist theorem?" on YouTube

Screen Shot 2024-08-25 at 8 46 34 PM

What aliasing looks like in the keys emulator To start by only looking at fundamental frequencies of notes and ignoring pitch effects like detune, LFO etc, the three highest notes that can be played are A#8 with 7458 Hz, B8 with 7902 Hz, and C9 with 8372 Hz. Since the lowest note is always the carrier, the sum and difference of A#8 and B8 are 15356 Hz and 444 Hz, neither of which would cause aliasing because they're below 22050 Hz. But if that signal is modulated by C9, we could expect a harmonic at 23731, which would cause an alias harmonic at 20369. I have confirmed this by analyzing the spectrum in Audacity:

Screen Shot 2024-08-25 at 8 26 04 PM

Impact Although to me the aliasing in the test case in inaudible, and using notes that high is uncommon, the potential for aliasing is there. Strictly from the listener's perspective, I can't say this alone is a disruptive enough issue to address, but I will keep my ear out for aliasing and try to come up with more impactful cases. The likelihood of this being more prominent due to harmonics of the square wave and pitch modulation via detune, EG Int, LFO etc is high. The nature of the emulator itself is non-scientific and my personal opinion is that the poly ring mod is mostly a wildcard to begin with, so the margin for allowing aliasing is also high.

Potential solutions To minimize aliasing in ring modulation:

waterjump commented 2 weeks ago

Following up with another test case that is audible and easily observable in Audacity, playing the three highest notes in poly ring voice with LFO pitch intensity turned all the way up shows clear aliasing. Patch to recreate

Screen Shot 2024-08-25 at 8 53 44 PM