CoderLine / alphaSynth

A HTML5 software midi synthesizer written in C#
41 stars 14 forks source link

Pitch bends are synthesized wrong. #2

Closed Danielku15 closed 8 years ago

Danielku15 commented 8 years ago

The pitch bends are synthesized to low. Taking alphaTab as input having a 4 semitone bend, it rather sounds like a single semitone bend.

mbektimirov commented 8 years ago

Hi Daniel, Do you have any thoughts on this issue? How could this be fixed to process normal pitch bend sound? Maybe the problem is with this calculation: SynthParameters.cs#L148 ?

Danielku15 commented 8 years ago

Hi. I had a look at the calculation of the Pitch but it should be correct there. The equation should correctly calculate the cents required for the pitch. I think the real problem lies in the overall pitch calculation in this area: https://github.com/CoderLine/alphaSynth/blob/master/Source/AlphaSynth/Bank/Patch/Sf2Patch.cs#L101

My guess is that I need to apply the pitch bend separately instead of considering it simply as an additional pitch to the base note. Like this:

var basePitchFrequency = SynthHelper.CentsToPitch(voiceparams.SynthParams.CurrentPitch)*gen.Frequency;
var pitchWithBend = basePitchFrequency*SynthHelper.CentsToPitch(voiceparams.PitchOffset);
var basePitch = pitchWithBend / voiceparams.SynthParams.Synth.SampleRate;

This change already makes the bends sound correclty but I need to do some more tests whether the calculation is correct this way. According to here the pitch bend needs to act as an additional factor to the overall frequency. This is reflected by the mentioned change but I still have some doubts.

mbektimirov commented 8 years ago

Most times it works well, but on some tabs bends are not playing at all. Tested with this one: https://www.dropbox.com/s/ex393b85rd9jvm6/7-strings-demo.gp5?dl=0

Danielku15 commented 8 years ago

I just had a second look at this file. You are right that the bends of the GuitarPro file are not played correctly, but that's not a problem of alphaSynth. I just made a small test with the attached file. I exported it as Midi from Guitar Pro and played it via alphaSynth and it plays the bends correctly. This means the bug is rather on the bend generation done by alphaTab. I'm closing this issue and open another one on alphaTab.

BendTest.zip

https://github.com/CoderLine/alphaTab/issues/90