Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #3816 - FM or heavy PM in TripleOscillator makes output… #5651

Merged
merged 1 commit into from
Sep 10, 2020

Conversation

DigArtRoks
Copy link
Contributor

…s odd for some target waveforms.

The internal waveforms of the class Oscillator produces the wrong amplitude when the input is a
negative phase. When doing PM or FM, negative phases may occur. When a negative phase is e.g. passed
to the the saw sample, it produces values less than -1.0, hence going out of range.

Converted all fraction calls to absFraction calls.

Removed the +2 in the function Oscillator::recalcPhase. The comment here was that it was needed to avoid
negative phases in case of PM. But by converting fraction to absFraction in the waveforms, negative phases
are not an issue anymore. On top of that the m_phase variable gains about 2 extra bits in precision.
As side effect of that, it improves the behaviour of the issue #2047 - TripleOscillator: Oscillators are getting out of sync.
Though I did not investigate it thoroughly over different notes and samplerates.

Add documentation to the fraction and absFraction functions in lmms_math.h as it was not immediately clear by the name what the
functions do. Correct the implementation of the functions in case the flag __INTEL_COMPILER is set. (floorf rounds always down).

…tputs odd for some target waveforms.

The internal waveforms of the class Oscillator produces the wrong amplitude when the input is a
negative phase. When doing PM or FM, negative phases may occur. When a negative phase is e.g. passed
to the the saw sample, it produces values less than -1.0, hence going out of range.

Converted all fraction calls to absFraction calls.

Removed the +2 in the function Oscillator::recalcPhase. The comment here was that it was needed to avoid
negative phases in case of PM. But by converting fraction to absFraction in the waveforms, negative phases
are not an issue anymore. On top of that the m_phase variable gains about 2 extra bits in precision.
As side effect of that, it improves the behaviour of the issue LMMS#2047 - TripleOscillator: Oscillators are getting out of sync.
Though I did not investigate it thoroughly over different notes and samplerates.

Add documentation to the fraction and absFraction functions in lmms_math.h as it was not immediately clear by the name what the
functions do. Correct the implementation of the functions in case the flag __INTEL_COMPILER is set. (floorf rounds always down).
@LmmsBot
Copy link

LmmsBot commented Aug 22, 2020

🤖 Hey, I'm @LmmsBot from github.com/lmms/bot and I made downloads for this pull request, click me to make them magically appear! 🎩

Linux

Windows

macOS

🤖
{"platform_name_to_artifacts": {"Linux": [{"artifact": {"title": {"title": "(AppImage)", "platform_name": "Linux"}, "link": {"link": "https://8400-15778896-gh.circle-artifacts.com/0/lmms-1.2.2.691-linux-x86_64.AppImage"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/8400?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}], "Windows": [{"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://8399-15778896-gh.circle-artifacts.com/0/lmms-1.2.2.691-mingw-win32.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/8399?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://8398-15778896-gh.circle-artifacts.com/0/lmms-1.2.2.691-mingw-win64.exe"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/8398?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}, {"artifact": {"title": {"title": "32-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/dbkauo3i7hidjcpo/artifacts/build/lmms-1.2.2-msvc2017-win32.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/34794903"}, {"artifact": {"title": {"title": "64-bit", "platform_name": "Windows"}, "link": {"link": "https://ci.appveyor.com/api/buildjobs/2v7rxinptpba1hi2/artifacts/build/lmms-1.2.2-msvc2017-win64.exe"}}, "build_link": "https://ci.appveyor.com/project/Lukas-W/lmms/builds/34794903"}], "macOS": [{"artifact": {"title": {"title": "", "platform_name": "macOS"}, "link": {"link": "https://8396-15778896-gh.circle-artifacts.com/0/lmms-1.2.2.691-mac10.13.dmg"}}, "build_link": "https://circleci.com/gh/LMMS/lmms/8396?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link"}]}, "commit_sha": "43fb609d5061f46bad4a5aff5bd889677ea34579"}

@DomClark
Copy link
Member

Code looks good, and I approve of the changes in principle, but what effect does this have on existing presets and projects? TripleOscillator is one of the more commonly used synths in LMMS, so we don't want to change its behaviour too much.

@DigArtRoks
Copy link
Contributor Author

DigArtRoks commented Sep 10, 2020

FYI - The fix will affect only the sound when:

  • FM is used, as this may generate negative phases for the modulated oscillator
  • or PM is used, but the impact is less, because in the function recalcPhase() they already did some compensation (+2) to avoid negative phases. (But this is no longer needed as the fix now uses absFraction for all the primitive waveforms.)
  • the volume of the modulating oscillator is turned high
  • the waveform of the modulated oscillator is different from sine wave and custom wave (these 2 handled negative phases already correctly before the fix)

The resulting sound will be less distorted compared to before.

@DomClark
Copy link
Member

It's probably fine then, since turning the volume of the modulating oscillator up high tends to produce objectionable noise anyway. I checked all the built-in presets and couldn't notice any difference between this PR and 1.2.2, so I'm happy with this.

@Spekular Spekular merged commit 5f4d0ca into LMMS:master Sep 10, 2020
@DigArtRoks DigArtRoks deleted the fix_3816 branch September 11, 2020 20:20
sdasda7777 pushed a commit to sdasda7777/lmms that referenced this pull request Jun 28, 2022
…tputs odd for some target waveforms. (LMMS#5651)

The internal waveforms of the class Oscillator produces the wrong amplitude when the input is a
negative phase. When doing PM or FM, negative phases may occur. When a negative phase is e.g. passed
to the the saw sample, it produces values less than -1.0, hence going out of range.

Converted all fraction calls to absFraction calls.

Removed the +2 in the function Oscillator::recalcPhase. The comment here was that it was needed to avoid
negative phases in case of PM. But by converting fraction to absFraction in the waveforms, negative phases
are not an issue anymore. On top of that the m_phase variable gains about 2 extra bits in precision.
As side effect of that, it improves the behaviour of the issue LMMS#2047 - TripleOscillator: Oscillators are getting out of sync.
Though I did not investigate it thoroughly over different notes and samplerates.

Add documentation to the fraction and absFraction functions in lmms_math.h as it was not immediately clear by the name what the
functions do. Correct the implementation of the functions in case the flag __INTEL_COMPILER is set. (floorf rounds always down).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FM or heavy PM in TripleOscillator makes outputs odd for some target waveforms
5 participants