It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
I am looking for libraries that would allow me to generate audio from scratch. I have recently discovered that WebAudio can do that, and there's tone.js as a JavaScript library that improves the interface, but the downside is that it requires the web platform, and I might want to do that sort of thing natively. (I could, of course, use electron to avoid the browser sandbox, but there's still the significant use of disk space and RAM, and many say that electron apps aren't friendly in terms of system resources.)

Anyway, here is what I am looking for:
* Preferably in a language that is API-compatible with C; failing that, I would accept Python or Rust (with Rust preferred over Python).
* Needs to allow generation of sounds from scratch. In particular, the ability to playback or manipulate existing audio files isn't what I am looking for. (In particular, the JavaScript library howler.js, while it appears to be a nice library, is not the type of library I am looking for.)
* Creating and playing a 440 Hz sine wave (which would register as an A on a tuner) should be as simple as a hello world program (essentially, it would serve as the hello world program for this library).

So, anyone have any ideas?
avatar
dtgreene:
When I was implementing a replacement for speaker beeps for the Andrew Toolkit's music inset, I used portaudio. I have slept many times since then, so I can't really say much about it, other than that it's what I ended up using after a similar search. It was easy enough for me to use, in any case. You can look at how I used it on my AUIS bitbucket project, specifically under atk/music if you care. Honestly, given the simplicity of what I was looking for at the time, it's possible the library doesn't actually do anything useful other than provide portable sound output.
Post edited May 22, 2020 by darktjm
This is an interesting multi-library approach you may find intriguing.

https://zach.se/generate-audio-with-python/
avatar
Tallima: This is an interesting multi-library approach you may find intriguing.

https://zach.se/generate-audio-with-python/
I've actually done something like that (though I used NumPy), but I would like a library that does all that work for me.
avatar
dtgreene:
avatar
darktjm: When I was implementing a replacement for speaker beeps for the Andrew Toolkit's music inset, I used portaudio. I have slept many times since then, so I can't really say much about it, other than that it's what I ended up using after a similar search. It was easy enough for me to use, in any case. You can look at how I used it on my AUIS bitbucket project, specifically under atk/music if you care. Honestly, given the simplicity of what I was looking for at the time, it's possible the library doesn't actually do anything useful other than provide portable sound output.
+1 from me for PortAudio.

It is MIT licensed, cross-platform and written in C. If I remember correctly, their website also contains samples to help you create various simple waves (e.g. sine, saw, square, etc.).

I have used it to create an audio module to stream audio files and sound effects when I was creating small experimental games in C++.
In my mind, generating audio from scratch amounts to writing whatever you want into a buffer. Could be cos(t), could be something else. That's what makes it "from scratch." Filling a buffer with cos(t)*amplitude is about one line of code. Maybe a few more if you want to preserve phasor state between blocks..

What can a library do to make it simpler? How is it still "from scratch" if the library is doing it for you? What else would you expect from a library other than pure sine waves?

I wouldn't expect anyone to write a library for writing sine waves, since it's so trivial. So if you find audio generation libraries, they're probably designed for more complex synths and instruments.. and less "from scratch."
Post edited May 22, 2020 by clarry
I'm not sure if this fits what you're looking for but I find Faust interesting ([url=]https://faust.grame.fr/[/url].
It's a bit of a more involved approach: a functional language that then gets crosscompiled into several target languages.

Similar but different is CSound ([url=]https://csound.com/[/url]), which can be used as an end-user tool to make music (or noise), or as a library.