electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » Arduino
Pursuing Karplus-Strong
Post new topic   Reply to topic
Page 1 of 2 [48 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Goto page: 1, 2 Next
Author Message
MapacheRaper



Joined: Feb 15, 2018
Posts: 166
Location: Spain

PostPosted: Sat Dec 01, 2018 7:02 am    Post subject: Pursuing Karplus-Strong Reply with quote  Mark this post and the followings unread

Im becoming more and more addicted to the arduino thing. Near obsessed.

This time with the karplus-strong algoridtm. A lot of voices says that is impossible to achieve due the memory limitations to get a delay line, but Meng Qi has one outstanding sounding module that only uses arduino and a few opamps.

After researching the web for two whole days, there is no code, no examples. So our chinese friend has done a perfect black box.

By the way, the module sounds like this:

http://detroitunderground.net/modular/du-krpls/

It seems apart of Meng Qi no one has achieved or shared code for this, apart of this oscure sketches-ideas

https://forum.arduino.cc/forums.html?topic=18889.0

So if anyone has some ideas on how to program it, (or discuss about the possibility or not to develop it, philosophicaly speaking with an apple in the hand) I would love to do an open source version of the module or just discuss it to let the ideas free flow
Back to top
View user's profile Send private message
Grumble



Joined: Nov 23, 2015
Posts: 1308
Location: Netherlands
Audio files: 30

PostPosted: Sat Dec 01, 2018 8:38 am    Post subject: Reply with quote  Mark this post and the followings unread

Could you plz elaborate how the karplus algorythm looks like?
I have a e-m karplus strong module in my rack, but are always struggeling to get a nice sound because I don’t know how exactly the karplus strong patch works.
I have made some small boards with an atxmega32e5, which has 4kb sram (atmega328 like the arduino uno has 2kb) but better, the xmega has 2 adc on board and dma! which would make it very much more suitable for making a delay as the uno.
I must admit that I don’t use the arduino ide, but atmel studio instead. Luckely the atmel studio and arduino ide work very well together, which is convenient if I want to use a library for instance for using an oled display

_________________
my synth
Back to top
View user's profile Send private message Visit poster's website
MapacheRaper



Joined: Feb 15, 2018
Posts: 166
Location: Spain

PostPosted: Sat Dec 01, 2018 1:02 pm    Post subject: Reply with quote  Mark this post and the followings unread

Cool, I didn´t event thought in different options than the nano and attiny85 that are the ones that I have.

I would take a look at that processor. The double memory and DACs sound like a great idea. In fact, today I have been thiking in a bigger processor/memory combo/resolution DACs to achieve more ambitious projects as wavetable oscillators, but let´s left that for another moment.

Taken from the wikipedia:

Quote:
Karplus–Strong string synthesis is a method of physical modelling synthesis that loops a short waveform through a filtered delay line to simulate the sound of a hammered or plucked string or some types of percussion.

At first glance, this technique can be viewed as subtractive synthesis based on a feedback loop similar to that of a comb filter for z-transform analysis. However, it can also be viewed as the simplest class of wavetable-modification algorithms now known as digital waveguide synthesis, because the delay line acts to store one period of the signal.

Alexander Strong invented the algorithm, and Kevin Karplus did the first analysis of how it worked. Together they developed software and hardware implementations of the algorithm, including a custom VLSI chip. They named the algorithm "Digitar" synthesis, as a portmanteau for "digital guitar".


Posted Image, might have been reduced in size. Click Image to view fullscreen.

So basically, is just a short burst of noise filtered, delayed and feed backed. It does nice strings, percussions and strange things in between.

The delay has to be really short, for example the PT2399 doesnt do karplus because the even the smallest setting is too long for this technique
Back to top
View user's profile Send private message
gabbagabi



Joined: Nov 29, 2008
Posts: 652
Location: Berlin by n8
Audio files: 23

PostPosted: Sun Dec 02, 2018 12:58 am    Post subject: Reply with quote  Mark this post and the followings unread

without deeper knowledge about the method, means sorry if the following is useless:

how short has the delay to be?
if u sample with lets say 20khz = one sample 50µs and have 1k RAM than u have a buffer for 51,2ms.
the 2399 goes down to 20ms?

i could imagine that the filter-calculation could be the problem, dunno if atmels have a hardware multiplier?

the sample thing is of course if u use analog noise, if u take internal or external digital noise - that could make things easyer, no need for DAC

or may u could push the analog noise thru a comparator (PWM) and than somehow store only the pulse/pause duration values?
Back to top
View user's profile Send private message
Grumble



Joined: Nov 23, 2015
Posts: 1308
Location: Netherlands
Audio files: 30

PostPosted: Sun Dec 02, 2018 6:52 am    Post subject: Reply with quote  Mark this post and the followings unread

And if you keep the filtering and adding/subtracting in hardware outside the processor?
_________________
my synth

Last edited by Grumble on Sun Dec 02, 2018 7:50 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
JovianPyx



Joined: Nov 20, 2007
Posts: 1988
Location: West Red Spot, Jupiter
Audio files: 224

PostPosted: Sun Dec 02, 2018 7:48 am    Post subject: Reply with quote  Mark this post and the followings unread

I've done extensive work with Karplus-Strong (KS), but I've stayed away from small and slow CPUs such as AVR (Arduino). I worked first with FPGAs, then to dsPIC (16 bit CPU), then to Raspberry Pi 3 and now to STM32F7 CPUs. In those environments I was able to get respectable voice count. One FPGA design has 192 voices, the dsPIC design has 12 voices, the Pi has 32 as does the STM32. There are also numerous features to extend the usefulness including a chorus (3 voice) at the output, pitch bend (over MIDI) and a method that causes string pitch tuning to be very precise. KS as an integer process has tuning issues where as pitch increases, tuning is more and more coarse to the point that you can't keep it in tune even with itself.

In my implementation, it's all digital. The filter, the delay line, everything. The MIDI controller runs as a task within the same CPU that is producing the sound. You can also search EM for an implementation done by Les Hall (was Inventor, is now Creator I believe). His implementation used a BBD as a delay line and his filter was a voltage controlled single pole low pass filter. In a digital implementation, I'm sure it's possible to put the filter outside the CPU, but that becomes expensive and large as the voice count increases. There is also the issue of getting the signal out of the CPU chip and then back into it - that would be cumbersome and slow and quite honestly doing the computation using 32 bit single precision floating point is going to sound at least as good as an analog filter and more possibly sounds better as at the very least, it will have far better noise characteristics (better signal to noise ratio). (no, I am not one who bows at the alter of analog) Using a device like an ARM such as STM32, you have 32 bit native computation with an FPU that computes single precision floating point add, subtract and multiply operations in one CPU cycle. The STM32 series is so inexpensive it just makes sense to use it for cost as well as speed.

My code for these systems is Verilog for FPGA, assembly language for dsPIC (using 16 bit fixed point arithmetic) and C for Pi and STM32, so for that level, the code is no more difficult than it is for AVR.

As for the delay line, the ones I use are less than 1024 locations in length depending on the pitch required.

The filter is there to strip harmonics off of the waveform circulating in the delay line. My experiments have shown that there's really just two types of filters that work well. Those are the original KS filter which as a 2 sample averaging filter and a simple single pole lowpass filter. Filters with faster falloff such as SVF cause the harmonics to die off so fast that there's no timbre change over time to be heard and the notes that come out are very short. It is noteworthy that while the original KS filter is very fast (2 adds and one divide by 2), it is not tunable which is why I use a single pole low pass filter. Changing the filter's cutoff changes the timbre of the waveform KS produces.

KS is useful for making string like sounds, probably the easiest to get is a sound that is very close to a natural harp. Tonal drums are also possible when the filter cutoff is set low. However, when the filter cutoff is changed, it also changes the amount of delay which causes pitch change. The drum tonal pitch is enough lower that you notice it being flat.

_________________
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
View user's profile Send private message Visit poster's website
ixtern



Joined: Jun 25, 2018
Posts: 145
Location: Poland

PostPosted: Tue Dec 04, 2018 4:25 am    Post subject: Reply with quote  Mark this post and the followings unread

JovianPyx wrote:
I've done extensive work with Karplus-Strong (KS), but I've stayed away from small and slow CPUs such as AVR (Arduino). I worked first with FPGAs, then to dsPIC (16 bit CPU), then to Raspberry Pi 3 and now to STM32F7 CPUs...

Thanks for your comments. They are very interesting. I have a STM32F746N Discovery board laying bored on the shelf but still has no time to make some programming with it. Maybe some day I'll do it although I like to work with hardware more than with software (as I have and had too much software programming in the work).
Back to top
View user's profile Send private message
MapacheRaper



Joined: Feb 15, 2018
Posts: 166
Location: Spain

PostPosted: Tue Dec 04, 2018 9:56 am    Post subject: Reply with quote  Mark this post and the followings unread

Sorry for the delay in response!!. I have been busy developing a frankenstain of quantizer slash turing machine in the atmel. It is working now but it needs some adjusting and finetuning yet... I will post it when is more mature.

Cool posts, guys, let´s see:

@Gabbi
In fact this is the most relevant question!. I don´t know what the range of delay times works for this nor how to implement filters in arduino (yet), but I will find it and post it.

Edit:

Quote:
in KS pitch depends of the delay time

you want to know the period (time in wich the wave complete 1 cycle)

wave period = 1 / frequency (Hz)

for A = 400 Hz then 1 /440 = 0.002272727272727... seconds


So something between 1/50=0.2 secs (for 50hz) and

1/15000=0.0000066666666 secs (for 15Khz). I guess until 2-5Khz should be enought for this implementation, so the shortests should be around 0.0002s

To my knowledge, Meng Qi is using just the arduino PWM output with a RC filter, so no need for DACs. Also the noise is digitally generated.

How I know this? Because he has another 2 karplus implementations, one of them is DIY and I took a peek at the BOM. I´ll be posting all this in some hours, I have to go out now

Edit: The BOM of one karplus DIY module by Meng Qi:

https://modularaddict.com/mengqi-little-karp-kit

ATMEGA328P-PU
LM386

Plus caps and resistors

Quote:
i could imagine that the filter-calculation could be the problem, dunno if atmels have a hardware multiplier?


Pfff, no idea... LOL. What is a hardware multiplier and why we need one?? Hahahah. I´ll take a look at that. Im guessing it´s going to be crucial to know about HW multipliers...

@Jovian
Cool, in fact really interesting!. Im going to take a good look at the STM32F7, as I would love to go deeper into the DSP thing. I have a background as a OO programmer (in web and interactive environments) so I feel confortable coding, but I have never do nothing remotely related to DSP before, so there´s a lot of things to learn first. For example, implement a filter.

For this project, and as long as Meng Qi has demostrated that is possible to develop a really nice sounding KS in arduino, I will like to replicate it, I mean via a different code, but to achieve similar results. Hopefully. (!).

The pros are that arduino is a easy entry point and doing it opensource will help others to add his grain of sand and end with an easy project for us newbies to have a economic and cool sounding eurorackable toy.

So I guess now I have to look how to implement 1 pole filters in arduino. (Thanks for the tip!!). And delay lines (I guess this is the easier part. Just recording the samples in an array, isn't?)

I would love to develop some wavetable osc and some kind of percussive monster in the vein of bassimilus iteritas... one day Wink Maybe 2 or 3 years in future beeing overly optimistic... But now let´s resolve the arduino KS thing first.

If you have more tips Im all ears

Thanks guys!!
Back to top
View user's profile Send private message
MapacheRaper



Joined: Feb 15, 2018
Posts: 166
Location: Spain

PostPosted: Tue Dec 04, 2018 10:16 am    Post subject: Reply with quote  Mark this post and the followings unread

@Gabi, I have been looking at HW multiplier. Did you mean if you can multiply things in the atmel?. Yes, you can Wink. You can do all the imaginable aritmetics inside.
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1988
Location: West Red Spot, Jupiter
Audio files: 224

PostPosted: Tue Dec 04, 2018 11:51 am    Post subject: Reply with quote  Mark this post and the followings unread

Regarding the injection of noise into the delay line: The original KS experiment did in fact use noise to excite the loop. That experiment was, however, not realtime. K & S wrote a program that would create a sound file which they would then play. This was due to the fact that their computing hardware was too slow for realtime in those days.

The reason they wanted to use noise was so that each excitement was different and would thus produce slightly different timbres for each "pluck" of the string. This closely emulates what happens with a real string.

Instead of noise, what I did was to use a pulse instead of noise. In my system, the pulse width can be controlled from 1/2 the delay line length down to one sample time. With 1/2 delay line length, the system produces the most 2nd harmonic. 1/3 delay line length produces an increased 3rd harmonic. Generally the wider the pulse the more mellow the timbre. I use velocity to control the amplitude of the pulse, and that controls the starting amplitude of the output. I reasoned that I can get a similar changing timbre by noting that for a string like piano (with sustain pedal down) a restrike will cause timbre change because the excite pulse is added to the existing waveform data, so each pluck will indeed have slightly different timbre. This also avoids having to compute a delay line full of new random numbers. In an environment like arduino, too many clocks is killer.

_________________
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
View user's profile Send private message Visit poster's website
JLS



Joined: Nov 05, 2005
Posts: 504
Location: Czech
Audio files: 30
G2 patch files: 316

PostPosted: Tue Dec 04, 2018 1:33 pm    Post subject: Reply with quote  Mark this post and the followings unread

One my simplest arduino karplus "synth" Very Happy


Chaos_Synth_karplus.ino
 Description:

Download (listen)
 Filename:  Chaos_Synth_karplus.ino
 Filesize:  1.39 KB
 Downloaded:  610 Time(s)


_________________
Sorry my bad English Smile
https://soundcloud.com/1jls
https://soundcloud.com/user-819966312-266044932
https://github.com/jlswbs
https://www.youtube.com/channel/UC66pYfMX8VBLaBbsaprIlnA
Back to top
View user's profile Send private message Visit poster's website
JovianPyx



Joined: Nov 20, 2007
Posts: 1988
Location: West Red Spot, Jupiter
Audio files: 224

PostPosted: Tue Dec 04, 2018 3:33 pm    Post subject: Reply with quote  Mark this post and the followings unread

In terms of code, I've got it in Verilog (for FPGA), assembly language (dsPIC) and ARM in C. Neither the Verilog nor the assembly language would do an arduino user any good. While the ARM code is in C, it uses float types which I believe would be too slow. The process itself is quite simple. There is a delay line which feeds a filter and the filter's output is routed back into the input of the delay line. The noise or impulse to excite is fed into the delay line by adding it to the filter's output before it goes back into the delay line.

The problem with float type in an 8 bit microprocessor like an AVR is that it is quite slow. The way to make it faster is to use fixed point arithmetic which is really an integer process. I use that methodology in the dsPIC code, but since it's assembly language it would look like alphabet soup unless you "get" dsPIC assembly language.

I can't find the primitive C code for ARM which I would have posted, because there is code that implements advanced features that are being used in the ARM code for a module I am designing and plan to sell. It is quite common for coders to keep such things private, but I will answer whatever questions I can to help interested folks in implementing KS for arduino. To do that, the coder needs to understand how to code for fixed point arithmetic since that is not a standard C type (God only knows why that is).

Excellent information about Karplus-Strong is here, but there is no AVR code there. On that page is shown a block diagram for the system which includes the original filter (an unweighted 2 sample averaging filter). That filter is going to be faster than the single pole low pass IIR filter that I use. It will work, but it isn't tunable to change the system's basic timbre - but it will work. Not sure what Meng Qi is using. To make it so that you can change the timbre (which goes from drum-like to harp-like) you need the single pole low pass IIR filter which looks like this:

Code:

z = a0 * input + b1 * z

where z is the filter's memory AND the filter's output
a0 is a value chosen from 0.0 to 1.0 (called the filter bandwidth)
b1 is 1.0 - a0

When the bandwidth value is set high, the filter is a low pass with a high cutoff. When it is low, the cutoff is low. Higher cutoff affords a more metallic timbre and has long sustain. Low cutoff affords a more drum-like sound.

Again, for arduino this would need to be coded in 16 bit fixed point to make it fast enough (although I can't be sure it would in fact be fast enough).

_________________
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
View user's profile Send private message Visit poster's website
MapacheRaper



Joined: Feb 15, 2018
Posts: 166
Location: Spain

PostPosted: Tue Dec 04, 2018 3:55 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thanks for the idea, Jovian. I read and re read your posts to grasp all the possible knowledge.

Edit: Im reading your new post. Nice! I was ging to try a IIRC filter that I have found. No idea how to implement it yet or if is valid. Amyway I think I prefer the equation that yu have posted. Thanks!!

@JLS
COOOOL, yours is probably the first arduino KS implementation of the whole internet. Im going to breadboard and try it right now. Looking at the codo is incredibly short and simple. Im assuming that the filter is this part:

Code:
x = r*nx*(1-nx);

(edit nopes, it was the note secuence note generator)

Which is very similar to what Jovian was pointing. And that the noise generator is that one:

Code:
delaymem[i] = random(256);

Quote:
(edit, yes, it was. so the filter is that??:
out = accum >> lowpass;

accum = accum - out + ((last >> 1) + (curr >> 1));
)




I still doesnt undertand everything that is happening. I´ll probably see it clearer on the breadboard

Thank you guys, you are fantastic. This whole forum is fantastic.

Lets play!!

Last edited by MapacheRaper on Tue Dec 04, 2018 5:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
MapacheRaper



Joined: Feb 15, 2018
Posts: 166
Location: Spain

PostPosted: Tue Dec 04, 2018 4:37 pm    Post subject: Reply with quote  Mark this post and the followings unread

So... Its WORKING AT THE FIRST TRY!!! YEAH!!!

Currently hearing kind of guitar generative sequenced plucks.

So one knob controls the decay. Other the secuence of notes that plays and the third one the speed of notes triggers.

Maybe Im uploading a video tomorrow. Im gonna try to tweak the code so you can choose the note and add CV and.... look for more percusive outputs.

Thanks JLS!!!

surprise jackson dancing

It sounds crystal clear, deep and organic. I love it!
Back to top
View user's profile Send private message
Grumble



Joined: Nov 23, 2015
Posts: 1308
Location: Netherlands
Audio files: 30

PostPosted: Wed Dec 05, 2018 12:13 am    Post subject: Reply with quote  Mark this post and the followings unread

Of course you are not limited to the arduino uno...
There is the Arduino Due which holds a 32-bit ARM core microcontroller. It has 54 digital input/output pins (of which 12 can be used as PWM outputs), 12 analog inputs, 4 UARTs (hardware serial ports), a 84 MHz clock, an USB OTG capable connection, 2 DAC (digital to analog), 2 TWI, a power jack, an SPI header, a JTAG header, a reset button and an erase button.
The downside: it can only handle voltages up to 3.3 volts, any higher can and probably will, damage the processor.

And there is the Arduino Leonardo, a microcontroller board based on the ATmega32u4 (datasheet). It has 20 digital input/output pins (of which 7 can be used as PWM outputs and 12 as analog inputs), a 16 MHz crystal oscillator, a micro USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.
The Leonardo differs from all preceding boards in that the ATmega32u4 has built-in USB communication, eliminating the need for a secondary processor. This allows the Leonardo to appear to a connected computer as a mouse and keyboard, in addition to a virtual (CDC) serial / COM port. Flash Memory 32 KB (ATmega32u4) of which 4 KB used by bootloader.
(aliexpress, €2,46 HERE)

_________________
my synth
Back to top
View user's profile Send private message Visit poster's website
ixtern



Joined: Jun 25, 2018
Posts: 145
Location: Poland

PostPosted: Wed Dec 05, 2018 1:52 am    Post subject: Reply with quote  Mark this post and the followings unread

Grumble wrote:
Of course you are not limited to the arduino uno...
There is the Arduino Due which holds a 32-bit ARM core microcontroller.
...
The downside: it can only handle voltages up to 3.3 volts, any higher can and probably will, damage the processor.

You have forgotten about Teensy. Teensy 3.5/3.6 are real beasts in the Arduino world with 32-bit ARM Cortex-M4, ADC, DACs and plenty of memory. 3.6 is faster but 3.5 has 5V tolerant inputs. And they are integrated with Arduino IDE by Teensyduino. The only drawback is the price. But fantastic support is worth that, I think. Just bought two Teensy 3.5 (from Mouser) and started to experiment with them.
Back to top
View user's profile Send private message
Grumble



Joined: Nov 23, 2015
Posts: 1308
Location: Netherlands
Audio files: 30

PostPosted: Wed Dec 05, 2018 1:56 am    Post subject: Reply with quote  Mark this post and the followings unread

I didn't forgot the Teensy, it is not an original Arduino product and thus is not listed on the Arduino website.
There are more boards that could run with the arduino software: https://playground.arduino.cc/Main/ArduinoOnOtherAtmelChips

_________________
my synth
Back to top
View user's profile Send private message Visit poster's website
JovianPyx



Joined: Nov 20, 2007
Posts: 1988
Location: West Red Spot, Jupiter
Audio files: 224

PostPosted: Wed Dec 05, 2018 8:58 am    Post subject: Reply with quote  Mark this post and the followings unread

The ARM M4 at 84 MHz sounds like a good way to implement KS. Given my experience, I'd say it is capable of at least 8 voices of polyphony and perhaps as many as 16. This is because the M4 has an FPU, though I don't know if it does add, subtract and multiply operations in one clock cycle and it might (you'll have to research that). That would eliminate the need to use clunky fixed point arithmetic which just obfuscates the C code. This also gives 24 bits of mantissa which would allow better sound resolution.

I'm not knocking the 8 bit AVR attempt at this, but when there are far more powerful CPUs - why not use them especially when they are really not all that expensive. To me, the 16 MHz 8 bit AVR is best employed as a microCONTROLLER; it is not really a DSP device. That is, however, just my opinion.

_________________
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
View user's profile Send private message Visit poster's website
MapacheRaper



Joined: Feb 15, 2018
Posts: 166
Location: Spain

PostPosted: Wed Dec 05, 2018 1:50 pm    Post subject: Reply with quote  Mark this post and the followings unread

So, the implementation of JLS only has 4 states of the filter (four possible positions between open and closed)

Im trying to rewrite it to be 255 positions but I must confess I have no idea of what Im doing. LOL

Maybe it would be better to write it from scratch.

Im trying to understand how to implement this filter idea of Jovian:

Code:
z = a0 * input + b1 * z


where z is the filter's memory AND the filter's output
a0 is a value chosen from 0.0 to 1.0 (called the filter bandwidth)
b1 is 1.0 - a0


z should be a normal variable or an array one type z[i] with 1024 positions?

The bandwidth is the cutoff?

To do a decay is ok to multiply the samples for, lets say .95f for a longer one and .66f for a shorter one?

Yeah, no fucking idea... It seems theres no tutorials about arduino DSP that remotely touch this concepts

Maybe I should try to copy and translate a karplus java implementation... Or just fucking buy a DU KARP module and call it a day!! Very Happy
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1988
Location: West Red Spot, Jupiter
Audio files: 224

PostPosted: Wed Dec 05, 2018 3:29 pm    Post subject: Reply with quote  Mark this post and the followings unread

z is just a single variable. You'd use an array if you had more than one waveguide (in KS parlance, the delay line is called "waveguide". So if you implement 4 strings (waveguides) you'd want to declare an array like:

float z[4]

where each string owns one location, like string 3 would use z[3] for it's memory.

The a0 and b1 values would be single variables as well, even in a multiple string implementation assuming you want the same timbre for all of the implemented strings. If you wanted each string to have a different timbre, then you'd want to array those as well.

The z value needs to be an array for multiple strings because that creates a separate filter for each string.

Bandwidth (a0 value) is indeed an expression that represents cutoff. b1 is always computed as 1.0 - a0

Yes, linear decay such as multiplying by 0.97f after the filter works (I do this). That is helpful when a0 is close to 1.0f as the string can resonate a very long time. I should also mention that if a0 is 1.0f, the string will NEVER stop resonating, so 1.0f is not a useful setting for most things.

Regarding arduino and DSP, there really aren't any 8 bit CPUs that are appropriate for DSP (in my opinion). The ARM version is good for what I would call "light DSP" work. I've no idea what Meng Qi used in his module, but if it's a single string, then I would guess he may have cleverly coded it using 16 bit fixed point (which in my opinion makes for some very obfuscated 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
View user's profile Send private message Visit poster's website
MapacheRaper



Joined: Feb 15, 2018
Posts: 166
Location: Spain

PostPosted: Wed Dec 05, 2018 4:57 pm    Post subject: Reply with quote  Mark this post and the followings unread

Invaluable post. Thanks again Jovian. Im meditating about all that you say and has been posted in this thread.

The ideas floating around my head waiting to get out in stampede in an eureka moment
Back to top
View user's profile Send private message
MapacheRaper



Joined: Feb 15, 2018
Posts: 166
Location: Spain

PostPosted: Thu Dec 06, 2018 9:10 am    Post subject: Reply with quote  Mark this post and the followings unread

Ok, I think I got it.

I mean, the theory.

In the practic, I have some integer variables crashing versus the floating point ones. I think this is where our chinese friend did his magic. You were anticipating it, Jovian, LOL.

The only think sure is that this is possible. It just to compose a jigsaw that enters in a 2K Ram space and that sounds incredibly tasty.

Easy... LOL Wish me luck. Wink

I have all the jigsaw pieces on the table. It´s a question of doing cabalas until the processor understands it.

By the way I have been looking at the SMT32 processors and Im tempted to order a cortex 4 or 7 board. I still have to look at the details to decide. I would like both. Plus an teensy. LOL, the fucking wormhole is eating me alive... and I love it!!
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1988
Location: West Red Spot, Jupiter
Audio files: 224

PostPosted: Thu Dec 06, 2018 10:24 am    Post subject: Reply with quote  Mark this post and the followings unread

The trick in using a small slow CPU (16 MHz and 8 bit is considered "slow") is to use fixed point arithmetic at 16 bits. This is a way to implement "real" numbers (over integer) by using integer processes to emulate fixed point arithmetic.

Generally (in case you don't know), 16 bit fixed point is usually implemented as 1.15. What that means is that there is one bit used for sign and 15 bits used to represent a fraction from 0.0 to 0.99999. 0.99999 is considered close enough to 1.0 and is effective. This does, however, obfuscate the C code because a multiply of 2 numbers isn't going to be a * b. Multiplying integers means that the product will actually need to be initially stored as 32 bits, not 16. That is, if int16_t is used for A B and C, doing C = A * B will overflow if A and B are large enough. If C is declared as int32_t, it won't, but then something like C >> 15 (I believe it would be 15, but not entirely sure) is needed to put the magnitude of C back to what A and B are. Once that shift is done, the number in C can be stored in a int16_t variable.

I haven't used fixed point for several years - it may be that to do
Code:
product = ( A * B ) >> 15;

requires that A and B also be declared as int32_t as well. It is probably true because the initial multiplication of A and B will result in a 32 bit result and may be truncated to 16 bits. If A and B are declared as 32 bits each, it will definitely NOT truncate to 16 bits.


Hopefully you already knew that or my explanation was good enough.

So properly doing the multiply looks something like this:
Code:

int16_t A, B, product;
int32_t C;

C = A * B;
product = C >> 15;


This can also be coded as:
Code:

product = ( A * B ) >> 15;


As you can see, multiplying A and B such that 'product' is the same type as A and B looks obfuscated and makes the code harder to read. I did this for my dsPIC stuff because while it's a 16 bit CPU, it had no FPU and I programmed in assembly language on that and it was the only way to get what I needed and make it as fast as possible. And it's even worse in assembly language because assembly language starts out obfuscated even without fixed point.

Here is what the simple single pole low pass filter code looks like:
Code:

z = ( ( a0 * input ) >> 15 )  + ( ( b1 * z ) >> 15 )


As you can see, it looks pretty cryptic.

Not to harp on small and slow, but the fact is that for an 8 bit CPU, doing a 16 bit multiply with int16_t requires FOUR multiply instruction and several adds, loads and stores - this makes a multiply very slow which is the main reason why a 16 MHz AVR is not considered a DSP chip.

Last edited by JovianPyx on Thu Dec 06, 2018 10:51 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
MapacheRaper



Joined: Feb 15, 2018
Posts: 166
Location: Spain

PostPosted: Thu Dec 06, 2018 10:51 am    Post subject: Reply with quote  Mark this post and the followings unread

Great explanation, maestro. I didn´t remotely know nothing about that and I find it fascinating and crystal clear.

I have never went down to assembler. The few times that I have tried to grasp it it has revealed as a nightmare. In fact I don´t understand how people can even program in it. Programs in, lets say, spectrum, was enterely done in assembler... My god

All my respect for the people that achive this. I see it as the maximun exercise of zen, memory, patience and logic.

So I didn´t know about your explanation, and Im hoping that I can solve it via 8bit operations, but if the only possible way is 16bits doing all that intrincacies, I will at least try. You know, sometimes you feel you have found something yur truly want to explore to the end, no matter the obstacles.

Im my case Im doing a lot of cool patches in reaktor with just a karplus and an oscillator. It so fucking full of possibilities that I want to extract this from the reaktor environment and crystalize it in my homemade modular... Wink

Not sure if I will suceed, but Im learning a lot in the quest and having a great time Wink

Thanks again!!
Back to top
View user's profile Send private message
JovianPyx



Joined: Nov 20, 2007
Posts: 1988
Location: West Red Spot, Jupiter
Audio files: 224

PostPosted: Thu Dec 06, 2018 10:57 am    Post subject: Reply with quote  Mark this post and the followings unread

Heh - assembly language - it's the only way to make things faster than C. I learned I think in the late 1970s (I'm 65 years old) on a MC6800 8 bit microprocessor which ran at a whopping huge 1.0 MHz. That's really really slow which motivated me to bite the proverbial bullet and learn assembly language because a C compiler had not been written for it. In fact, I first learned to do what is called "machine language" coding. This where you string the hexadecimal CPU instructions together. Once I got a "symbolic assembler" program for it, it became a bit less nasty because the symbols or names can be used to represent memory locations.

However, C compilers these days are very good at optimizing and can often come up with better use of CPU instructions than someone coding in assembly language - so please don't take this as a warning that you shouldn't use C. Unless you are really good at assembly language you probably won't be able to improve on what C does.

Fun, eh? Cool Cool Cool Cool

_________________
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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 2 [48 Posts]
View unread posts
View new posts in the last week
Goto page: 1, 2 Next
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » Arduino
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use