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 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
  host / artist show at your time
<on air> Sorry, postponed until next week Chez Mosc
 Forum index » DIY Hardware and Software » Arduino
Pursuing Karplus-Strong
Post new topic   Reply to topic
Page 2 of 2 [46 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Goto page: Previous 1, 2
Author Message
Grumble



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

PostPosted: Thu Dec 06, 2018 2:23 pm    Post subject: Reply with quote  Mark this post and the followings unread

Very Happy I learned machine code on a self made "machine" built around the HD64180
I even had it sampling audio under dma, a video interface, a soundboard with a AY38910 all written in machine code.
Then I got the Junior computer around the 6502 and then a REAL computer: the Acorn Atom (also 6502 based)
Yup, same age as you salut

_________________
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: Thu Dec 06, 2018 2:26 pm    Post subject: Reply with quote  Mark this post and the followings unread

As an addendum - There is a way to possibly speed up the low pass IIR filter which also eliminates the need for the b1 variable:

The formula can be rewritten algebraically as:
Code:

z = z + a0 * ( in - z )

_________________
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: 490
Location: Czech
Audio files: 30
G2 patch files: 316

PostPosted: Sat Dec 29, 2018 3:08 am    Post subject: Reply with quote  Mark this post and the followings unread

Update Arduino Karplus-Strong.

- better triggering
- better timers (PWM PIN 11)

Example Simple Karplus-Strong and duophonic Karplus-Automata cellular automata sequencer Smile


Karplus_Strong.ino
 Description:

Download
 Filename:  Karplus_Strong.ino
 Filesize:  1.74 KB
 Downloaded:  630 Time(s)


Karplus_Automata.ino
 Description:

Download
 Filename:  Karplus_Automata.ino
 Filesize:  2.86 KB
 Downloaded:  591 Time(s)


_________________
Sorry my bad English Smile
https://soundcloud.com/1jls
https://soundcloud.com/user-819966312-266044932
https://github.com/jlswbs
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 29, 2018 4:45 pm    Post subject: Reply with quote  Mark this post and the followings unread

Cool! I´ll be testing it in no time. Thanks!!
Back to top
View user's profile Send private message
JLS



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

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

Floating point version Arduino Karplus-Strong.

- better sound
- better lowpass filtering
- but needs more memory and cpu resources


Karplus_Float.ino
 Description:

Download
 Filename:  Karplus_Float.ino
 Filesize:  2.64 KB
 Downloaded:  591 Time(s)


_________________
Sorry my bad English Smile
https://soundcloud.com/1jls
https://soundcloud.com/user-819966312-266044932
https://github.com/jlswbs
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 30, 2018 8:50 am    Post subject: Reply with quote  Mark this post and the followings unread

JLS wrote:
Floating point version Arduino Karplus-Strong.

- better sound
- better lowpass filtering
- but needs more memory and cpu resources


This is why I use STM32 ARMs. The better ones have single cycle float multiply and float add (from a hardware FPU), they have a lot more SRAM and they are a lot faster. There are also several DSP instructions including square root and MAC. Still can use C, but the environment is different if you move away from the arduino compatible chips. If gcc is given the correct optimization strings, it will use DSP instructions where possible (which speeds things up). STM32H7 for example runs at 400 MHz and has 1 megabyte of internal SRAM (though not all of it is contiguous, there is a 512 kbyte contiguous piece).

I use a completely free set of tools, though there's some initial angst in setting it all up. gcc needs to have stuff added so that it can cross compile. There are also GUI based environments (like Eclipse), but I found those to be confusing, tedious and non-intuitive. My typical work cycle is
1) edit source with my favorite text editor
2) issue a make command to compile the code
3) send the binary to the ARM and test.
4) repeat as necessary.

The arduino platform is great for learning about microcontrollers, but while it does things that might make coding easier - they also make the code slower. Those constrictions go away when you leave the arduino world and once you learn how to do things the non-arduino way, you'll be able to use any processor out there not just those in the arduino developer world.

_________________
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: Mon Dec 31, 2018 7:35 am    Post subject: Reply with quote  Mark this post and the followings unread

That floating point version seems really cool JLS. Im diying to test it. Thanks for sharing!

@Jovian, yepp, after some weeks playing with the arduino I see you are totally right. It is more intended for gating/triggering, sequencing, etc, but for DSP it needs way more meat (even if you can do some cool tricks too, even complete oscillators)

Jovian, has you taken a peek at the ESP8266 and ESP32 chips?. It packs a lot of power and bang for the buck. Definitively I think we will see some next gen O_C and mutable type of things coming from this chips
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: Mon Dec 31, 2018 12:45 pm    Post subject: Reply with quote  Mark this post and the followings unread

I had not seen the ESP chips. I don't need the wifi tho. I've had really good experience with the STM32 stuff, so I'll stick with that. Dual core is nice, but troublesome to get 2 cores cooperating usefully (parallel processing). For synth projects, a fast single core CPU is far less bother IMO. I've written multithreaded polysynths for a raspberry pi3 and that code still has issues regarding coordination of threads and memory sharing.
_________________
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: Mon Dec 31, 2018 1:08 pm    Post subject: Reply with quote  Mark this post and the followings unread

I have never done multithread, but I have meditate about it and it looks like a pain in the ass, yes. But we like it or not it´s what the future brings. It seems like 3-4GHz is the max speed that silicon does and the current state of the art chips are growing in parallel giving more and more multitreads.

So I guess somehow code will adapt to that, maybe facilitating or even completely inmaskaring in in the framework (so the framework do all the heavylifting transparently for the coder)

Regarding ESP, I see it with a lot of potential. Imagine the Ornament and Crime. Probable the more succesful open source module in existence. All people using it. A ESP version could use the wifi to connect with the smartphone/computer, so suddenly you have snapshots of the patches (infinite patches memory) plus you can control the secuencers and whatnot from the phone. And run different algoridms in every channel, something that most users ask but is quite difficult to implement in the module now.

And all this in a chip that costs 2-3USD instead of the 20-30 of the teensy.

Interesting times, for sure. I guess we will have a new wave of completely new functions in modules, no seen yet, in no time, as people start to hack with the ESP and find his treasoures

With that said, I have some SMT32 arriving in the next days too. Yumm
Back to top
View user's profile Send private message
remedios_dream



Joined: Apr 26, 2021
Posts: 3
Location: eternity

PostPosted: Mon Apr 26, 2021 3:41 pm    Post subject: Reply with quote  Mark this post and the followings unread

@JLS
I see the topic is quite old I would like to ask for your help.

If I understand code right: assuming the sampling frequency is 22050 and our delay size is 256 we have one of 255 frequencies available, right?
Where:

freq = sample_rate / bound

where max size of bound is 255.

Is there any way to get more frequencies? The simplest one is to make delay array bigger but arduino will be out of ram then.

Maybe there's another karplus-strong implementation that do not require creating large data array?

Last one could you please explain what `accum` is?
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24069
Location: The Netherlands, Enschede
Audio files: 277
G2 patch files: 320

PostPosted: Mon Apr 26, 2021 8:43 pm    Post subject: Reply with quote  Mark this post and the followings unread

remedios_dream wrote:
Is there any way to get more frequencies?


Yes there is, you can interpolate between the possible integer taps to make fractional taps.

In that way only your lowest possible frequency will be determined by the delay length (and the sample rate).

Basically what you will do then is to calculate the number "delay cells" that you would need for some frequency. This will not be an integer in general, but you can take a bit of the tap at the integer value and a bit of the next step. Getting more of the integer tap when closer to that or more of the next when closer to that.

So, the amounts to take from each steps will vary as to which one you are nearer to.

The interpolation algorithm used for this in it simplest form is linear, but there are other interpolation algorithms too.

Linear meaning that when you are halfway you use half of both step outputs summed, or when it is something.25 .. use 3/4 of the first and 1/4 of the next.

I know of two algorithms, the linear one I mentioned, and ther also is an allpass interpolation algorithm. The 2nd one giving better results, but behaving a bit odd for sliding notes, and the first one doing better for sliding notes but having some amplitude differences between notes. There may be more ideas about this that I have no knowledge of Smile

Another thing you could use, in order to use very short delays, would be to use a readout pointer on the delay line that is not fixed but one that moves .. .you could move it slower than the sample rate to get lower frequencies - I've never tried this myself, but I know JovianPyx has been doing something along these lines. Alas, he never disclosed the details and he is no longer amongst us earthlings to tell.

Anyway, in that way you could even decouple the lowest possible note from the delay length used (by moving the readout ponter on the delay line slower than the sample rate).


Sooo .. this is about what I know about the KS thing Laughing maybe a bit of googling from this info will help you to move forward?

Aand .. also welcome to the forum remedios_dream.

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
remedios_dream



Joined: Apr 26, 2021
Posts: 3
Location: eternity

PostPosted: Tue Apr 27, 2021 1:43 pm    Post subject: Reply with quote  Mark this post and the followings unread

@Blue Hell

Thank you for your answer,

You're right I totally forgot about interpolation here, also moving pointer is cool idea. I've used it several times in few wavetable kinda synthesis projects.

My main platform is stm32, unfortunately covid hits badly and those chips getting more and more expensive. I'm considering a step back, for a reasonable price.

Now I see that there's one thing which I have to learn.. How to imitate floats in weaker mcus.

There's a lot of binary shifts in code and I assume that's because we try to imitate floating point, right?

Do you recommend any resources on how to start dsp with such 8 bit micros?
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24069
Location: The Netherlands, Enschede
Audio files: 277
G2 patch files: 320

PostPosted: Tue Apr 27, 2021 2:03 pm    Post subject: Reply with quote  Mark this post and the followings unread

For non floating point .. have a look at fixed point math .. you can probably find some C macros doing the hard work for you .. although it is not really that hard, it involves some shifting ...

Only thing is with 16 bit math you need to be careful not to under- or over-flow things .. which may need some occasional rescaling (more shifts!), or using 32 bit intermediate values here and there.

And 32 bit math everywhere might be too expensive CPU wise ... and 8 bit math .. just too poor.

The shifts of course are just cheap multiplication and division (by factors of two).

_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
danielfiction



Joined: Jul 15, 2009
Posts: 9
Location: nyc

PostPosted: Sat May 01, 2021 2:48 pm    Post subject:
Subject description: mysterious
Reply with quote  Mark this post and the followings unread

JLS wrote:
Update Arduino Karplus-Strong.

- better triggering
- better timers (PWM PIN 11)

Example Simple Karplus-Strong and duophonic Karplus-Automata cellular automata sequencer Smile


Hello!
I've been following this thread with great interest. But try as I might, these code examples produce no sound. I'm running an Arduino Uno. My wiring works fine—I've checked it with other pin9 Direct Digital Synthesis libraries such as Mozi, and my potentiometers work correctly.

is there something i'm missing? a library installed? wrong board?

best,
daniel
Back to top
View user's profile Send private message
danielfiction



Joined: Jul 15, 2009
Posts: 9
Location: nyc

PostPosted: Sat May 01, 2021 3:15 pm    Post subject:
Subject description: mysterious
Reply with quote  Mark this post and the followings unread

Oh, i figured it out—I couldn't just change PWM Pin to 9, I had to manually wire it to 11, 3, or 9 according to the sketch.

would anyone mind telling me why that is? I usually make these changes in code without breaking functionality at all!

[quote="danielfiction"]
JLS wrote:
Update Arduino Karplus-Strong.

Hello!
I've been following this thread with great interest. But try as I might, these code examples produce no sound. I'm running an Arduino Uno. My wiring works fine—I've checked it with other pin9 Direct Digital Synthesis libraries such as Mozi, and my potentiometers work correctly.

is there something i'm missing? a library installed? wrong board?

best,
daniel
Back to top
View user's profile Send private message
herd



Joined: Sep 18, 2021
Posts: 4
Location: herd

PostPosted: Sun Sep 19, 2021 6:00 am    Post subject: Reply with quote  Mark this post and the followings unread

necro posting, just wastin' time here,

never understood why communities were so insular.

THE reference for karplus-strong is ccrma at stanford. i kind of feel like julius o. smith III is the qi jiguang of our time, he died for your syns, notate everything, give it to the people.

even if you just stare at the pictures, julius' pages will tell you about most things you want to be aware of, to some functional level.

(one of the other prehistoric university hosted dsp pages has just disappeared, god help us when ccrma goes down)

i've only messed with k-s in a purely dsp environ. linear interpolation is kind of like a free lowpass you don't want (the algorithm is a 6dB lowpass). 2nd order hermite (musicdsp.org or at least was) at 44.1k will give you arbitrary decay lengths that are practically undamped for perhaps a minute, much better than cubic.

you want an allpass (3rd or 4th order) or more in your delay line to add "stiffness"/nice metally tones. you'll want to redact the delay line length for this.

if you get an environ where you can implement it, coupling two lines orthogonally ("vertical and horizontal vibrations") with different damping settings allows you to shape a more realistic amplitude contour. using a similar scheme with different lengths allows you to play touch harmonics.

injecting a white noise impulse is traditional but i prefer envelopes or shaped impulses (or mass-springs). you can also use a constant white noise (filtered?) for bowing effects or "fun wind instruments".

qi jiguang and julius o. smith III are your best friends ever. remember where they are.
Back to top
View user's profile Send private message
blue hell
Site Admin


Joined: Apr 03, 2004
Posts: 24069
Location: The Netherlands, Enschede
Audio files: 277
G2 patch files: 320

PostPosted: Mon Sep 20, 2021 4:50 am    Post subject: Reply with quote  Mark this post and the followings unread

Ah, thanks for your comments herd - they might get me to do things again Cool
_________________
Jan
also .. could someone please turn down the thermostat a bit.
Posted Image, might have been reduced in size. Click Image to view fullscreen.
Back to top
View user's profile Send private message Visit poster's website
elektromeister



Joined: Feb 18, 2013
Posts: 32
Location: Freiburg

PostPosted: Tue Oct 17, 2023 9:11 am    Post subject: Reply with quote  Mark this post and the followings unread

I once programmed such a KS-Algo on my DSP - using this idea of multiple feed backs:

http://www.96khz.org/htm/waveguide3stage2.htm

The author states it was fine for guitars because it also creates slightly detuned third harmonics which comes more close to the real guitar.

We observe the same behavior in metal material which is bended and under torsion. Real waves differ from the mathematical ideal.

_________________
music is the key
Back to top
View user's profile Send private message
danielfiction



Joined: Jul 15, 2009
Posts: 9
Location: nyc

PostPosted: Sun Nov 05, 2023 9:03 pm    Post subject: Solar Karplus Strong Success
Subject description: making cool sounds with cheap chips
Reply with quote  Mark this post and the followings unread

Back to top
View user's profile Send private message
danielfiction



Joined: Jul 15, 2009
Posts: 9
Location: nyc

PostPosted: Sun Nov 05, 2023 9:07 pm    Post subject: Reply with quote  Mark this post and the followings unread

JLS wrote:
One my simplest arduino karplus "synth" Very Happy


hi all!

This is a cool old thread with lots of creative potential.

I wanted to get some Karplus Strong synth sounds running on an atmega328. I designed a board that implements the atmel chip with an onboard amplifier, a solar panel, and a few analog inputs (voltage divider straight off the solar panel, also a thermistor).

The code I've been working with really is optimized for "aleatoric" operation, ie, just kind of sitting back and letting the music change around you. (i've made about 25 of these solar powered autonomous instruments, but that's another story. anyway, it works, and this thread was really helpful as I was getting it off the ground.

I made a few different boards for it back in 2021 and I'm just dusting it off to make a new run of PCBs. excited to add some controls to it, and some depth to the code!

@JLS, your code has been really helpful in getting my circuit working. I thank you so much for sharing it!

https://www.instagram.com/p/CSNFi6AlKqx/
here's a video of the solar sounder running karplus strong.
Back to top
View user's profile Send private message
mosc
Site Admin


Joined: Jan 31, 2003
Posts: 18195
Location: Durham, NC
Audio files: 211
G2 patch files: 60

PostPosted: Thu Nov 09, 2023 1:37 pm    Post subject: Reply with quote  Mark this post and the followings unread

I love that video. A beautiful gizmo that Stan Lunetta would be proud of.
_________________
--Howard
my music and other stuff
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic
Page 2 of 2 [46 Posts]
View unread posts
View new posts in the last week
Goto page: Previous 1, 2
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