New SymPy Project -- PyTuning

126 views
Skip to first unread message

Mark Conway Wirt

unread,
Apr 4, 2017, 10:43:33 AM4/4/17
to sympy
Hello SymPy People,

On the SymPy project page they mention letting the list know if you're using SymPy in a project.

My particular project may (or may not) be interesting to the folks on the list, owing to the fact that the domain is a good deal different form the standard SymPy domain. From the project description:

PyTuning is a Python library intended for the exploration of musical scales and microtonalities. It can be used by developers who need ways of calculating, analyzing, and manipulating musical scales, but it can also be used interactively.

It makes heavy use of the SymPy package, a pure-Python computer algebra system, which allows scales and scale degrees to be manipulated symbolically, with no loss of precision. There is also an optional dependency on Matplotlib (and Seaborn) for some visualizations that have been included in the package.

It is released under an MIT-style license. Source code is hosted on GitHub. Pypi entry is here.

Thanks for all the work that's gone into this great package! (I also use it at work more in line with its default use-cases.)

--mcw 

Aaron Meurer

unread,
Apr 4, 2017, 1:50:43 PM4/4/17
to sy...@googlegroups.com
Thanks for sharing. That is an interesting use of SymPy.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/58123d8c-ea4d-4a5b-84b4-e798374ebb28%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Sumit Srivastava

unread,
Apr 4, 2017, 2:23:00 PM4/4/17
to sympy
Really interesting usecase. Has it been done(or something) by someone else earlier?

Mark Conway Wirt

unread,
Apr 6, 2017, 10:13:28 AM4/6/17
to sympy
Not in Python, so far as I know.

It's a pretty niche domain (musical scales and microtonalities). There is an Ada application that's pretty full featured, and I think that most of the people in the community use that. 

But I'm not an Ada guy; hence the Python library :)

Ondřej Čertík

unread,
Apr 6, 2017, 12:55:06 PM4/6/17
to sympy
Hi Mark,

Very nice project, thanks for sharing. Music theory is indeed very
interesting. I was recently playing with a numerical solver for guitar
strings:

https://gitlab.com/certik/stringsim

But I didn't have time to finish it yet. I was going to use sympy for
the method of manufactured solutions to verify the solver. I was
wondering if you can produce realistic sounds by literally solving the
string equation for an electric guitar (it's my understanding that to
first order it's just the strings and the pickups, as well as how and
where you pluck the string, but everything else is secondary, unlike
for a piano or an acoustic guitar) and feed it to some software
amplifier. I think that's how some of the guitar simulators work, but
I think they take shortcuts (like they don't actually solve the
equation, but just have some modes or even samples and mix them up). I
was curious if I can have a regular numerical solver, as I am used to
solving other equations. I wasn't able to find anything online or in
literature.

Ondrej

Mark Conway Wirt

unread,
Apr 6, 2017, 1:28:03 PM4/6/17
to sympy
I was wondering if you can produce realistic sounds by literally solving the 
string equation for an electric guitar...

Perhaps, but you would probably have issues with performance -- you may be able to get a good sound, but it would be difficult to generate it in real- or near-real time.

For strings (and some kinds of percussion) physical modeling is often used, but not taken in the direction of modeling the string or membrane. The most common form of modeling is digital waveguide synthesis. One of the earliest "good sounding" approaches was probably the Karplus-Strong algorithm, which is usually considered a physical model (albeit a pretty abstract/conceptual one).

You may want to look at cSound's repluck (which is based on Karplus-Strong).

http://www.csounds.com/manual/html/repluck.html

On Thursday, April 6, 2017 at 12:55:06 PM UTC-4, Ondřej Čertík wrote:

Ondřej Čertík

unread,
Apr 6, 2017, 3:06:04 PM4/6/17
to sympy
On Thu, Apr 6, 2017 at 11:28 AM, Mark Conway Wirt
<mark...@geostellar.com> wrote:
> I was wondering if you can produce realistic sounds by literally solving the
> string equation for an electric guitar...
>
>
> Perhaps, but you would probably have issues with performance -- you may be
> able to get a good sound, but it would be difficult to generate it in real-
> or near-real time.

Yes, I am not interested in real time. I am interested in solving the
actual physics, with good numerics (e.g. convergence, verification,
etc.) and getting good sound. So if it takes 1h to get 1s of sound,
that's totally fine with me.

My suspicion is that you might be able to get better sound with the
approaches below (since they fine tune the parameters and make it
sound good), than with a direct solve of the physical equation
(without artificially fine tunning any parameters), but perhaps not.
So that's why I am curious.

>
> For strings (and some kinds of percussion) physical modeling is often used,
> but not taken in the direction of modeling the string or membrane. The most
> common form of modeling is digital waveguide synthesis. One of the earliest
> "good sounding" approaches was probably the Karplus-Strong algorithm, which
> is usually considered a physical model (albeit a pretty abstract/conceptual
> one).

Yes, that is an example of what I meant by the "shortcut" approach, as
it seems to be just some digital filters, but not really solving a
physical equation
(https://en.wikipedia.org/wiki/Karplus%E2%80%93Strong_string_synthesis),
at least not directly. But since it sounds nice, it must be doing
something right, but it feels like they skipped the actual physical
model, and just created an algorithm, but I can't see how this
directly corresponds to a vibrating string.

>
> You may want to look at cSound's repluck (which is based on Karplus-Strong).
>
> http://www.csounds.com/manual/html/repluck.html

Nice, thanks, it took me a while to find the actual source code:

https://github.com/csound/csound/blob/6d8779dc884f79d6aa43a21f163e36bc67c3c411/Opcodes/repluck.c

It seems both this code, as well as Karplus-Strong, is not really
solving the physical equation, it's just a good sounding model.


Ondrej

>
> On Thursday, April 6, 2017 at 12:55:06 PM UTC-4, Ondřej Čertík wrote:
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/df2cf836-1512-443f-b9c4-f7a69cec3e6f%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages