Wednesday, February 15, 2012

Simple Audio Synthesizer in Java

This is about a program I wrote in 2005. The objective was to generate sounds that resemble the sounds of real musical instruments. This blog post includes an executable JAR file and the source code for this. If you computer is Java-ready you can start by trying it here right away [YASS]. (UI in English).

This is how the UI should look like (Except this one is the original UI in Spanish)
It uses a bottom-up approach to recreate the sounds of real musical instruments by starting from the most basic constructs - simple sinusoidal functions. This means that more complex wave functions are created by aggregating sinusoidal waves with different frequencies and modulating the amplitude of the resulting waves using envelope functions. The UI allows to modify the basic wave function by modifying the individual sinusoidal waves or choosing from a preset list of wave functions. It also allows for choosing from a preset list of envelope functions. Finally it allows to choose from a preset list of musical instruments. This latter option just chooses the appropriate wave functions and envelope functions that make the resulting sound resemble a musical instrument. This last part was done just by using my own judgement and not any machine learning (Disclaimer: I don't pride myself of having a sense of musical aptitude). And this is all this program can do.

One thing that is most likely wrong is the keyboard, I wouldn't trust the mapping of the tones in the keyboard to the actual tones, this is a quick fix though. I frankly don't remember where did I get the mapping for this keyboard. This document from the University of Tennessee explains how to make the mapping correctly:
Another thing that I definitely have to credit is Manfred Thole's demo on Fourier Synthesis, while I clearly took inspiration on the sinusoidal editor from his demo I totally borrowed his function to convert integers to the μ-law scale

Finally I was not sure if I should post the source code for two reasons: 1) Function definitions, variable names, etc are all in Spanish and I'm writing my blog in English. 2) I actually lost the original source code and had to decompile the class files inside the JAR file to get source code and recompile it again with the UI in English, thus additionally losing comments and therefore potentially not acknowledging some sources of inspiration and some wisdom for the future. Still I'm including here the source code in case somebody finds it useful despite of cons 1) and 2), one good thing is that it still compiles in the Java SDK 7 even after decompilation: [].

Sunday, February 12, 2012

Learning English

I mentioned in some older post about how I learned to write in my native language when I was young [Learning Karate by Waxing Cars],  in this post I will explain how I learned to communicate in a second language: English. I started to get interested in this language when I was a 13-14 year old teenager with lots of spare time. I was good at school but English is something that most of the times you don't get to learn at schools in Ecuador even with proper motivation. I had decided to learn this language as something that might be useful later but most importantly because I saw this as a challenge and something that nobody close to me could do at least at the time. I had no clue about how one teaches himself a second language so I took an English-Spanish dictionary and tried to learn every word brute-force style. Disappointed after some time I tried to learn the grammar rules from another book. Although more motivated by my recent experience with the acquired ability of creating some simple sentences using the few grammar rules I had learned I was still totally lacking any form of speech or listening skills.
ESL videotapes that I used. I just found
them using Google wondering if they
are still available somewhere. This is
apparently a DVD version but I can't forget
the Eagle logo. [Price: $600] [link]
I think their approach is remarkable!

This was around 1998 and while in Silicon Valley there was already a new born Google (maybe Backrub), I didn't have access to computers at the time. Fortunately I had at home an old VHS player and some ESL video tapes that my mother had got some time back from somewhere. My mother never used the tapes herself but she made sure to even photocopy the printed course materials and went as far as to retype some of the material using a typewriter (I hope I don't  get my mother into trouble because of some possible case of copyright infringement). Look at the picture in this blog post and the caption. The Speak to Me course is 90% about practicing in front of the screen by repetition, these are not lectures. (Again another example related to [Learning Karate by Waxing Cars] although this time took me longer to realize about the success of this attempt). This educational resource was treasure to me. I went through every one of these more than a half dozen videotapes twice. This time I was very satisfied with the results and was eager to take it to a next level. Unfortunately most private English classes in Ecuador are either very expensive or a well elaborated scam. My parents just could not afford it. So I forgot about English for a while.

Two years later in my last year (senior year?) of high school I was fortunate enough to have assigned a native level speaker as my English teacher, Ms. Martha Dockter. To my own surprise I realized that I could already engage in casual conversation with her in English without major trouble. I had not met any other English speaker before. Ms. Martha was very helpful on correcting a lot of mistakes on my writing and speech, I learned tons with her. She passed away in 2008 (†). Her obiturary reads that she was the daughter of a Reverend from Mansfield, Ohio who travelled to Ecuador with his wife to do missionary work. I'm sure there are many more students like me grateful for her teachings. This is my story about how in a time before the internet I got to learn a second language. Finding the educational resources was harder than today but finding the willingness for self-education was still as hard as it is today.