Author |
Message |
BobTheDog
Joined: Feb 28, 2005 Posts: 4044 Location: England
Audio files: 32
G2 patch files: 15
|
Posted: Fri Oct 20, 2017 10:40 pm Post subject:
|
|
|
Good stuff.
That is a good milestone |
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Sat Oct 21, 2017 2:06 pm Post subject:
|
|
|
And another milestone - it's a polysynth now. Computed sines (not tables). I had set it for 16 voices, but my oxygen 25 controller doesn't output more than 10 note on messages. If 10 keys are held down, any new keypresses are ignored. I will have to test with a MIDI sequencer.
As a rough metric for how much CPU the synth is using, I have LED 1 (green) turn on while it's in the idle loop (where the MIDI controller lives) and it's turned off by the synth process. The longer the synth process takes to execute (i.e. more voices playing) the dimmer the green LED gets. It's noticable, but it's still rather bright. I can probably scope the LED to see what the on/off ratio is. There were no problems with the sound while doing this, so it looks pretty good. Obviously more features will slow it down, this is a rather featureless synth. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
BobTheDog
Joined: Feb 28, 2005 Posts: 4044 Location: England
Audio files: 32
G2 patch files: 15
|
Posted: Sat Oct 21, 2017 10:21 pm Post subject:
|
|
|
Good stuff |
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Tue Oct 24, 2017 9:17 am Post subject:
|
|
|
Something I learned today...
Accidentally using a double data type can be devastating to performance. I converted my computed sine organ to one that uses a sine table and linear interpolation to provide precise tuning. I accidentally forgot to include 'f' at the end of a float constant and the performance of the program went into the toilet (it did only 6 voices without crashing the synth). _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
BobTheDog
Joined: Feb 28, 2005 Posts: 4044 Location: England
Audio files: 32
G2 patch files: 15
|
Posted: Tue Oct 24, 2017 10:43 am Post subject:
|
|
|
There is a compiler flag to force floating literals to float rather than the default double, well worth using: -fsingle-precision-constant |
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Tue Oct 24, 2017 12:57 pm Post subject:
|
|
|
BobTheDog wrote: | There is a compiler flag to force floating literals to float rather than the default double, well worth using: -fsingle-precision-constant |
Yes, I know that works. I've got a thing about depending on any default conditions whether they are set by the compiler's internal defaults or ones I add with flags. I'd rather follow this rule an old doctor told me:
Never assume - Always be specific.
If I code with absolute specificity, I can then know what each literal type is - because it's explicit. For me, it's easier/better to see it in the code.
Using such a flag causes the code to look wrong, that is, we C programmers should know that unsuffixed literals like 1.4 are double. When such a flag is used, the 1.4 is float which would eventually confuse. This becomes especially important when looking at someone else's code - where you are pretty much forced to dig around in a makefile which is often not very friendly as well as downright ugly, especially when created by a project generator. I try not to use compiler flags to fix bad code I write. In my case, this problem was corrected by simply adding a single 'f' character to main.c. But as usual, different strokes for different folks. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
BobTheDog
Joined: Feb 28, 2005 Posts: 4044 Location: England
Audio files: 32
G2 patch files: 15
|
Posted: Tue Oct 24, 2017 10:19 pm Post subject:
|
|
|
The thing is it isn't bad code, for me it is a bad part of the language. In a strongly typed language such as C floating literals in my eye should be sized to destination variable size.
so:
float fValue = 0.0;
The literal should be a float not a double.
double dValue = 0.0;
The literal should be a double.
I know the compiler flag doesn't fix this but at least it fixes the problem when your FPU is only 32 bits and using doubles forces everything into software.
But as you say different strokes. |
|
Back to top
|
|
|
emeb
Joined: Dec 16, 2008 Posts: 35 Location: Arizona
|
Posted: Tue Oct 24, 2017 11:36 pm Post subject:
|
|
|
Nice to see you're making lots of progress with this. I've been coding on F7 for the last few months for some commercial projects in synth and it's working fairly well. One of the designs is running an F746 at full clock rate and I'm able to get about 32 oscillators with some fairly complex waveform calculations going simultaneously (along with all the modulation controls and a GUI).
It's not as easy to go big as when you're using a PC or RPi / etc. so you do have to work at optimization - take advantage of ITCM and DTCM to accelerate processor cycles and memory access, use DMA wherever possible, shut down stuff you're not using to conserve bus cycles, etc. Quite a brain teaser... |
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Wed Oct 25, 2017 4:10 am Post subject:
|
|
|
Very familiar stuff there emeb. Yesterday I worked on converting my computed sine organ to wavetable with linear interpolation. The computed sine synth was able to implement 17 voices while the wavetable version implements 33. My MIDI connection is via USART6 which I operate in "bare-metal" mode. SysTick timer is disabled which was a challenge since the original driver code needed SysTick for some delays it used during initialization of the CODEC. I'm also running the CPU at 216 MHz. This is pretty much featureless. With a single pole IIR low pass filter for click removal, the voice count drops to 31. And then of course, I find optimizations and it's back to 32 voices with the click filter enabled.
As for numerical literals, even though C doesn't force us to always suffix identifier names, I do it anyway. It is obvious to a human reader and the compiler can't do what a human might not expect. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Sat Nov 04, 2017 6:08 am Post subject:
|
|
|
I've now got a Karplus-Strong MIDI polysynth working. At present, the features are sparse including precise tuning and sustain, but no pitch bend yet. As such, the synth supports 28 voices.
I've been looking at the driver code for inefficiencies. The audio driver includes callbacks to allow filling the DMA buffers with new data. I've never liked callbacks because they burn call/return clocks, so I'm looking to see if I can eliminate the callbacks and use the ISR directly. I know it's only a few clocks, but every clock helps. Of course, there is the standard DO NOT EDIT THIS FILE... _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Thu Nov 09, 2017 9:04 am Post subject:
|
|
|
I had been wondering recently what the performance difference between float and int32_t would be so I wrote a very simple benchmark to test adds. I ran the test with the FPU enabled and disabled.
With all CPU caches disabled:
With FPU enabled, float types take about 3.8% longer than int32_t to do an add.
With FPU disabled, float types take about 72 times longer than int32_t to do an add.
With all CPU caches enabled:
With FPU enabled, float and int32_t types take nearly the same amount of time within about 0.1%. Some tests line items show float a bit faster, some show int32_t a bit faster.
The above tests were done with a loop of 100,000,000 iterations. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
emeb
Joined: Dec 16, 2008 Posts: 35 Location: Arizona
|
Posted: Fri Nov 10, 2017 8:36 am Post subject:
|
|
|
Nice research there. It's not immediately obvious to me why turning the cache on makes float math equal int math. Will have to think on that some... |
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Tue Nov 14, 2017 11:17 am Post subject:
|
|
|
More about my benchmark test:
On a whim, I decided to test using firmware version 1.4.0 and 1.8.0. Ultimately, there is no difference due to the firmware, but the two programs (identical C code) used different makefiles. It turned out that 1.4.0 used a different optimization level than the 1.8.0.
Here: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html I found great information on using gcc optimization and I was able to get all of the numbers to match for both test environments.
The reason I turned to optimization is that the loop times as well as the float and int32_t add times were quite a bit larger (more than 4 times slower) when optimization was default. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Tue Nov 14, 2017 2:44 pm Post subject:
|
|
|
Testing the new optimization effect on my Karplus-Strong poly synth - with default optimization, the synth would support 7 voices (under high stress conditions). With optimizations set to full, the voice count increased to 30. This (rather roughly) confirms that given a task with heavy arithmetic, with default optimizations, the STM32F746 runs about 4 times slower than with full.
It supports precision tuning, CC control over timbre, pitch bend to +12/-12 semitones and sustain. I will probably drop the voice count to 16 (or 24) to allow for chorus. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Wed Nov 15, 2017 2:14 pm Post subject:
|
|
|
Now a question:
I've been working on getting peak performance out of the STM32F746. One thing that seems to escape me is how to get gcc to use the DSP instructions. By using arm-none-eabi-objdump -d -S main.o I can get an assembly listing and it's clear that no DSP instructions are being used. The project contains 2 single pole IIR filters which should be able to use a vmla.f32 instruction, but it does not appear in the listing.
So the question is:
Is there a gcc option flag that I need to use to get gcc to use DSP instructions? _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
emeb
Joined: Dec 16, 2008 Posts: 35 Location: Arizona
|
Posted: Thu Nov 16, 2017 9:18 am Post subject:
|
|
|
JovianPyx wrote: | Now a question:Is there a gcc option flag that I need to use to get gcc to use DSP instructions? |
None that I've found. Generally gcc is pretty good about writing efficient code and doing smart things with optimization such as loop unrolling and taking advantage of pipelining. That said, it doesn't seem to always take advantage of the extra DSP instructions. For example, I've seen it use the integer multiply/accumulate instructions but it doesn't appear to properly infer the saturation operation. When I need saturation I often just use inline assembly to force it to use those.
You should take a look at some of the "intrinsic" functions in the CMSIS library - these are the DSP instructions wrapped up to look like inline C functions that you can slap down when you know they apply. Sometimes that helps, but more often than not I've found that there's not much to be gained.
Optimization is a dark art... |
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Thu Nov 16, 2017 9:58 am Post subject:
|
|
|
Thanks emeb,
Ok, that's just the way it is then. I'll first look at the DSP library, but I'll probably take a crack at writing my own filter with __asm just for "fun". All I need is a simple single pole low pass IIR filter. I've done it with the DSP instructions on a dsPIC in assembly language, so hopefully, I can make it happen with the STM32F746. For now though, the other optimization I've done gives at least acceptable performance. The DSP instructions won't double the voice count to be sure, but they may free up clocks I can use for various new features I'd like to add. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Fri Nov 17, 2017 5:47 pm Post subject:
|
|
|
emeb wrote: | You should take a look at some of the "intrinsic" functions in the CMSIS library - these are the DSP instructions wrapped up to look like inline C functions that you can slap down when you know they apply. Sometimes that helps, but more often than not I've found that there's not much to be gained.
Optimization is a dark art... |
I've been looking at the DSP library and now I wonder - is this just a set of well written C functions or do they actually cause gcc to insert instructions like vmla.f32 or vfma.f32? There seems nothing special in the code. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
emeb
Joined: Dec 16, 2008 Posts: 35 Location: Arizona
|
Posted: Sat Nov 18, 2017 5:53 pm Post subject:
|
|
|
The CMSIS DSP library doesn't have any special directives to force the use of certain instructions - it is as you surmise just a set of well written DSP functions. One might even debate how well written it is - it makes certain assumption about pipelining etc that may not apply across the whole Cortex Mx family.
When I mentioned "intrinsics" above I was specifically talking about the static inline functions defined in cmsis_gcc.h which allow you to access special CPU instructions as though they were actual C functions. |
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
Posted: Sat Nov 18, 2017 6:29 pm Post subject:
|
|
|
emeb wrote: | The CMSIS DSP library doesn't have any special directives to force the use of certain instructions - it is as you surmise just a set of well written DSP functions. One might even debate how well written it is - it makes certain assumption about pipelining etc that may not apply across the whole Cortex Mx family.
When I mentioned "intrinsics" above I was specifically talking about the static inline functions defined in cmsis_gcc.h which allow you to access special CPU instructions as though they were actual C functions. |
OH... thanks, I shall take a special look there. _________________ FPGA, dsPIC and Fatman Synth Stuff
Time flies like a banana. Fruit flies when you're having fun. BTW, Do these genes make my ass look fat? corruptio optimi pessima
|
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
|
Back to top
|
|
|
blue hell
Site Admin
Joined: Apr 03, 2004 Posts: 24079 Location: The Netherlands, Enschede
Audio files: 278
G2 patch files: 320
|
Posted: Sat Dec 09, 2017 5:51 pm Post subject:
|
|
|
Sounds good Scott, the distortion may a bit over done .. well .. to my current taste .. which may be different tomorrow .. the second version seems to have some more dynamics to me .. and overall, a good KS implementation! _________________ Jan
also .. could someone please turn down the thermostat a bit.
|
|
Back to top
|
|
|
JovianPyx
Joined: Nov 20, 2007 Posts: 1988 Location: West Red Spot, Jupiter
Audio files: 224
|
|
Back to top
|
|
|
|