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

NickDS

  • Guest
pFM3 voice allocation algorithm change / discussion
« on: March 09, 2022, 04:08:00 PM »
Hello,
 
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.
 



« Last Edit: May 15, 2023, 08:20:11 PM by NickDS »

Xavier

  • Administrator
  • Hero Member
  • *
  • Posts: 2256
    • 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 »

Xavier

  • Administrator
  • Hero Member
  • *
  • Posts: 2256
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #2 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: 2256
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #3 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.

Xavier

  • Administrator
  • Hero Member
  • *
  • Posts: 2256
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #4 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 »

lokki

  • Sr. Member
  • ****
  • Posts: 383
    • View Profile
Re: pFM3 voice allocation algorithm change / discussion
« Reply #5 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:)

Xavier

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