preenfm Forum

PreenFM => preenfm2 and preenfm3 => Topic started by: matrix12x on June 08, 2014, 03:04:32 AM

Title: waveforms
Post by: matrix12x on June 08, 2014, 03:04:32 AM
Hi,
I am interested in possibly trying to program one or two more waveforms for the oscillators such as a formant or something. I have bee with the FM8 and really love the way an FM modulated formant sounds.

I was wondering how difficult this would be? I started looking at the code in waveforms.java. Also would there be enough room left for something like this?

Would a good starting point be the Shruthi-1 code in his oscillator.cc file?

Thanks,
John
Title: Re: waveforms
Post by: pld on June 08, 2014, 09:19:27 AM
I guess space is an issue if you want to add a waveform, see http://ixox.fr/forum/index.php?topic=63386.0
Otherwise it's not too difficult as long as it's just another lookup-table (check src/synth/Osc.cpp and Osc.h, and SynthState.h and .cpp for the OscShape enum and editing).

If the waveform is generated a runtime somehow, then it becomes a bit more complex :)
The shruti oscillator is a bit different since it's integer based (and avr-optimized) instead of float, but the basic principles are the same (phase accumulator, lookup, interpolation).
Title: Re: waveforms
Post by: matrix12x on June 08, 2014, 04:59:57 PM
Thanks. That link was great. I started looking at the tables and I see that they are normalized to +/-1 and that the values are float. How does one take a single cycle wave file and create a table of 1024 to 2048 entries from it? I am assuming I would have to start with a raw format file, but is it 8, 16 or 32 bit?

Is there possible a python script? I will definitely start searching.
Title: Re: waveforms
Post by: Xavier on June 09, 2014, 10:55:04 AM
Thanks. That link was great. I started looking at the tables and I see that they are normalized to +/-1 and that the values are float. How does one take a single cycle wave file and create a table of 1024 to 2048 entries from it? I am assuming I would have to start with a raw format file, but is it 8, 16 or 32 bit?

Is there possible a python script? I will definitely start searching.

No there's no python script.. What i do is i create directly the c arrays in java based on some series of sinusoid.
I'm afraid you'll have to find by yourself how to create your own arrays.

The waveforms are in the fast memory access of the STM32F4 (CCM). There's only 64Kb here and almost all is used.
So what you can do is to replace an existing waveforms (keep the sinusoid one for FM ;-).

Or you can add one or two in the regular memory... just remove the "__attribute__ ((section(".ccm")))" in the declaration in the wave.c file..
Will be slower and could produce some audio glitch when access in full polyphony with effects...

Xavier
Title: Re: waveforms
Post by: tIB on June 09, 2014, 09:30:05 PM
Forgive me for throwing out ideas that I have no concept of whether they are possible to realise, or the required skills to make them so but...

One of the things I love to do in the analogue world is FM with sine waves ran into wavefolders. I've often wonders what yamaha style 'FM' might sound like with the sine waves animated in this way- pretty amazing I'd have thought! I'd have thought realising that would take a ton of processing power though?

Imagine this sort of thing on 6 operators! https://www.youtube.com/watch?v=vXr01PSF7iw
Title: Re: waveforms
Post by: matrix12x on June 10, 2014, 12:44:18 AM

No there's no python script.. What i do is i create directly the c arrays in java based on some series of sinusoid.
I'm afraid you'll have to find by yourself how to create your own arrays.

The waveforms are in the fast memory access of the STM32F4 (CCM). There's only 64Kb here and almost all is used.
So what you can do is to replace an existing waveforms (keep the sinusoid one for FM ;-).

Or you can add one or two in the regular memory... just remove the "__attribute__ ((section(".ccm")))" in the declaration in the wave.c file..
Will be slower and could produce some audio glitch when access in full polyphony with effects...

Xavier

Thanks. I have my table now, normalized to +/-1. 1024 values. I am adding them to waves.c, but I have one quick question, do I need to format in 5 rows of equal size like you did? For my first attempt, I am going to load it into regular memory, and see what happens.

Title: Re: waveforms
Post by: matrix12x on June 10, 2014, 02:17:27 AM
Quick question, what is the tool chain that is required?
I am on OSX.
Title: Re: waveforms
Post by: pld on June 10, 2014, 07:31:48 AM
I've been using gcc-arm-none-eabi-4_7-2013q3 on OS X.
IIRC I did a 'brew install dfu-util' to be able to flash the board directly...
Title: Re: waveforms
Post by: pld on June 10, 2014, 11:10:28 AM
do I need to format in 5 rows of equal size like you did?
As long as the array has 1024 elements, the formatting shouldn't matter. But it is more readable in case have to re-count :)
How did you come up with the values?

Quote
For my first attempt, I am going to load it into regular memory, and see what happens.
Will be interesting.
If I find some time, I'll compile a debug version and measure the impact in cycles (unless Xavier has already tried that?).
Title: Re: waveforms
Post by: Xavier on June 10, 2014, 11:00:21 PM
Quote
For my first attempt, I am going to load it into regular memory, and see what happens.
Will be interesting.
If I find some time, I'll compile a debug version and measure the impact in cycles (unless Xavier has already tried that?).

The only measure i did (a while back) was that with regular memory i could not get 8 voices (of 6op) at the same time without audio drop out.
Since then, there were a lot of optimization (and i could even add a FX slot).
Don't know what the status is today.
Would be fast to test ;-)
remove "__attribute__ ((section(".ccm")))" from all wavetables and try to get audio glitch.
Title: Re: waveforms
Post by: matrix12x on June 11, 2014, 12:05:53 AM
I am installing the tool chain right now and should compile tonight. I'll let you know how it goes.
Title: Re: waveforms
Post by: matrix12x on June 11, 2014, 02:54:57 AM
after some trial and error I got it to compile. I am still getting some errors while compiling, but I still seem to get my bin file, and it installs fine and seems to run fine.

I started with just removing "__attribute__ ((section(".ccm")))" to get the current waveforms to run in regular memory.

How many simultaneous notes should I try and play before expecting a drop out?
Title: Re: waveforms
Post by: Xavier on June 11, 2014, 09:15:02 AM
If you have your bin file what you got are warnings and not errors.  ;)

Worst case scenario :
In the menu set all midi channel to "1" for the 4 instruments.
Set 2 voices per instrument and select algos 27 or 28 and a different FILTER for each.
Then press 2 keys at the same time !

If you remove the CCM attribute for a waveform, for a real test, specify your waveform for all the operators of all instruments.
Title: Re: waveforms
Post by: pld on June 11, 2014, 09:04:08 PM
So I just did a quick first test with no waveforms in CCM, algo 27 for each voice, HP filter, arp running and well, it doesn't sound pretty, but no obvious glitching (overclocked firmware).
But its too hot for me so I might have just re-flashed the same firmware twice ;)
Title: Re: waveforms
Post by: matrix12x on June 12, 2014, 03:55:19 AM
Same here.
overclocked, no waveforms in CCM. no filter. Algo 27 and 28. held down 2 keys.
I did not notice any glitches either.


I started adding my own wave and got this when I compiled. Any ideas?
src/synth/Osc.cpp:108:1: error: too many initializers for 'WaveTable [8]'

Title: Re: waveforms
Post by: pld on June 12, 2014, 08:03:35 AM
Same here.
overclocked, no waveforms in CCM. no filter. Algo 27 and 28. held down 2 keys.
I did not notice any glitches either.
Great. I'll try and get some better measurements at some point to see how close to the limit we are.

Quote
I started adding my own wave and got this when I compiled. Any ideas?
src/synth/Osc.cpp:108:1: error: too many initializers for 'WaveTable [8]'
You'll need to adjust #define NUMBER_OF_WAVETABLES in Common.h to 9.
Then add the type to enum OscShape in SynthState.h (before _LAST) and the name to the oscShapeNames list in SynthState.cpp:189 and you should be good to go.
Title: Re: waveforms
Post by: Xavier on June 12, 2014, 11:36:26 AM

What you can do is leaving the existing waveforms in CCM and adding your new one in regular RAM.
Not to run out of regular ram.


Title: Re: waveforms
Post by: matrix12x on June 14, 2014, 03:51:04 AM
Awesome!! got it working. added the new waveform.
heads up, on my mac, when I went to add the name to the oscShapeNames list in SynthState.cpp:189, my text editor kept on changing the character used for " and it would not compile. it took me a while to figure that  the character was being changed.

So basically what I did was sample a waveform I liked to use as raw material on audacity. Trimmed it to one cycle. Made it mono. used sample data export. I made sure that the single cycle was 1024 samples based on the sample rate and the frequency/pitch of the sound. Then I added a space and commas after every single entry using Excel.

Then I added this data to the waveforms.c. I then changed #define NUMBER_OF_WAVETABLES in Common.h to 9.

The I edited waveforms.java. Then added the type to enum OscShape in SynthState.h (before _LAST) and the name to the oscShapeNames list in SynthState.cpp:189.

I compiled. . . and yay!! lots of fun.





Title: Re: waveforms
Post by: pld on June 14, 2014, 08:49:44 AM
Great!
I wouldn't have thought to use Excel to convert data :D
Title: Re: waveforms
Post by: Xavier on June 14, 2014, 09:51:01 PM
and yay!! lots of fun.

I like this last line  :D

Title: Re: waveforms
Post by: lokki on January 03, 2018, 05:58:28 PM
old thread i know...

so is the procedure the same with the newer firmware (i want to try to add more than 6 new waves)? do i add to waves.c?
waves2.c is not needed, right? i can compile the firmware even if i rename/move this file. also no need to edit waveform.java, right?

thanks.

EDIT: nevermind i figured it out. but i overflowed ram by adding all the tables i wanted :-) hehe.