Author Topic: pFM3 voice allocation algorithm change / discussion  (Read 1077 times)

NickDS

  • Team member
  • *
  • Posts: 8
    • View Profile
pFM3 voice allocation algorithm change / discussion
« on: March 09, 2022, 04:08:00 PM »
Hello,
 
Recently I got a pre-built PreenFM3 from Van Daal, first of all very big compliment/thank you to Mr. Hosxe for the exceptional work and also to Van Daal, the metal Grey one is looking seriously fine!
 
I hope somebody can give me some help/hints how to install a little changed firmware on the PreenFM3. (I am working as a designer, mostly with video and photography, hope you have mercy with the noobish questions I have)
 
My Issue is:
While playing in 16 voice Poly mode, I realized that when playing the same Note/Chord repeatedly, the pFM3 occupies the same voice (also clearly visible in CPU/Voice usage), so while playing the same note it behaves like in mono mode. The effect is pretty obvious, the prior played note is stolen abruptly in the release by the new same note. Especially when playing with high velocity the big amplitude change is an inharmonic issue. Beside this effect, I would like to see/test how the pFM3 behaves, when the rule for playing the same note is the same like playing a different note.
 
In my sound setup I mostly use the DSI Tempest (as a drum machine and as an analog six Voice synth) and the FM Synth Yamaha TG77. So I compared the Voice algorithm of the two with the PreenFm3.
 
As for the TG77, I could observe that while repeatedly playing the same note with very long release, if the 16 voices are occupied, then the oldest is stolen by the new one.
 
The DSI Tempest is different. A quote from Tempest manual:
 
"Tempest’s voice allocation algorithm is unique in that voice allocation is determined by the VCA level of a sound — in other words, its relative amplitude. Instead of performing a round robin-type voice allocation, newly triggered sounds will steal a voice/sound that has the lowest amplitude level. In addition, if a note is “on” it will not be stolen."
 
Voice allocation algorithm of the PreenFM, posted by Xavier (it seems like it is the same on pFM3):
 
The logic in the first loop :
. is the note we ask is already paying => use same voice
. If a voice is not playing => use voice (I don't remember why we don't stop looping here :/ )
. If a voice is still playing but has been release => use it unless we find a not playing voice or an older note that is also realeased later in the loop
 
If we didn't find any available voice. We must chose one :Second loop....
. chose the older one but excludes voices that are about to start (isNewNotePending()).
 
Quote: https://ixox.fr/forum/index.php?topic=63544.0
 
 
So my try to experiment with this issue is, a friend excluded the part in the timbre.cpp code (located in preenfm3-0.109/firmware/Src/synth) for same note playing: Screenshot of the code change is in the attachement
 
 
I hope someone can help me out with the following questions:
 
Is the change in the timbre.cpp correct?
 
My first (noobish) approach was, I replaced the old timbre.cpp, then put the ca. 54mb "preenfm3-0.109" folder on the SD Card and the "p3_0_109.bin" file.  Flashed the firmware and tadaaa nothing happened… Then I came across the new word by the name "compile"… 
 
A general question: Do I need the 50mb folder for flashing the firmware? Or is the firmware .bin file sufficient for the firmware flash?

Is there a software for compiling the changed firmware folder?
 
 
Thanks in advance for every hint

Xavier

  • Administrator
  • Hero Member
  • *
  • Posts: 2136
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #1 on: March 13, 2022, 12:14:08 PM »
Hi,

Thanks for the nice words. That's always great to read people like their preenfm  8)

If you want to work on the preenfm3 firmware, the easier way is to use the stm dedicated IDE:
https://www.st.com/en/development-tools/stm32cubeide.html
I use version 1.5.1, so i don't know if that will work with newer version. But i think you can download older ones.
This IDE will take care of the editing and compilation of the new firmware.
It can also flash it on the preenfm3 but for that you need a ST-LINK board connected to the SWD connector on the main pfm3 board.

If you don't have a STlink, compile the firmware from the IDE.
And use the script here to create the bin file.
https://github.com/Ixox/preenfm3/tree/master/scripts
Then copy the bin on you SD card and flash it.

If you have to make many tests and many iterations of you change,  the STLINK board is the way to go ;)

The area you want to modify (voice allocation) is not straightforward as it has to work with Mono, multi, glide, unisound....
And also because to use a busy voice, the preenfm does not stop immediatly the note to avoid "click", it quickly fade out previous note and then play the new one (that's the isNewNotePending stuff).

Yes the code you modified is the correct one.

Don't hesitate to ask any questions, sorry for the delay on this first reply.
I'll really do my best to help people to customize the firmware :)

Xavier


« Last Edit: March 13, 2022, 12:17:41 PM by Xavier »

NickDS

  • Team member
  • *
  • Posts: 8
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #2 on: March 14, 2022, 11:08:55 AM »
Hi,

thank you for the reply and for the hints.
But I am struggling to create the .bin file for the SD Card. May be you know where the problem is. I will explain what I did so far.

- I installed the STM32CubeIDE 1.5.1, created a new workspace (checked copy project into workspace) and could load the project in which i only repelaced the timbre.cpp (import-existing Projects into workspace)
- then ctr+b to build all, i did this as debugLQFP144 and as release (did for each lib, bootloader preenfm3 twice..)

I am working on windows10, so i installed Cygwin64 to run the create_object.sh. But at this point the script can not find the needed files to work with. It just creates a pfm3_firmware__folder with two .cmd files... Do I have to put the create_object.sh into a special folder? (I tried it to run the script in a couple different locations with no luck)  Or am i completly wrong? This all is kind of pretty new for me, so please excuse my noobish questions. Even if I can`t/won`t edit the code any further, I would like to know the process how i can create a flashable bin of a changed firmware.

thanks for any hints.

Nick

« Last Edit: March 14, 2022, 08:33:16 PM by NickDS »

Xavier

  • Administrator
  • Hero Member
  • *
  • Posts: 2136
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #3 on: March 14, 2022, 09:09:18 PM »
Oh yes, I forgot about Cygwin to execute the bash script under windows. That's a lot of things to install.
But I think you're not far...

FYI : You only need to build as "Release".
In Eclipse, select the 3 project (preenfm3, bootloader, lib), right click -> Set Active -> Release.

After building, make sure you have a file called preenfm3.elf in firmware/Release/ folder.

You must run "create_object_new_bootloader.sh". (The other one copy the bootloader from previous version.)
In this script you need to update some command to fit your installation.
Make sure this line points to your IDE installation and that "arm-none-eabi-objcopy" exists on this path.
https://github.com/Ixox/preenfm3/blob/master/scripts/create_object_new_bootloader.sh#L4

In CygWin on windows i have something like :
Code: [Select]
OBJCOPY_BIN="/c/ST/STM32CubeIDE_1.5.1/STM32CubeIDE/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.7-2018-q2-update.win32_1.5.0.202011040924/tools/bin/arm-none-eabi-objcopy.exe"

This script also prints some information about what folder and what firmware version it will create. That can be helpfull to see what's wrong.
https://github.com/Ixox/preenfm3/blob/master/scripts/create_object_new_bootloader.sh#L44

Then a folder pfm3_firmware_0_109 should be created with the firmware file inside (p3_0_109.Bin) that you'll copy on the SD card to flash.

Hope that will help
« Last Edit: March 14, 2022, 09:22:38 PM by Xavier »

Xavier

  • Administrator
  • Hero Member
  • *
  • Posts: 2136
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #4 on: March 14, 2022, 09:27:56 PM »
Additional info :
Edit firmware/Inc/version.h
And you can modify the 2 lines as follow (Add a 'n' for example / n for Nick)
Code: [Select]
#define PFM3_FIRMWARE_VERSION "v0.109n"
#define PFM3_FIRMWARE_VERSION_STRLEN 8
Rebuild in eclipse.
And rerun the script above.

Your folder and firmware name will be named 0.109n.
And you'll also see this version at the top right after pressing the MENU button on your preenfm3.
That allows you to be sure you're actually running the firmware you just built.

NickDS

  • Team member
  • *
  • Posts: 8
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #5 on: March 15, 2022, 04:42:33 PM »
thank you Xavier for the instructions. as I changed the path of OBJCOPY_BIN it worked and the script created the .bin file succesfully.

a friend helped me to change the timbre.cpp a couple of times and i tested it on the pfm3. as you said, it is not that straightforward^^ playing the same note doesnt accupy the same voice anymore, but now when playing the same note twice, the note gets stuck in the sustain and at this point we couldnt find the reason for this effect. i guess from this point it gets deeper into the code.. i will keep you updated if there is progress!

Xavier

  • Administrator
  • Hero Member
  • *
  • Posts: 2136
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #6 on: March 16, 2022, 09:04:10 PM »
Yes i assume noteOff also has to be modified.
The current noteOff does not expect several voices playing the same midi note.

Maybe add a !isReleased test here.
https://github.com/Ixox/preenfm3/blob/master/firmware/Src/synth/Timbre.cpp#L429
Code: [Select]
                    if (!voices_[n]->isReleased()) {
                        voices_[n]->noteOff();
                        if (likely(!isUnison)) {
                            return;
                        }
                    }


So that you don't stop again the note that was already stopped before and let the other one playing.
I haven't tested so that's maybe more complicated thant that. (???).


If that does not work you can also try without
Code: [Select]
              if (likely(!isUnison)) {
                            return;
                        }


« Last Edit: March 16, 2022, 09:12:55 PM by Xavier »

NickDS

  • Team member
  • *
  • Posts: 8
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #7 on: March 17, 2022, 02:30:54 AM »
Thank you very much Xavier! your first suggestion worked perfect!

Playing the same note doesnt stuck anymore in the sustain. now playing the same note behaves like playing a different note and the last one gets stolen. (seemls like it is the last one...) pretty nice !

I tested it in 16 voice poly mode, works perfect.

In Sequencer multi mode it works also fine, tested it in real time sequencer in multi mode with two instruments playing (one instrument 10 voices and the other 6 voices) and also no problems in step sequencer.

Also played a bit with the Arpeggiator, seems to work fine, Octav, Division, Duration, seems to work like it should...

Tested the mono mode and the unison mode shortly, it seems like here are no problems too.

But i tested everything pretty roughly. I am going to test it more in detail and write the feedback here!
« Last Edit: March 17, 2022, 02:39:16 AM by NickDS »

lokki

  • Sr. Member
  • ****
  • Posts: 370
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #8 on: March 17, 2022, 07:52:56 AM »
Nice!

Could you then post your firmware here? Seems like an interesting variation, that I would like to try:)

NickDS

  • Team member
  • *
  • Posts: 8
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #9 on: March 17, 2022, 11:55:20 AM »
yes sure. new .bin is in the attachement
« Last Edit: March 17, 2022, 01:11:29 PM by NickDS »

Xavier

  • Administrator
  • Hero Member
  • *
  • Posts: 2136
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #10 on: March 18, 2022, 09:12:36 AM »
Oh it works... Great !   8)
Now i'm wondering if that should be the default behaviour.

NickDS

  • Team member
  • *
  • Posts: 8
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #11 on: March 18, 2022, 03:39:59 PM »
i think it should be the default behavior for the poly mode.
but the prior reuse poly algorithm has also its own benifits for some styles. maybe its nice to keep both and create an additional mode in the engine menu?! but i have no idea how complicated this is to include. but i can offer testing and compiling skills ha ;)

just in case, i attached the edited timbre.cpp file

i testet a bit more also in mono and unison mode with glide, I couldnt hear/find any complications...

i did i bit research on how Elektrons Digitone handles its voices:

VOICE STEALING The Digitone has eight voice polyphony. VOICE STEALING sets the rules for how voices are stolen (which voice is taken when you play a new note) when you use more than eight voices at the same time. Press / to select voice stealing mode.

CYCLE The first played note is stolen first.
TRACK Track priority. Notes played on track 1 has priority over notes played on track 2, 3, and 4. Track 2 notes over track 3, 4 Track 3 notes over track 4.
LO Lowest note is stolen first
HI Highest note is stolen first.

REUSE Selects if the same note played twice should reuse the same voice, or cycle to use another free voice.
ON Reuses the same voice. Useful for staccato effects and drums.
OFF Cycles to use another voice. Good for piano-like sounds and pads


quote from: https://www.elektron.se/wp-content/uploads/2020/06/Digitone-User-Manual_ENG_OS1.30_200613.pdf

« Last Edit: March 18, 2022, 03:56:19 PM by NickDS »