Pitch, Tempo and Volume using FluidSynth
ClosedPublic

Authored by cedricbonhomme on Sep 8 2016, 3:17 PM.

Details

Summary

Use of the FluidSynth Library to set the pitch.
The documentations does mention that: 0 << pitch << 1024 * 16 - 1
The pitch slider has been set from 0 to 16
Changing the pitch has immediate effect.

The tempo has only been reactivated, it does work but needs the current question to be stopped() and played() again.

Diff Detail

Repository
R163 Minuet
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
cedricbonhomme retitled this revision from to Pitch and Tempo using FluidSynth.
cedricbonhomme updated this object.
cedricbonhomme edited the test plan for this revision. (Show Details)
cedricbonhomme set the repository for this revision to R163 Minuet.
cedricbonhomme added a reviewer: Minuet.
cedricbonhomme updated this object.
cedricbonhomme retitled this revision from Pitch and Tempo using FluidSynth to Pitch, Tempo and Volume using FluidSynth.
cedricbonhomme removed R163 Minuet as the repository for this revision.

Volume, change volume from 0 to 127 using the slider.
fluid_synth_cc(m_synth, 1, 7, m_volume) // change the volume (command 7), on the channel 1

sandroandrade edited reviewers, added: sandroandrade; removed: Minuet.Sep 12 2016, 2:43 PM
sandroandrade set the repository for this revision to R163 Minuet.
sandroandrade added a project: Minuet.
sandroandrade requested changes to this revision.Sep 14 2016, 2:54 PM
sandroandrade edited edge metadata.

Hi,

Could you please make the required changes?

Thanks for your patch :)

src/app/qml/midiplayer/MidiPlayer.qml
124

You'd better keep those from -12 (one octave below) to 12 (one octave above), since it's somehow implementation independent. And then make the required calculations in fluidsynth backend implementation.

138

Same here. Let's keep the volume slider ranging from 50% to 200% (default value 100%) and make the needed calculations in the fluidsynth backend.

This revision now requires changes to proceed.Sep 14 2016, 2:54 PM
cedricbonhomme edited edge metadata.

I've followed your recommendations.
Sliders have been set to:

  • 12/-12/0 for pitch
  • 200/50/100 for volume

The corresponding tunning for the fluidsynth lib are done in the setters.

sandroandrade requested changes to this revision.Sep 19 2016, 5:45 PM
sandroandrade edited edge metadata.

Hi,

Thanks again for your patch. It seems the pitch change implementation still misses something, though. Fluidsynth documentation says:

MIDI pitch bend value (0-16383 with 8192 being center)

However, the default configuration for pitch bend is to increase/decrease two semitones. You need to send a configuration MIDI event ("Controller Event") to set the value of the Data Entry MSB for pitch bends. That must be done only once, at sound backend initialization.

Check the section "Pitch Bend "Events" and the Data Entry MSB Controller" at:
http://www.infocellar.com/sound/midi/pitch-bends.htm

This revision now requires changes to proceed.Sep 19 2016, 5:45 PM
NOTE: to get the ability to pitch bend from zero down by one full octave (13 half steps in a chromatic scale = 6 ½ steps), use a value of 14, which allows you an just over an octave.
sandroandrade added a comment.EditedSep 20 2016, 2:52 AM

Actually, there is a much simpler implementation, with no need for using pitch bend events.
Just add the pitch drift in FluidSynthSoundBackend::prepareFromExerciseOptions. Something like:

...
appendEvent(1, chosenRootNote + m_pitch, 127, 1000*(60.0/m_tempo));
...
foreach ...
appendEvent(1, chosenRootNote + additionalNote.toInt() + m_pitch, 127, ((m_playMode == "scale") ? 1000:4000)*(60.0/m_tempo));

Actually, there is a much simpler implementation, with no need for using pitch bend events.
Just add the pitch drift in FluidSynthSoundBackend::prepareFromExerciseOptions. Something like:

...
appendEvent(1, chosenRootNote + m_pitch, 127, 1000*(60.0/m_tempo));
...
foreach ...
appendEvent(1, chosenRootNote + additionalNote.toInt() + m_pitch, 127, ((m_playMode == "scale") ? 1000:4000)*(60.0/m_tempo));

If we do so, we cannot change the pitch during an exercise. Should I use fluid_synth_pitch_bend with the Data Entry MSB Controller instead?

src/app/qml/midiplayer/MidiPlayer.qml
124

thank you for the review, I will edit them this week-end.

cedricbonhomme edited edge metadata.
cedricbonhomme removed R163 Minuet as the repository for this revision.

The documentation advise on setting Registered Param LSB and Registered Param MSB to 0.
The Data Entry MSB has been set to 14.
Those changes are done in the constructor of FluidSynthSoundBackend right after the definition of m_synth.

sandroandrade requested changes to this revision.Sep 21 2016, 7:36 PM
sandroandrade edited edge metadata.

My ears say some weird things are still happening :)

  • Pitch changes aren't working for semitones. Ex: there is no change in pitch when moving pitch from 0 to 1 (eg: from C to C#). It does work for a whole tone (eg: from C to D), i.e., when changing pitch from 0 to 2.
  • Also, when moving from 4 to 5 it's actually moving from 4 to 6. The change should be a semitone (eg: from E to F) but it's moving a whole tone (eg: from E to F#).

Could you try to figure out what is happening? I can give you some help if you find it hard to solve.

Thanks,

This revision now requires changes to proceed.Sep 21 2016, 7:36 PM
cedricbonhomme edited edge metadata.
This revision was automatically updated to reflect the committed changes.