Friday, August 29, 2014

Writing a synthesizer... in Java

Java. A synthesizer. I am writing the latter with the former. The first questions most people ask me are: why are you writing a synthesizer? Why Java?

I am writing a subtractive synthesizer in Java, indeed. "Why?," you would ask. I have two objectives with this project:

  1. Challenge myself, learn something new, and write a piece of software that I'll enjoy to use frequently.
  2. Demonstrate that Java is powerful enough to synthesize decent audio in real time.
In these series of posts, I am going to describe the challenges and share the knowledge I acquire as I go through this adventure.

Why a synthesizer?

Most people don't know about this, but I enjoy electronic music a whole lot (in particular: many forms of Trance, including Uplifting Trance, Goa Trance, Psychedelic TranceDrum & Bass and variations such as Neurofunk; some Breakbeats; and a few other things), enough to actually dabble into production. I have studied a bit of music theory, looked for tutorials, tips and tricks everywhere and followed some YouTube channels from great producers out there to learn more about the tricks of the trade. I have played with lots of different synthesizers and effects and experimented some DAWs, my favorite being FL Studio.

The natural step after playing with those, as an avid programmer who is always looking for a challenge, is to learn more about how these things work from the inside. The best way to do that? Why yes, to write code!

Of course, writing a synthesizer (or any piece of software, for that matter) is not only about writing code. You need to know the concepts behind what you're going to do.

To build the inner workings of a synthesizer, you need a solid foundation on Digital Signal Processing, or DSP for short, and a working knowledge of MIDI if you want it to respond to real instruments and DAWs. It is also useful to learn about Steinberg's VST, one of the most popular software interfaces for audio synthesizers and effects, and similar technologies, such as DXi, RTAS and Audio Units, as these will allow you to use your plugin on pretty much any DAW in existence.

As an added bonus, writing my own synthesizer means I can add my own touch to my songs. (Although I have yet to finish and publish one...)

Why Java?

My language of choice was Java in part due to the experience I have with it, but mostly because I wanted an extra bit of challenge by writing the synthesizer in a language that is usually regarded as inadequate for real-time number-crunching (and prove that it actually is up to the task).

Since I wanted this synthesizer to integrate with FL Studio, I had to look for a Java library that provided me an implementation of one of the audio plugin interfaces supported by the DAW. jVSTwRapper was my choice; it does a great job of keeping the native-Java overhead very low and provides an API that closely resembles the native one in C++ while providing a bit of object-oriented flavor.

I also had to write a simple GUI to test the synthesizer itself in Java without having to go through the build process and restart my DAW anytime I made any changes to the code. That in itself was not as challenging as before, as I had written a module music player in Java (supporting MOD, S3M and IT) and the workings are very similar.

Oh, and Java is the primary language of Android apps. Maybe in the future you could be playing with my synthesizer on your smartphone. How cool is that?

Stay tuned!

No comments:

Post a Comment